|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Tool |
|
17 * @subpackage Framework |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Tool_Framework_Registry_EnabledInterface |
|
25 */ |
|
26 require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php'; |
|
27 |
|
28 require_once 'Zend/Tool/Framework/Loader/Interface.php'; |
|
29 require_once 'Zend/Tool/Framework/Manifest/Interface.php'; |
|
30 require_once 'Zend/Tool/Framework/Provider/Interface.php'; |
|
31 |
|
32 |
|
33 /** |
|
34 * @category Zend |
|
35 * @package Zend_Tool |
|
36 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
38 */ |
|
39 abstract class Zend_Tool_Framework_Loader_Abstract |
|
40 implements Zend_Tool_Framework_Loader_Interface, Zend_Tool_Framework_Registry_EnabledInterface |
|
41 { |
|
42 /** |
|
43 * @var Zend_Tool_Framework_Repository_Interface |
|
44 */ |
|
45 protected $_registry = null; |
|
46 |
|
47 /** |
|
48 * @var array |
|
49 */ |
|
50 private $_retrievedFiles = array(); |
|
51 |
|
52 /** |
|
53 * @var array |
|
54 */ |
|
55 private $_loadedClasses = array(); |
|
56 |
|
57 /** |
|
58 * _getFiles |
|
59 * |
|
60 * @return array Array Of Files |
|
61 */ |
|
62 abstract protected function _getFiles(); |
|
63 |
|
64 /** |
|
65 * setRegistry() - required by the enabled interface to get an instance of |
|
66 * the registry |
|
67 * |
|
68 * @param Zend_Tool_Framework_Registry_Interface $registry |
|
69 * @return Zend_Tool_Framework_Loader_Abstract |
|
70 */ |
|
71 public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry) |
|
72 { |
|
73 $this->_registry = $registry; |
|
74 return $this; |
|
75 } |
|
76 |
|
77 /** |
|
78 * load() - called by the client initialize routine to load files |
|
79 * |
|
80 */ |
|
81 public function load() |
|
82 { |
|
83 $this->_retrievedFiles = $this->getRetrievedFiles(); |
|
84 $this->_loadedClasses = array(); |
|
85 |
|
86 $manifestRepository = $this->_registry->getManifestRepository(); |
|
87 $providerRepository = $this->_registry->getProviderRepository(); |
|
88 |
|
89 $loadedClasses = array(); |
|
90 |
|
91 // loop through files and find the classes declared by loading the file |
|
92 foreach ($this->_retrievedFiles as $file) { |
|
93 if(is_dir($file)) { |
|
94 continue; |
|
95 } |
|
96 |
|
97 $classesLoadedBefore = get_declared_classes(); |
|
98 $oldLevel = error_reporting(E_ALL | ~E_STRICT); // remove strict so that other packages wont throw warnings |
|
99 // should we lint the files here? i think so |
|
100 include_once $file; |
|
101 error_reporting($oldLevel); // restore old error level |
|
102 $classesLoadedAfter = get_declared_classes(); |
|
103 $loadedClasses = array_merge($loadedClasses, array_diff($classesLoadedAfter, $classesLoadedBefore)); |
|
104 } |
|
105 |
|
106 // loop through the loaded classes and ensure that |
|
107 foreach ($loadedClasses as $loadedClass) { |
|
108 |
|
109 // reflect class to see if its something we want to load |
|
110 $reflectionClass = new ReflectionClass($loadedClass); |
|
111 if ($reflectionClass->implementsInterface('Zend_Tool_Framework_Manifest_Interface') |
|
112 && !$reflectionClass->isAbstract()) |
|
113 { |
|
114 $manifestRepository->addManifest($reflectionClass->newInstance()); |
|
115 $this->_loadedClasses[] = $loadedClass; |
|
116 } |
|
117 |
|
118 if ($reflectionClass->implementsInterface('Zend_Tool_Framework_Provider_Interface') |
|
119 && !$reflectionClass->isAbstract() |
|
120 && !$providerRepository->hasProvider($reflectionClass->getName(), false)) |
|
121 { |
|
122 $providerRepository->addProvider($reflectionClass->newInstance()); |
|
123 $this->_loadedClasses[] = $loadedClass; |
|
124 } |
|
125 |
|
126 } |
|
127 |
|
128 return $this->_loadedClasses; |
|
129 } |
|
130 |
|
131 /** |
|
132 * getRetrievedFiles() |
|
133 * |
|
134 * @return array Array of Files Retrieved |
|
135 */ |
|
136 public function getRetrievedFiles() |
|
137 { |
|
138 if ($this->_retrievedFiles == null) { |
|
139 $this->_retrievedFiles = $this->_getFiles(); |
|
140 } |
|
141 |
|
142 return $this->_retrievedFiles; |
|
143 } |
|
144 |
|
145 /** |
|
146 * getLoadedClasses() |
|
147 * |
|
148 * @return array Array of Loaded Classes |
|
149 */ |
|
150 public function getLoadedClasses() |
|
151 { |
|
152 return $this->_loadedClasses; |
|
153 } |
|
154 |
|
155 |
|
156 } |