diff --git a/Puc/v4/Autoloader.php b/Puc/v4/Autoloader.php index 8376537..7e90fa5 100644 --- a/Puc/v4/Autoloader.php +++ b/Puc/v4/Autoloader.php @@ -1,45 +1,49 @@ rootDir = dirname(__FILE__) . '/'; - $nameParts = explode('_', __CLASS__, 3); - $this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_'; + private $staticMap; - $this->libraryDir = realpath($this->rootDir . '../..') . '/'; - $this->staticMap = array( - 'PucReadmeParser' => 'vendor/readme-parser.php', - 'Parsedown' => 'vendor/ParsedownLegacy.php', - ); - if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) { - $this->staticMap['Parsedown'] = 'vendor/Parsedown.php'; + 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/readme-parser.php', + 'Parsedown' => 'vendor/ParsedownLegacy.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')); - } - - 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)) { + public function autoload($className) { + if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) { /** @noinspection PhpIncludeInspection */ - include $path; + 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; + } } } } -} \ No newline at end of file + +endif; \ No newline at end of file diff --git a/plugin-update-checker.php b/plugin-update-checker.php index 8aff3eb..05837cc 100644 --- a/plugin-update-checker.php +++ b/plugin-update-checker.php @@ -1,6 +1,6 @@