Skip to content

Commit

Permalink
Ensure that all classes and also non-class files are correctly loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Oct 23, 2019
1 parent 2c457d5 commit 038315e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
bower_components
/vendor
vendor
/third-party
release
composer.lock
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@
"scripts": {
"post-install-cmd": [
"php-scoper add --output-dir=./third-party --force",
"cd third-party && echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > composer.json && composer dump-autoload --classmap-authoritative --no-interaction && rm composer.json"
"cd includes && echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > composer.json && composer dump-autoload --classmap-authoritative --no-interaction && rm composer.json",
"cd third-party && echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > composer.json && composer dump-autoload --classmap-authoritative --no-interaction && rm composer.json",
"cp vendor/composer/autoload_files.php third-party/vendor/composer/autoload_files.php"
],
"post-update-cmd": [
"php-scoper add --output-dir=./third-party --force",
"cd third-party && echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > composer.json && composer dump-autoload --classmap-authoritative --no-interaction && rm composer.json"
"cd includes && echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > composer.json && composer dump-autoload --classmap-authoritative --no-interaction && rm composer.json",
"cd third-party && echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > composer.json && composer dump-autoload --classmap-authoritative --no-interaction && rm composer.json",
"cp vendor/composer/autoload_files.php third-party/vendor/composer/autoload_files.php"
],
"lint": "vendor/bin/phpcs",
"lint-fix": "vendor/bin/phpcbf"
Expand Down
24 changes: 22 additions & 2 deletions includes/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,28 @@
define( 'GOOGLESITEKIT_PLUGIN_BASENAME', plugin_basename( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );
define( 'GOOGLESITEKIT_PLUGIN_DIR_PATH', plugin_dir_path( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );

// Autoload vendor files.
require_once GOOGLESITEKIT_PLUGIN_DIR_PATH . 'vendor/autoload.php';
// Autoload files.
require_once GOOGLESITEKIT_PLUGIN_DIR_PATH . 'includes/vendor/autoload.php';
require_once GOOGLESITEKIT_PLUGIN_DIR_PATH . 'third-party/vendor/autoload.php';

/**
* Loads vendor files containing functions etc.
*
* This integrates with the dependency prefixing script. Its autoloader loads all classes, but not the other files.
*
* @since 1.0.0
* @access private
*/
function autoload_vendor_files() {
$files = require GOOGLESITEKIT_PLUGIN_DIR_PATH . 'third-party/vendor/composer/autoload_files.php';
foreach ( $files as $file_identifier => $file ) {
$file = str_replace( 'third-party/vendor', 'third-party', $file );
if ( file_exists( $file ) ) {
require_once $file;
}
}
}
autoload_vendor_files();

// Initialize the plugin.
Plugin::load( GOOGLESITEKIT_PLUGIN_MAIN_FILE );
Expand Down

0 comments on commit 038315e

Please sign in to comment.