-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from boenrobot/master
Possible fix for #3, plus CS fixes
- Loading branch information
Showing
4 changed files
with
89 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
;; maintainers of Autoload | ||
Gregory Beaver [cellog] <[email protected]> (lead) | ||
Brett Bieber [saltybeagle] <[email protected]> (lead) | ||
Clay Loveless [clay] <[email protected]> (contributor) | ||
Clay Loveless [clay] <[email protected]> (contributor) | ||
Vasil Rangelov [boen_robot] <[email protected]> (contributor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,14 @@ To use: | |
<email>[email protected]</email> | ||
<active>yes</active> | ||
</contributor> | ||
<date>2011-08-08</date> | ||
<time>13:56:45</time> | ||
<contributor> | ||
<name>Vasil Rangelov</name> | ||
<user>boen_robot</user> | ||
<email>[email protected]</email> | ||
<active>yes</active> | ||
</contributor> | ||
<date>2012-02-05</date> | ||
<time>19:12:49</time> | ||
<version> | ||
<release>0.2.4</release> | ||
<api>0.1.0</api> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,14 @@ To use: | |
<email>[email protected]</email> | ||
<active>yes</active> | ||
</contributor> | ||
<date>2011-08-08</date> | ||
<time>13:56:45</time> | ||
<contributor> | ||
<name>Vasil Rangelov</name> | ||
<user>boen_robot</user> | ||
<email>[email protected]</email> | ||
<active>yes</active> | ||
</contributor> | ||
<date>2012-02-05</date> | ||
<time>19:12:49</time> | ||
<version> | ||
<release>0.2.4</release> | ||
<api>0.1.0</api> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* Standard Autoloader for PEAR2 | ||
* | ||
* PEAR2_Autoload is the standard method of class loading for development and | ||
* low-volume web sites using PEAR2 packages. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PEAR2 | ||
* @package PEAR2_Autoload | ||
* @author Gregory Beaver <[email protected]> | ||
* @author Brett Bieber <[email protected]> | ||
* @copyright 2012 PEAR2 | ||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | ||
* @version GIT: $Id$ | ||
* @link http://pear2.php.net/PEAR2_Autoload | ||
*/ | ||
namespace PEAR2; | ||
if (!class_exists('\PEAR2\Autoload', false)) { | ||
/** | ||
* Standard Autoloader for PEAR2 | ||
* | ||
* PEAR2_Autoload is the standard method of class loading for development | ||
* and low-volume web sites using PEAR2 packages. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PEAR2 | ||
* @package PEAR2_Autoload | ||
* @author Gregory Beaver <[email protected]> | ||
* @author Brett Bieber <[email protected]> | ||
* @copyright 2012 PEAR2 | ||
* @license http://www.opensource.org/licenses/bsd-license.php | ||
* New BSDLicense | ||
* @version GIT: $Id$ | ||
* @link http://pear2.php.net/PEAR2_Autoload | ||
*/ | ||
class Autoload | ||
{ | ||
/** | ||
|
@@ -48,7 +84,8 @@ class Autoload | |
/** | ||
* Initialize the PEAR2 autoloader | ||
* | ||
* @param string $path Directory path to register | ||
* @param string $path Directory path to register | ||
* @param string $mapfile Path to a mapping file to register. | ||
* | ||
* @return void | ||
*/ | ||
|
@@ -161,14 +198,20 @@ static function load($class) | |
} | ||
} | ||
|
||
$file = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class) . '.php'; | ||
$file = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class) . | ||
'.php'; | ||
foreach (self::$paths as $path) { | ||
if (file_exists($path . DIRECTORY_SEPARATOR . $file)) { | ||
require $path . DIRECTORY_SEPARATOR . $file; | ||
if (!self::loadSuccessful($class)) { | ||
throw new \Exception('Class ' . $class . ' was not present in ' . | ||
if (count(spl_autoload_functions()) > 1) { | ||
return false; | ||
} | ||
throw new \Exception( | ||
'Class ' . $class . ' was not present in ' . | ||
$path . DIRECTORY_SEPARATOR . $file . | ||
'") [PEAR2_Autoload-@PACKAGE_VERSION@]'); | ||
'") [PEAR2_Autoload-@PACKAGE_VERSION@]' | ||
); | ||
} | ||
|
||
if (in_array($class, self::$unmapped)) { | ||
|
@@ -177,18 +220,25 @@ static function load($class) | |
return true; | ||
} | ||
} | ||
|
||
$e = new \Exception('Class ' . $class . ' could not be loaded from ' . | ||
if (count(spl_autoload_functions()) > 1) { | ||
return false; | ||
} | ||
$e = new \Exception( | ||
'Class ' . $class . ' could not be loaded from ' . | ||
$file . ', file does not exist (registered paths="' . | ||
implode(PATH_SEPARATOR, self::$paths) . | ||
'") [PEAR2_Autoload-@PACKAGE_VERSION@]'); | ||
'") [PEAR2_Autoload-@PACKAGE_VERSION@]' | ||
); | ||
$trace = $e->getTrace(); | ||
if (isset($trace[2]) && isset($trace[2]['function']) && | ||
in_array($trace[2]['function'], array('class_exists', 'interface_exists'))) { | ||
$checkFunctions = array('class_exists', 'interface_exists'); | ||
if (isset($trace[2]) && isset($trace[2]['function']) | ||
&& in_array($trace[2]['function'], $checkFunctions) | ||
) { | ||
return false; | ||
} | ||
if (isset($trace[1]) && isset($trace[1]['function']) && | ||
in_array($trace[1]['function'], array('class_exists', 'interface_exists'))) { | ||
if (isset($trace[1]) && isset($trace[1]['function']) | ||
&& in_array($trace[1]['function'], $checkFunctions) | ||
) { | ||
return false; | ||
} | ||
throw $e; | ||
|
@@ -197,30 +247,32 @@ static function load($class) | |
/** | ||
* Check if the requested class was loaded from the specified path | ||
* | ||
* @param string $class The name of the class to check. | ||
* | ||
* @return bool | ||
*/ | ||
protected static function loadSuccessful($class) | ||
{ | ||
if (!class_exists($class, false) && !interface_exists($class, false)) { | ||
return false; | ||
} | ||
return true; | ||
return class_exists($class, false) || interface_exists($class, false); | ||
} | ||
|
||
/** | ||
* If possible, update the classmap file with newly-discovered | ||
* mapping. | ||
* | ||
* @param string $class Class name discovered | ||
* | ||
* @param string $class Class name discovered | ||
* @param string $origin File where class was found | ||
* | ||
* @return void | ||
*/ | ||
protected static function updateMap($class, $origin) | ||
{ | ||
if (is_writable(self::$mapfile) || is_writable(dirname(self::$mapfile))) { | ||
if (is_writable(self::$mapfile) | ||
|| is_writable(dirname(self::$mapfile)) | ||
) { | ||
self::$map[$class] = $origin; | ||
file_put_contents(self::$mapfile, | ||
file_put_contents( | ||
self::$mapfile, | ||
'<'."?php\n" | ||
. "// PEAR2\Autoload auto-generated classmap\n" | ||
. "return " . var_export(self::$map, true) . ';', | ||
|