Skip to content

Commit

Permalink
copy third-party libs instead of using Composer autoloader (#256) (#260)
Browse files Browse the repository at this point in the history
The autoloader mechanism is quite heavy for a single dependency and
requires composer and vendor dir to be part of the final product.

We yet have generated/minified resources in our project, so this is the
minimalistic approach to copy the CrawlerDetect lib, too and extend the
custom autoloader mechanism.
  • Loading branch information
stklcode committed Sep 22, 2023
1 parent 9e65129 commit 75b2198
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ coverage
css/*.min.css
js/*.min.js
js/*.min.js.map
lib
phpunit.*.xml
vendor/
node_modules/
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
},
"extra": {
"copy-file": {
"vendor/jaybizzle/crawler-detect/src/": "lib/Jaybizzle/CrawlerDetect/",
"vendor/npm-asset/chartist/dist/index.css": "css/chartist.min.css",
"vendor/npm-asset/chartist/dist/index.umd.js": "js/chartist.min.js",
"vendor/npm-asset/chartist-plugin-tooltips-updated/dist/chartist-plugin-tooltip.min.js": "js/"
Expand Down
3 changes: 0 additions & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<file>statify.php</file>
<exclude-pattern>vendor/*</exclude-pattern>

<!-- Exclude minified Javascript files. -->
<exclude-pattern>*.min.js</exclude-pattern>

<!-- WordPress coding standards -->
<config name="minimum_supported_wp_version" value="4.7" />
<rule ref="WordPress">
Expand Down
9 changes: 6 additions & 3 deletions statify.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
)
);

/* Composer Autoload */
require __DIR__ . '/vendor/autoload.php';

/* Autoload */
spl_autoload_register( 'statify_autoload' );

Expand Down Expand Up @@ -87,5 +84,11 @@ function statify_autoload( $class ) {
STATIFY_DIR,
strtolower( str_replace( '_', '-', $class ) )
);
} elseif ( 0 === strncmp( $class, 'Jaybizzle\\CrawlerDetect\\', 24 ) && ! class_exists( $class, false ) ) {
require_once sprintf(
'%s/lib/%s.php',
STATIFY_DIR,
str_replace( '\\', DIRECTORY_SEPARATOR, $class )
);
}
}

0 comments on commit 75b2198

Please sign in to comment.