Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Loader.php
Go to the documentation of this file.
00001 <?php
00030 class Zend_Loader
00031 {
00052     public static function loadClass($class, $dirs = null)
00053     {
00054         if (class_exists($class, false) || interface_exists($class, false)) {
00055             return;
00056         }
00057 
00058         if ((null !== $dirs) && !is_string($dirs) && !is_array($dirs)) {
00059             require_once 'Zend/Exception.php';
00060             throw new Zend_Exception('Directory argument must be a string or an array');
00061         }
00062 
00063         // Autodiscover the path from the class name
00064         // Implementation is PHP namespace-aware, and based on 
00065         // Framework Interop Group reference implementation:
00066         // http://groups.google.com/group/php-standards/web/psr-0-final-proposal
00067         $className = ltrim($class, '\\');
00068         $file      = '';
00069         $namespace = '';
00070         if ($lastNsPos = strripos($className, '\\')) {
00071             $namespace = substr($className, 0, $lastNsPos);
00072             $className = substr($className, $lastNsPos + 1);
00073             $file      = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
00074         }
00075         $file .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
00076 
00077         if (!empty($dirs)) {
00078             // use the autodiscovered path
00079             $dirPath = dirname($file);
00080             if (is_string($dirs)) {
00081                 $dirs = explode(PATH_SEPARATOR, $dirs);
00082             }
00083             foreach ($dirs as $key => $dir) {
00084                 if ($dir == '.') {
00085                     $dirs[$key] = $dirPath;
00086                 } else {
00087                     $dir = rtrim($dir, '\\/');
00088                     $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath;
00089                 }
00090             }
00091             $file = basename($file);
00092             self::loadFile($file, $dirs, true);
00093         } else {
00094             self::loadFile($file, null, true);
00095         }
00096 
00097         if (!class_exists($class, false) && !interface_exists($class, false)) {
00098             require_once 'Zend/Exception.php';
00099             throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file");
00100         }
00101     }
00102 
00126     public static function loadFile($filename, $dirs = null, $once = false)
00127     {
00128         self::_securityCheck($filename);
00129 
00133         $incPath = false;
00134         if (!empty($dirs) && (is_array($dirs) || is_string($dirs))) {
00135             if (is_array($dirs)) {
00136                 $dirs = implode(PATH_SEPARATOR, $dirs);
00137             }
00138             $incPath = get_include_path();
00139             set_include_path($dirs . PATH_SEPARATOR . $incPath);
00140         }
00141 
00145         if ($once) {
00146             include_once $filename;
00147         } else {
00148             include $filename;
00149         }
00150 
00154         if ($incPath) {
00155             set_include_path($incPath);
00156         }
00157 
00158         return true;
00159     }
00160 
00174     public static function isReadable($filename)
00175     {
00176         if (is_readable($filename)) {
00177             // Return early if the filename is readable without needing the 
00178             // include_path
00179             return true;
00180         }
00181 
00182         if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'
00183             && preg_match('/^[a-z]:/i', $filename)
00184         ) {
00185             // If on windows, and path provided is clearly an absolute path, 
00186             // return false immediately
00187             return false;
00188         }
00189 
00190         foreach (self::explodeIncludePath() as $path) {
00191             if ($path == '.') {
00192                 if (is_readable($filename)) {
00193                     return true;
00194                 }
00195                 continue;
00196             }
00197             $file = $path . '/' . $filename;
00198             if (is_readable($file)) {
00199                 return true;
00200             }
00201         }
00202         return false;
00203     }
00204 
00214     public static function explodeIncludePath($path = null)
00215     {
00216         if (null === $path) {
00217             $path = get_include_path();
00218         }
00219 
00220         if (PATH_SEPARATOR == ':') {
00221             // On *nix systems, include_paths which include paths with a stream 
00222             // schema cannot be safely explode'd, so we have to be a bit more
00223             // intelligent in the approach.
00224             $paths = preg_split('#:(?!//)#', $path);
00225         } else {
00226             $paths = explode(PATH_SEPARATOR, $path);
00227         }
00228         return $paths;
00229     }
00230 
00243     public static function autoload($class)
00244     {
00245         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);
00246         try {
00247             @self::loadClass($class);
00248             return $class;
00249         } catch (Exception $e) {
00250             return false;
00251         }
00252     }
00253 
00264     public static function registerAutoload($class = 'Zend_Loader', $enabled = true)
00265     {
00266         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);
00267         require_once 'Zend/Loader/Autoloader.php';
00268         $autoloader = Zend_Loader_Autoloader::getInstance();
00269         $autoloader->setFallbackAutoloader(true);
00270 
00271         if ('Zend_Loader' != $class) {
00272             self::loadClass($class);
00273             $methods = get_class_methods($class);
00274             if (!in_array('autoload', (array) $methods)) {
00275                 require_once 'Zend/Exception.php';
00276                 throw new Zend_Exception("The class \"$class\" does not have an autoload() method");
00277             }
00278 
00279             $callback = array($class, 'autoload');
00280 
00281             if ($enabled) {
00282                 $autoloader->pushAutoloader($callback);
00283             } else {
00284                 $autoloader->removeAutoloader($callback);
00285             }
00286         }
00287     }
00288 
00296     protected static function _securityCheck($filename)
00297     {
00301         if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) {
00302             require_once 'Zend/Exception.php';
00303             throw new Zend_Exception('Security check: Illegal character in filename');
00304         }
00305     }
00306 
00321     protected static function _includeFile($filespec, $once = false)
00322     {
00323         if ($once) {
00324             return include_once $filespec;
00325         } else {
00326             return include $filespec ;
00327         }
00328     }
00329 }
 All Data Structures Namespaces Files Functions Variables Enumerations