Probably fixed a bug where, if an older version of PUC 4.x is loaded first, the more recent version's factory (Puc_v4pN_Factory) won't be able to instantiate any classes.

This bug was caused by a combination of two facts:

1) The version that gets loaded first takes the Puc_v4_Factory alias.
2) All other versions register their class names with the existing Puc_v4_Factory, not their own factory class.

We can't really do much about the first one, but we can work around the second one by also registering each class with the version-specific factory.

See also #279
This commit is contained in:
Yahnis Elsts 2019-03-29 19:17:36 +02:00
parent 8499f5c429
commit 006bb9394f
1 changed files with 19 additions and 9 deletions

View File

@ -2,7 +2,7 @@
/**
* Plugin Update Checker Library 4.5
* http://w-shadow.com/
*
*
* Copyright 2019 Janis Elsts
* Released under the MIT license. See license.txt for details.
*/
@ -12,13 +12,23 @@ require dirname(__FILE__) . '/Puc/v4/Factory.php';
require dirname(__FILE__) . '/Puc/v4p5/Autoloader.php';
new Puc_v4p5_Autoloader();
//Register classes defined in this file with the factory.
Puc_v4_Factory::addVersion('Plugin_UpdateChecker', 'Puc_v4p5_Plugin_UpdateChecker', '4.5');
Puc_v4_Factory::addVersion('Theme_UpdateChecker', 'Puc_v4p5_Theme_UpdateChecker', '4.5');
//Register classes defined in this version with the factory.
foreach (
array(
'Plugin_UpdateChecker' => 'Puc_v4p5_Plugin_UpdateChecker',
'Theme_UpdateChecker' => 'Puc_v4p5_Theme_UpdateChecker',
Puc_v4_Factory::addVersion('Vcs_PluginUpdateChecker', 'Puc_v4p5_Vcs_PluginUpdateChecker', '4.5');
Puc_v4_Factory::addVersion('Vcs_ThemeUpdateChecker', 'Puc_v4p5_Vcs_ThemeUpdateChecker', '4.5');
'Vcs_PluginUpdateChecker' => 'Puc_v4p5_Vcs_PluginUpdateChecker',
'Vcs_ThemeUpdateChecker' => 'Puc_v4p5_Vcs_ThemeUpdateChecker',
Puc_v4_Factory::addVersion('GitHubApi', 'Puc_v4p5_Vcs_GitHubApi', '4.5');
Puc_v4_Factory::addVersion('BitBucketApi', 'Puc_v4p5_Vcs_BitBucketApi', '4.5');
Puc_v4_Factory::addVersion('GitLabApi', 'Puc_v4p5_Vcs_GitLabApi', '4.5');
'GitHubApi' => 'Puc_v4p5_Vcs_GitHubApi',
'BitBucketApi' => 'Puc_v4p5_Vcs_BitBucketApi',
'GitLabApi' => 'Puc_v4p5_Vcs_GitLabApi',
)
as $pucGeneralClass => $pucVersionedClass
) {
Puc_v4_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.5');
//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_v4p5_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.5');
}