mirror of
https://gh.wpcy.net/https://github.com/YahnisElsts/plugin-update-checker.git
synced 2026-05-03 14:43:49 +08:00
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.
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
if ( !class_exists('Puc_v4p7_Autoloader', false) ):
|
|
|
|
class Puc_v4p7_Autoloader {
|
|
private $prefix = '';
|
|
private $rootDir = '';
|
|
private $libraryDir = '';
|
|
|
|
private $staticMap;
|
|
|
|
public function __construct() {
|
|
$this->rootDir = dirname(__FILE__) . '/';
|
|
$nameParts = explode('_', __CLASS__, 3);
|
|
$this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
|
|
|
|
$this->libraryDir = realpath($this->rootDir . '../..') . '/';
|
|
$this->staticMap = array(
|
|
'PucReadmeParser' => 'vendor/PucReadmeParser.php',
|
|
'Parsedown' => 'vendor/Parsedown.php',
|
|
);
|
|
|
|
spl_autoload_register(array($this, 'autoload'));
|
|
}
|
|
|
|
public function autoload($className) {
|
|
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
|
|
/** @noinspection PhpIncludeInspection */
|
|
include ($this->libraryDir . $this->staticMap[$className]);
|
|
return;
|
|
}
|
|
|
|
if (strpos($className, $this->prefix) === 0) {
|
|
$path = substr($className, strlen($this->prefix));
|
|
$path = str_replace('_', '/', $path);
|
|
$path = $this->rootDir . $path . '.php';
|
|
|
|
if (file_exists($path)) {
|
|
/** @noinspection PhpIncludeInspection */
|
|
include $path;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
endif;
|