1 | <?php |
||
16 | class ClassInterfaceCache |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
||
21 | * |
||
22 | * @var string[][] $interfaces |
||
23 | */ |
||
24 | private $interfaces = array(); |
||
25 | |||
26 | /** |
||
27 | * @type string[][] $aliases |
||
28 | */ |
||
29 | protected $aliases = array(); |
||
30 | |||
31 | |||
32 | /** |
||
33 | * @param string $fqn |
||
34 | * @return string |
||
35 | */ |
||
36 | public function getFqn($fqn) |
||
40 | |||
41 | |||
42 | /** |
||
43 | * @param string $fqn |
||
44 | * @return array |
||
45 | */ |
||
46 | public function getInterfaces($fqn) |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @param string $fqn |
||
65 | * @param string $interface |
||
66 | * @return bool |
||
67 | */ |
||
68 | public function hasInterface($fqn, $interface) |
||
74 | |||
75 | |||
76 | /** |
||
77 | * adds an alias for a classname |
||
78 | * |
||
79 | * @param string $fqn the class name that should be used (concrete class to replace interface) |
||
80 | * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
||
81 | * @param string $for_class the class that has the dependency (is type hinting for the interface) |
||
82 | */ |
||
83 | public function addAlias($fqn, $alias, $for_class = '') |
||
98 | |||
99 | |||
100 | /** |
||
101 | * returns TRUE if the provided FQN is an alias |
||
102 | * |
||
103 | * @param string $fqn |
||
104 | * @param string $for_class |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function isAlias($fqn = '', $for_class = '') |
||
118 | |||
119 | |||
120 | /** |
||
121 | * returns TRUE if the provided FQN is an alias |
||
122 | * |
||
123 | * @param string $fqn |
||
124 | * @return bool |
||
125 | */ |
||
126 | protected function isDirectAlias($fqn = '') |
||
130 | |||
131 | |||
132 | /** |
||
133 | * returns TRUE if the provided FQN is an alias for the specified class |
||
134 | * |
||
135 | * @param string $fqn |
||
136 | * @param string $for_class |
||
137 | * @return bool |
||
138 | */ |
||
139 | protected function isAliasForClass($fqn = '', $for_class = '') |
||
146 | |||
147 | |||
148 | /** |
||
149 | * returns FQN for provided alias if one exists, otherwise returns the original FQN |
||
150 | * functions recursively, so that multiple aliases can be used to drill down to a FQN |
||
151 | * for example: |
||
152 | * if the following two entries were added to the aliases array: |
||
153 | * array( |
||
154 | * 'interface_alias' => 'some\namespace\interface' |
||
155 | * 'some\namespace\interface' => 'some\namespace\classname' |
||
156 | * ) |
||
157 | * then one could use Loader::getNew( 'interface_alias' ) |
||
158 | * to load an instance of 'some\namespace\classname' |
||
159 | * |
||
160 | * @param string $alias |
||
161 | * @param string $for_class |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getFqnForAlias($alias = '', $for_class = '') |
||
175 | } |
||
176 |