1 | <?php |
||
29 | class MetaCache |
||
30 | { |
||
31 | |||
32 | private $_metaClass = null; |
||
33 | private $_component = null; |
||
34 | |||
35 | /** |
||
36 | * Options |
||
37 | * @var string |
||
38 | */ |
||
39 | private $_instanceId = null; |
||
40 | |||
41 | /** |
||
42 | * Addendum runtime path |
||
43 | * @var string |
||
44 | */ |
||
45 | private $_path = ''; |
||
46 | |||
47 | /** |
||
48 | * |
||
49 | * @var NsCache |
||
50 | */ |
||
51 | private $_nsCache = null; |
||
52 | |||
53 | /** |
||
54 | * Runtime path |
||
55 | * @var string |
||
56 | */ |
||
57 | private static $_runtimePath = null; |
||
58 | |||
59 | /** |
||
60 | * Local cacheq |
||
61 | * @var type |
||
62 | */ |
||
63 | private static $_cache = []; |
||
64 | |||
65 | 3 | public function __construct($metaClass = null, AnnotatedInterface $component = null, MetaOptions $options = null) |
|
66 | { |
||
67 | 3 | if (null === self::$_runtimePath) |
|
68 | 3 | { |
|
69 | self::$_runtimePath = (new ConfigDetector)->getRuntimePath(); |
||
70 | } |
||
71 | 3 | $this->_path = self::$_runtimePath . '/addendum'; |
|
72 | 3 | $this->_metaClass = $metaClass; |
|
73 | 3 | $this->_component = $component; |
|
74 | 3 | if (empty($options)) |
|
75 | 3 | { |
|
76 | 3 | $this->_instanceId = Addendum::DefaultInstanceId; |
|
77 | 3 | } |
|
78 | else |
||
79 | { |
||
80 | $this->_instanceId = $options->instanceId; |
||
81 | } |
||
82 | 3 | $this->_nsCache = new NsCache(dirname($this->_getFilename()), Addendum::fly($this->_instanceId)); |
|
83 | 3 | } |
|
84 | |||
85 | 32 | public function setComponent(AnnotatedInterface $component = null) |
|
89 | |||
90 | 32 | public function setOptions(MetaOptions $options = null) |
|
94 | |||
95 | 32 | public function prepare() |
|
125 | |||
126 | 32 | public function get() |
|
151 | |||
152 | 21 | public function set(Meta $meta) |
|
166 | |||
167 | public function remove() |
||
177 | |||
178 | /** |
||
179 | * Clear entire cache |
||
180 | * @return boolean |
||
181 | */ |
||
182 | 3 | public function clear() |
|
186 | |||
187 | 2 | private function _clearCurrent() |
|
191 | |||
192 | 3 | private function _clear($path) |
|
204 | |||
205 | 34 | private function _getFilename() |
|
209 | |||
210 | 34 | private function _classToFile($className) |
|
214 | |||
215 | /** |
||
216 | * Recursively create dir with proper permissions. |
||
217 | * |
||
218 | * @param string $path |
||
219 | */ |
||
220 | 32 | private function mkdir($path) |
|
226 | |||
227 | } |
||
228 |