File indexing completed on 2024-12-29 05:28:08
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Tool 0017 * @subpackage Framework 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Tool_Framework_Registry_EnabledInterface 0025 */ 0026 // require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php'; 0027 0028 // require_once 'Zend/Tool/Framework/Loader/Interface.php'; 0029 // require_once 'Zend/Tool/Framework/Manifest/Interface.php'; 0030 // require_once 'Zend/Tool/Framework/Provider/Interface.php'; 0031 0032 0033 /** 0034 * @category Zend 0035 * @package Zend_Tool 0036 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0037 * @license http://framework.zend.com/license/new-bsd New BSD License 0038 */ 0039 abstract class Zend_Tool_Framework_Loader_Abstract 0040 implements Zend_Tool_Framework_Loader_Interface, Zend_Tool_Framework_Registry_EnabledInterface 0041 { 0042 /** 0043 * @var Zend_Tool_Framework_Repository_Interface 0044 */ 0045 protected $_registry = null; 0046 0047 /** 0048 * @var array 0049 */ 0050 private $_retrievedFiles = array(); 0051 0052 /** 0053 * @var array 0054 */ 0055 private $_loadedClasses = array(); 0056 0057 /** 0058 * _getFiles 0059 * 0060 * @return array Array Of Files 0061 */ 0062 abstract protected function _getFiles(); 0063 0064 /** 0065 * setRegistry() - required by the enabled interface to get an instance of 0066 * the registry 0067 * 0068 * @param Zend_Tool_Framework_Registry_Interface $registry 0069 * @return Zend_Tool_Framework_Loader_Abstract 0070 */ 0071 public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry) 0072 { 0073 $this->_registry = $registry; 0074 return $this; 0075 } 0076 0077 /** 0078 * load() - called by the client initialize routine to load files 0079 * 0080 */ 0081 public function load() 0082 { 0083 $this->_retrievedFiles = $this->getRetrievedFiles(); 0084 $this->_loadedClasses = array(); 0085 0086 $manifestRepository = $this->_registry->getManifestRepository(); 0087 $providerRepository = $this->_registry->getProviderRepository(); 0088 0089 $loadedClasses = array(); 0090 0091 // loop through files and find the classes declared by loading the file 0092 foreach ($this->_retrievedFiles as $file) { 0093 if(is_dir($file)) { 0094 continue; 0095 } 0096 0097 $classesLoadedBefore = get_declared_classes(); 0098 $oldLevel = error_reporting(E_ALL | ~E_STRICT); // remove strict so that other packages wont throw warnings 0099 // should we lint the files here? i think so 0100 include_once $file; 0101 error_reporting($oldLevel); // restore old error level 0102 $classesLoadedAfter = get_declared_classes(); 0103 $loadedClasses = array_merge($loadedClasses, array_diff($classesLoadedAfter, $classesLoadedBefore)); 0104 } 0105 0106 // loop through the loaded classes and ensure that 0107 foreach ($loadedClasses as $loadedClass) { 0108 0109 // reflect class to see if its something we want to load 0110 $reflectionClass = new ReflectionClass($loadedClass); 0111 if ($reflectionClass->implementsInterface('Zend_Tool_Framework_Manifest_Interface') 0112 && !$reflectionClass->isAbstract()) 0113 { 0114 $manifestRepository->addManifest($reflectionClass->newInstance()); 0115 $this->_loadedClasses[] = $loadedClass; 0116 } 0117 0118 if ($reflectionClass->implementsInterface('Zend_Tool_Framework_Provider_Interface') 0119 && !$reflectionClass->isAbstract() 0120 && !$providerRepository->hasProvider($reflectionClass->getName(), false)) 0121 { 0122 $providerRepository->addProvider($reflectionClass->newInstance()); 0123 $this->_loadedClasses[] = $loadedClass; 0124 } 0125 0126 } 0127 0128 return $this->_loadedClasses; 0129 } 0130 0131 /** 0132 * getRetrievedFiles() 0133 * 0134 * @return array Array of Files Retrieved 0135 */ 0136 public function getRetrievedFiles() 0137 { 0138 if ($this->_retrievedFiles == null) { 0139 $this->_retrievedFiles = $this->_getFiles(); 0140 } 0141 0142 return $this->_retrievedFiles; 0143 } 0144 0145 /** 0146 * getLoadedClasses() 0147 * 0148 * @return array Array of Loaded Classes 0149 */ 0150 public function getLoadedClasses() 0151 { 0152 return $this->_loadedClasses; 0153 } 0154 0155 0156 }