Attempt to fix errors caused by using Composer-generated autoloaders 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.
This commit is contained in:
Yahnis Elsts 2019-09-27 17:06:01 +03:00
parent 0f490e940c
commit bbe88a70d6
7 changed files with 1577 additions and 1565 deletions

View File

@ -16,12 +16,9 @@ if ( !class_exists('Puc_v4p7_Autoloader', false) ):
$this->libraryDir = realpath($this->rootDir . '../..') . '/'; $this->libraryDir = realpath($this->rootDir . '../..') . '/';
$this->staticMap = array( $this->staticMap = array(
'PucReadmeParser' => 'vendor/readme-parser.php', 'PucReadmeParser' => 'vendor/PucReadmeParser.php',
'Parsedown' => 'vendor/ParsedownLegacy.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')); spl_autoload_register(array($this, 'autoload'));
} }

View File

@ -294,4 +294,25 @@ if ( !class_exists('Puc_v4p7_Factory', false) ):
} }
} }
//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; endif;

View File

@ -17,6 +17,11 @@
"php": ">=5.2.0" "php": ">=5.2.0"
}, },
"autoload": { "autoload": {
"files": ["plugin-update-checker.php"] "psr-0": {
"Puc_v4p7_" : "Puc/v4p7/",
"Puc_v4_" : "Puc/v4/",
"PucReadmeParser" : "vendor/",
"Parsedown" : "vendor/"
}
} }
} }

View File

@ -7,28 +7,8 @@
* Released under the MIT license. See license.txt for details. * 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'; require dirname(__FILE__) . '/Puc/v4p7/Autoloader.php';
new Puc_v4p7_Autoloader(); new Puc_v4p7_Autoloader();
//Register classes defined in this version with the factory. require dirname(__FILE__) . '/Puc/v4p7/Factory.php';
foreach ( require dirname(__FILE__) . '/Puc/v4/Factory.php';
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');
}

1545
vendor/Parsedown.php vendored

File diff suppressed because it is too large Load Diff

1538
vendor/ParsedownModern.php vendored Normal file

File diff suppressed because it is too large Load Diff