1 | <?php |
||
20 | class ClassInterfaceCache |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
||
25 | * |
||
26 | * @var string[][] $interfaces |
||
27 | */ |
||
28 | private $interfaces = array(); |
||
29 | |||
30 | /** |
||
31 | * @type string[][] $aliases |
||
32 | */ |
||
33 | protected $aliases = array(); |
||
34 | |||
35 | |||
36 | |||
37 | /** |
||
38 | * @param string $fqn |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getFqn($fqn) |
||
45 | |||
46 | |||
47 | |||
48 | /** |
||
49 | * @param string $fqn |
||
50 | * @return array |
||
51 | */ |
||
52 | public function getInterfaces($fqn) |
||
67 | |||
68 | |||
69 | /** |
||
70 | * @param string $fqn |
||
71 | * @param string $interface |
||
72 | * @return bool |
||
73 | */ |
||
74 | public function hasInterface($fqn, $interface) |
||
80 | |||
81 | |||
82 | /** |
||
83 | * adds an alias for a classname |
||
84 | * |
||
85 | * @param string $fqn the class name that should be used (concrete class to replace interface) |
||
86 | * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
||
87 | * @param string $for_class the class that has the dependency (is type hinting for the interface) |
||
88 | */ |
||
89 | public function addAlias($fqn, $alias, $for_class = '') |
||
101 | |||
102 | |||
103 | /** |
||
104 | * returns TRUE if the provided FQN is an alias |
||
105 | * |
||
106 | * @param string $fqn |
||
107 | * @param string $for_class |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function isAlias($fqn = '', $for_class = '') |
||
121 | |||
122 | |||
123 | /** |
||
124 | * returns TRUE if the provided FQN is an alias |
||
125 | * |
||
126 | * @param string $fqn |
||
127 | * @return bool |
||
128 | */ |
||
129 | protected function isDirectAlias($fqn = '') |
||
133 | |||
134 | |||
135 | /** |
||
136 | * returns TRUE if the provided FQN is an alias for the specified class |
||
137 | * |
||
138 | * @param string $fqn |
||
139 | * @param string $for_class |
||
140 | * @return bool |
||
141 | */ |
||
142 | protected function isAliasForClass($fqn = '', $for_class = '') |
||
149 | |||
150 | |||
151 | /** |
||
152 | * returns FQN for provided alias if one exists, otherwise returns the original FQN |
||
153 | * functions recursively, so that multiple aliases can be used to drill down to a FQN |
||
154 | * for example: |
||
155 | * if the following two entries were added to the aliases array: |
||
156 | * array( |
||
157 | * 'interface_alias' => 'some\namespace\interface' |
||
158 | * 'some\namespace\interface' => 'some\namespace\classname' |
||
159 | * ) |
||
160 | * then one could use Loader::getNew( 'interface_alias' ) |
||
161 | * to load an instance of 'some\namespace\classname' |
||
162 | * |
||
163 | * @param string $alias |
||
164 | * @param string $for_class |
||
165 | * @return string |
||
166 | */ |
||
167 | public function getFqnForAlias($alias = '', $for_class = '') |
||
178 | } |
||
179 |