Skip to content

Commit

Permalink
Attempt to fix errors caused by using Composer-generated autoloaders …
Browse files Browse the repository at this point in the history
…when multiple versions of the library are loaded at the same time.

See #300. Apparently, when using the `files` autoloading mechanism, Composer will only include the files for one version of the library (i.e. the first one loaded). Let's see if we can fix that by switching to a `psr-0` autoloader. This requires a bunch of changes to the standalone autoloader and the factory registration process.
  • Loading branch information
YahnisElsts committed Sep 27, 2019
1 parent 0f490e9 commit bbe88a7
Show file tree
Hide file tree
Showing 7 changed files with 1,577 additions and 1,565 deletions.
7 changes: 2 additions & 5 deletions Puc/v4p7/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ public function __construct() {

$this->libraryDir = realpath($this->rootDir . '../..') . '/';
$this->staticMap = array(
'PucReadmeParser' => 'vendor/readme-parser.php',
'Parsedown' => 'vendor/ParsedownLegacy.php',
'PucReadmeParser' => 'vendor/PucReadmeParser.php',
'Parsedown' => 'vendor/Parsedown.php',
);
if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
$this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
}

spl_autoload_register(array($this, 'autoload'));
}
Expand Down
21 changes: 21 additions & 0 deletions Puc/v4p7/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,25 @@ public static function addVersion($generalClass, $versionedClass, $version) {
}
}

//Register classes defined in this version with the factory.
foreach (
array(
'Plugin_UpdateChecker' => 'Puc_v4p7_Plugin_UpdateChecker',
'Theme_UpdateChecker' => 'Puc_v4p7_Theme_UpdateChecker',

'Vcs_PluginUpdateChecker' => 'Puc_v4p7_Vcs_PluginUpdateChecker',
'Vcs_ThemeUpdateChecker' => 'Puc_v4p7_Vcs_ThemeUpdateChecker',

'GitHubApi' => 'Puc_v4p7_Vcs_GitHubApi',
'BitBucketApi' => 'Puc_v4p7_Vcs_BitBucketApi',
'GitLabApi' => 'Puc_v4p7_Vcs_GitLabApi',
)
as $pucGeneralClass => $pucVersionedClass
) {
Puc_v4_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.7');
//Also add it to the minor-version factory in case the major-version factory
//was already defined by another, older version of the update checker.
Puc_v4p7_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.7');
}

endif;
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"php": ">=5.2.0"
},
"autoload": {
"files": ["plugin-update-checker.php"]
"psr-0": {
"Puc_v4p7_" : "Puc/v4p7/",
"Puc_v4_" : "Puc/v4/",
"PucReadmeParser" : "vendor/",
"Parsedown" : "vendor/"
}
}
}
24 changes: 2 additions & 22 deletions plugin-update-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,8 @@
* Released under the MIT license. See license.txt for details.
*/

require dirname(__FILE__) . '/Puc/v4p7/Factory.php';
require dirname(__FILE__) . '/Puc/v4/Factory.php';
require dirname(__FILE__) . '/Puc/v4p7/Autoloader.php';
new Puc_v4p7_Autoloader();

//Register classes defined in this version with the factory.
foreach (
array(
'Plugin_UpdateChecker' => 'Puc_v4p7_Plugin_UpdateChecker',
'Theme_UpdateChecker' => 'Puc_v4p7_Theme_UpdateChecker',

'Vcs_PluginUpdateChecker' => 'Puc_v4p7_Vcs_PluginUpdateChecker',
'Vcs_ThemeUpdateChecker' => 'Puc_v4p7_Vcs_ThemeUpdateChecker',

'GitHubApi' => 'Puc_v4p7_Vcs_GitHubApi',
'BitBucketApi' => 'Puc_v4p7_Vcs_BitBucketApi',
'GitLabApi' => 'Puc_v4p7_Vcs_GitLabApi',
)
as $pucGeneralClass => $pucVersionedClass
) {
Puc_v4_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.7');
//Also add it to the minor-version factory in case the major-version factory
//was already defined by another, older version of the update checker.
Puc_v4p7_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.7');
}
require dirname(__FILE__) . '/Puc/v4p7/Factory.php';
require dirname(__FILE__) . '/Puc/v4/Factory.php';
Loading

0 comments on commit bbe88a7

Please sign in to comment.