Zend_Loader

Static methods for loading classes and files.

Defined (1)

The class is defined in the following location(s).

/inc/VideoUploader/includes/Zend/Loader.php  
  1. class Zend_Loader 
  2. /** 
  3. * Loads a class from a PHP file. The filename must be formatted 
  4. * as "$class.php". 
  5. * If $dirs is a string or an array, it will search the directories 
  6. * in the order supplied, and attempt to load the first matching file. 
  7. * If $dirs is null, it will split the class name at underscores to 
  8. * generate a path hierarchy (e.g., "Zend_Example_Class" will map 
  9. * to "Zend/Example/Class.php"). 
  10. * If the file was not found in the $dirs, or if no $dirs were specified,  
  11. * it will attempt to load it from PHP's include_path. 
  12. * @param string $class - The full class name of a Zend component. 
  13. * @param string|array $dirs - OPTIONAL Either a path or an array of paths 
  14. * to search. 
  15. * @return void 
  16. * @throws Zend_Exception 
  17. */ 
  18. public static function loadClass($class, $dirs = null) 
  19. if (class_exists($class, false) || interface_exists($class, false)) { 
  20. return; 
  21.  
  22. if ((null !== $dirs) && !is_string($dirs) && !is_array($dirs)) { 
  23. require_once 'Zend/Exception.php'; 
  24. throw new Zend_Exception('Directory argument must be a string or an array'); 
  25.  
  26. $file = self::standardiseFile($class); 
  27.  
  28. if (!empty($dirs)) { 
  29. // use the autodiscovered path 
  30. $dirPath = dirname($file); 
  31. if (is_string($dirs)) { 
  32. $dirs = explode(PATH_SEPARATOR, $dirs); 
  33. foreach ($dirs as $key => $dir) { 
  34. if ($dir == '.') { 
  35. $dirs[$key] = $dirPath; 
  36. } else { 
  37. $dir = rtrim($dir, '\\/'); 
  38. $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath; 
  39. $file = basename($file); 
  40. self::loadFile($file, $dirs, true); 
  41. } else { 
  42. self::loadFile($file, null, true); 
  43.  
  44. if (!class_exists($class, false) && !interface_exists($class, false)) { 
  45. require_once 'Zend/Exception.php'; 
  46. throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file"); 
  47.  
  48. /** 
  49. * Loads a PHP file. This is a wrapper for PHP's include() function. 
  50. * $filename must be the complete filename, including any 
  51. * extension such as ".php". Note that a security check is performed that 
  52. * does not permit extended characters in the filename. This method is 
  53. * intended for loading Zend Framework files. 
  54. * If $dirs is a string or an array, it will search the directories 
  55. * in the order supplied, and attempt to load the first matching file. 
  56. * If the file was not found in the $dirs, or if no $dirs were specified,  
  57. * it will attempt to load it from PHP's include_path. 
  58. * If $once is TRUE, it will use include_once() instead of include(). 
  59. * @param string $filename 
  60. * @param string|array $dirs - OPTIONAL either a path or array of paths 
  61. * to search. 
  62. * @param boolean $once 
  63. * @return boolean 
  64. * @throws Zend_Exception 
  65. */ 
  66. public static function loadFile($filename, $dirs = null, $once = false) 
  67. self::_securityCheck($filename); 
  68.  
  69. /** 
  70. * Search in provided directories, as well as include_path 
  71. */ 
  72. $incPath = false; 
  73. if (!empty($dirs) && (is_array($dirs) || is_string($dirs))) { 
  74. if (is_array($dirs)) { 
  75. $dirs = implode(PATH_SEPARATOR, $dirs); 
  76. $incPath = get_include_path(); 
  77. set_include_path($dirs . PATH_SEPARATOR . $incPath); 
  78.  
  79. /** 
  80. * Try finding for the plain filename in the include_path. 
  81. */ 
  82. if ($once) { 
  83. include_once $filename; 
  84. } else { 
  85. include $filename; 
  86.  
  87. /** 
  88. * If searching in directories, reset include_path 
  89. */ 
  90. if ($incPath) { 
  91. set_include_path($incPath); 
  92.  
  93. return true; 
  94.  
  95. /** 
  96. * Returns TRUE if the $filename is readable, or FALSE otherwise. 
  97. * This function uses the PHP include_path, where PHP's is_readable() 
  98. * does not. 
  99. * Note from ZF-2900: 
  100. * If you use custom error handler, please check whether return value 
  101. * from error_reporting() is zero or not. 
  102. * At mark of fopen() can not suppress warning if the handler is used. 
  103. * @param string $filename 
  104. * @return boolean 
  105. */ 
  106. public static function isReadable($filename) 
  107. if (is_readable($filename)) { 
  108. // Return early if the filename is readable without needing the 
  109. // include_path 
  110. return true; 
  111.  
  112. if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' 
  113. && preg_match('/^[a-z]:/i', $filename) 
  114. ) { 
  115. // If on windows, and path provided is clearly an absolute path,  
  116. // return false immediately 
  117. return false; 
  118.  
  119. foreach (self::explodeIncludePath() as $path) { 
  120. if ($path == '.') { 
  121. if (is_readable($filename)) { 
  122. return true; 
  123. continue; 
  124. $file = $path . '/' . $filename; 
  125. if (is_readable($file)) { 
  126. return true; 
  127. return false; 
  128.  
  129. /** 
  130. * Explode an include path into an array 
  131. * If no path provided, uses current include_path. Works around issues that 
  132. * occur when the path includes stream schemas. 
  133. * @param string|null $path 
  134. * @return array 
  135. */ 
  136. public static function explodeIncludePath($path = null) 
  137. if (null === $path) { 
  138. $path = get_include_path(); 
  139.  
  140. if (PATH_SEPARATOR == ':') { 
  141. // On *nix systems, include_paths which include paths with a stream 
  142. // schema cannot be safely explode'd, so we have to be a bit more 
  143. // intelligent in the approach. 
  144. $paths = preg_split('#:(?!//)#', $path); 
  145. } else { 
  146. $paths = explode(PATH_SEPARATOR, $path); 
  147. return $paths; 
  148.  
  149. /** 
  150. * spl_autoload() suitable implementation for supporting class autoloading. 
  151. * Attach to spl_autoload() using the following: 
  152. * <code> 
  153. * spl_autoload_register(array('Zend_Loader', 'autoload')); 
  154. * </code> 
  155. * @deprecated Since 1.8.0 
  156. * @param string $class 
  157. * @return string|false Class name on success; false on failure 
  158. */ 
  159. public static function autoload($class) 
  160. 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); 
  161. try { 
  162. @self::loadClass($class); 
  163. return $class; 
  164. } catch (Exception $e) { 
  165. return false; 
  166.  
  167. /** 
  168. * Register {@link autoload()} with spl_autoload() 
  169. * @deprecated Since 1.8.0 
  170. * @param string $class (optional) 
  171. * @param boolean $enabled (optional) 
  172. * @return void 
  173. * @throws Zend_Exception if spl_autoload() is not found 
  174. * or if the specified class does not have an autoload() method. 
  175. */ 
  176. public static function registerAutoload($class = 'Zend_Loader', $enabled = true) 
  177. 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); 
  178. require_once 'Zend/Loader/Autoloader.php'; 
  179. $autoloader = Zend_Loader_Autoloader::getInstance(); 
  180. $autoloader->setFallbackAutoloader(true); 
  181.  
  182. if ('Zend_Loader' != $class) { 
  183. self::loadClass($class); 
  184. $methods = get_class_methods($class); 
  185. if (!in_array('autoload', (array) $methods)) { 
  186. require_once 'Zend/Exception.php'; 
  187. throw new Zend_Exception("The class \"$class\" does not have an autoload() method"); 
  188.  
  189. $callback = array($class, 'autoload'); 
  190.  
  191. if ($enabled) { 
  192. $autoloader->pushAutoloader($callback); 
  193. } else { 
  194. $autoloader->removeAutoloader($callback); 
  195.  
  196. /** 
  197. * Ensure that filename does not contain exploits 
  198. * @param string $filename 
  199. * @return void 
  200. * @throws Zend_Exception 
  201. */ 
  202. protected static function _securityCheck($filename) 
  203. /** 
  204. * Security check 
  205. */ 
  206. if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) { 
  207. require_once 'Zend/Exception.php'; 
  208. throw new Zend_Exception('Security check: Illegal character in filename'); 
  209.  
  210. /** 
  211. * Attempt to include() the file. 
  212. * include() is not prefixed with the @ operator because if 
  213. * the file is loaded and contains a parse error, execution 
  214. * will halt silently and this is difficult to debug. 
  215. * Always set display_errors = Off on production servers! 
  216. * @param string $filespec 
  217. * @param boolean $once 
  218. * @return boolean 
  219. * @deprecated Since 1.5.0; use loadFile() instead 
  220. */ 
  221. protected static function _includeFile($filespec, $once = false) 
  222. if ($once) { 
  223. return include_once $filespec; 
  224. } else { 
  225. return include $filespec ; 
  226.  
  227. /** 
  228. * Standardise the filename. 
  229. * Convert the supplied filename into the namespace-aware standard,  
  230. * based on the Framework Interop Group reference implementation: 
  231. * http://groups.google.com/group/php-standards/web/psr-0-final-proposal 
  232. * The filename must be formatted as "$file.php". 
  233. * @param string $file - The file name to be loaded. 
  234. * @return string 
  235. */ 
  236. public static function standardiseFile($file) 
  237. $fileName = ltrim($file, '\\'); 
  238. $file = ''; 
  239. $namespace = ''; 
  240. if ($lastNsPos = strripos($fileName, '\\')) { 
  241. $namespace = substr($fileName, 0, $lastNsPos); 
  242. $fileName = substr($fileName, $lastNsPos + 1); 
  243. $file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; 
  244. $file .= str_replace('_', DIRECTORY_SEPARATOR, $fileName) . '.php'; 
  245. return $file;