svn: /pear2/Autoload/trunk/src/ Autoload.php

From: Date: Wed, 22 Sep 2010 03:28:18 +0000
Subject: svn: /pear2/Autoload/trunk/src/ Autoload.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-9681@lists.php.net to get a copy of this message
saltybeagle Wed, 22 Sep 2010 03:28:18 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=303659 Log: Remove the dependency on include_path for a couple of reasons. 1. Speed. 2. include_path can be externally modified which can cause files that exist to not be loaded. Changed paths: U pear2/Autoload/trunk/src/Autoload.php Modified: pear2/Autoload/trunk/src/Autoload.php =================================================================== --- pear2/Autoload/trunk/src/Autoload.php 2010-09-22 02:59:36 UTC (rev 303658) +++ pear2/Autoload/trunk/src/Autoload.php 2010-09-22 03:28:18 UTC (rev 303659) @@ -53,17 +53,13 @@ /** * Add a path * - * @param string $path The directory to add to the include path + * @param string $path The directory to add to the set of PEAR2 paths * * @return void */ protected static function addPath($path) { if (!in_array($path, self::$paths)) { - $paths = explode(PATH_SEPARATOR, get_include_path()); - if (!in_array($path, $paths)) { - set_include_path(get_include_path() . PATH_SEPARATOR . $path); - } self::$paths[] = $path; } } @@ -80,17 +76,19 @@ if (strtolower(substr($class, 0, 6)) !== 'pear2\\') { return false; } - $file = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class) . '.php'; - $fp = @fopen($file, 'r', true); - if ($fp) { - fclose($fp); - require $file; - if (!class_exists($class, false) && !interface_exists($class, false)) { - die(new \Exception('Class ' . $class . ' was not present in ' . - $file . ' (include_path="' . get_include_path() . - '") [PEAR2_Autoload version 1.1]')); + foreach (self::$paths as $path) { + $file = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class) . '.php'; + $fp = @fopen($path . DIRECTORY_SEPARATOR . $file, 'r', true); + if ($fp) { + fclose($fp); + require $path . DIRECTORY_SEPARATOR . $file; + if (!class_exists($class, false) && !interface_exists($class, false)) { + die(new \Exception('Class ' . $class . ' was not present in ' . + $file . ' (include_path="' . get_include_path() . + '") [PEAR2_Autoload version 1.1]')); + } + return true; } - return true; } $e = new \Exception('Class ' . $class . ' could not be loaded from ' . $file . ', file does not exist (include_path="' . get_include_path() .

« previous php.pear.core (#9681) next »