diff options
Diffstat (limited to 'libs/Zend/Loader.php')
-rw-r--r-- | libs/Zend/Loader.php | 89 |
1 files changed, 74 insertions, 15 deletions
diff --git a/libs/Zend/Loader.php b/libs/Zend/Loader.php index bfa962a62d..b5ae731ef0 100644 --- a/libs/Zend/Loader.php +++ b/libs/Zend/Loader.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Loader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Loader.php 16206 2009-06-21 19:15:37Z thomas $ + * @version $Id: Loader.php 22020 2010-04-27 16:35:56Z matthew $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Loader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Loader @@ -56,12 +56,24 @@ class Zend_Loader } if ((null !== $dirs) && !is_string($dirs) && !is_array($dirs)) { - require_once 'Zend/Exception.php'; + // require_once 'Zend/Exception.php'; throw new Zend_Exception('Directory argument must be a string or an array'); } - // autodiscover the path from the class name - $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; + // Autodiscover the path from the class name + // Implementation is PHP namespace-aware, and based on + // Framework Interop Group reference implementation: + // http://groups.google.com/group/php-standards/web/psr-0-final-proposal + $className = ltrim($class, '\\'); + $file = ''; + $namespace = ''; + if ($lastNsPos = strripos($className, '\\')) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + } + $file .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; + if (!empty($dirs)) { // use the autodiscovered path $dirPath = dirname($file); @@ -79,12 +91,11 @@ class Zend_Loader $file = basename($file); self::loadFile($file, $dirs, true); } else { - self::_securityCheck($file); - include $file; + self::loadFile($file, null, true); } if (!class_exists($class, false) && !interface_exists($class, false)) { - require_once 'Zend/Exception.php'; + // require_once 'Zend/Exception.php'; throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file"); } } @@ -162,11 +173,59 @@ class Zend_Loader */ public static function isReadable($filename) { - if (!$fh = @fopen($filename, 'r', true)) { + if (is_readable($filename)) { + // Return early if the filename is readable without needing the + // include_path + return true; + } + + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' + && preg_match('/^[a-z]:/i', $filename) + ) { + // If on windows, and path provided is clearly an absolute path, + // return false immediately return false; } - @fclose($fh); - return true; + + foreach (self::explodeIncludePath() as $path) { + if ($path == '.') { + if (is_readable($filename)) { + return true; + } + continue; + } + $file = $path . '/' . $filename; + if (is_readable($file)) { + return true; + } + } + return false; + } + + /** + * Explode an include path into an array + * + * If no path provided, uses current include_path. Works around issues that + * occur when the path includes stream schemas. + * + * @param string|null $path + * @return array + */ + public static function explodeIncludePath($path = null) + { + if (null === $path) { + $path = get_include_path(); + } + + if (PATH_SEPARATOR == ':') { + // On *nix systems, include_paths which include paths with a stream + // schema cannot be safely explode'd, so we have to be a bit more + // intelligent in the approach. + $paths = preg_split('#:(?!//)#', $path); + } else { + $paths = explode(PATH_SEPARATOR, $path); + } + return $paths; } /** @@ -205,7 +264,7 @@ class Zend_Loader public static function registerAutoload($class = 'Zend_Loader', $enabled = true) { trigger_error(__CLASS__ . '::' . __METHOD__ . ' is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead', E_USER_NOTICE); - require_once 'Zend/Loader/Autoloader.php'; + // require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->setFallbackAutoloader(true); @@ -213,7 +272,7 @@ class Zend_Loader self::loadClass($class); $methods = get_class_methods($class); if (!in_array('autoload', (array) $methods)) { - require_once 'Zend/Exception.php'; + // require_once 'Zend/Exception.php'; throw new Zend_Exception("The class \"$class\" does not have an autoload() method"); } @@ -240,7 +299,7 @@ class Zend_Loader * Security check */ if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) { - require_once 'Zend/Exception.php'; + // require_once 'Zend/Exception.php'; throw new Zend_Exception('Security check: Illegal character in filename'); } } |