Fix "Cannot declare class Puc_v4_Autoloader".

Oops, I knew I'd missed something! Well, this is that something.
This commit is contained in:
Yahnis Elsts 2017-01-13 18:49:54 +02:00
parent 1bf50ba942
commit fd62858e90
2 changed files with 39 additions and 35 deletions

View File

@ -1,45 +1,49 @@
<?php
class Puc_v4_Autoloader {
private $prefix = '';
private $rootDir = '';
private $libraryDir = '';
if ( !class_exists('Puc_v4_Autoloader', false) ):
private $staticMap;
class Puc_v4_Autoloader {
private $prefix = '';
private $rootDir = '';
private $libraryDir = '';
public function __construct() {
$this->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;
}
}
}
}
}
endif;

View File

@ -1,6 +1,6 @@
<?php
/**
* Plugin Update Checker Library 4.0
* Plugin Update Checker Library 4.0.2
* http://w-shadow.com/
*
* Copyright 2017 Janis Elsts