@@ -11,10 +11,10 @@ |
||
11 | 11 | interface FactoryInterface |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param mixed $arguments Either a Fully Qualified Class Name |
|
16 | - * or array of data required for construction |
|
17 | - * @return mixed |
|
18 | - */ |
|
19 | - public static function create($arguments); |
|
14 | + /** |
|
15 | + * @param mixed $arguments Either a Fully Qualified Class Name |
|
16 | + * or array of data required for construction |
|
17 | + * @return mixed |
|
18 | + */ |
|
19 | + public static function create($arguments); |
|
20 | 20 | } |
@@ -14,19 +14,19 @@ |
||
14 | 14 | class MatchAnyRouteSpecification extends MultiRouteSpecification |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - foreach ($this->specifications as $specification) { |
|
26 | - if ($specification->isMatchingRoute()) { |
|
27 | - return true; |
|
28 | - } |
|
29 | - } |
|
30 | - return false; |
|
31 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + foreach ($this->specifications as $specification) { |
|
26 | + if ($specification->isMatchingRoute()) { |
|
27 | + return true; |
|
28 | + } |
|
29 | + } |
|
30 | + return false; |
|
31 | + } |
|
32 | 32 | } |
@@ -14,14 +14,14 @@ |
||
14 | 14 | */ |
15 | 15 | class DoesNotMatchRouteSpecification extends RouteMatchSpecificationDecorator |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return ! $this->specification->isMatchingRoute(); |
|
26 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return ! $this->specification->isMatchingRoute(); |
|
26 | + } |
|
27 | 27 | } |
@@ -12,11 +12,11 @@ |
||
12 | 12 | */ |
13 | 13 | interface RouteMatchSpecificationInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * returns true if current request matches specification |
|
17 | - * |
|
18 | - * @since $VID:$ |
|
19 | - * @return boolean |
|
20 | - */ |
|
21 | - public function isMatchingRoute(); |
|
15 | + /** |
|
16 | + * returns true if current request matches specification |
|
17 | + * |
|
18 | + * @since $VID:$ |
|
19 | + * @return boolean |
|
20 | + */ |
|
21 | + public function isMatchingRoute(); |
|
22 | 22 | } |
@@ -14,19 +14,19 @@ |
||
14 | 14 | class MatchAllRouteSpecifications extends MultiRouteSpecification |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - foreach ($this->specifications as $specification) { |
|
26 | - if (! $specification->isMatchingRoute()) { |
|
27 | - return false; |
|
28 | - } |
|
29 | - } |
|
30 | - return true; |
|
31 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + foreach ($this->specifications as $specification) { |
|
26 | + if (! $specification->isMatchingRoute()) { |
|
27 | + return false; |
|
28 | + } |
|
29 | + } |
|
30 | + return true; |
|
31 | + } |
|
32 | 32 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | public function isMatchingRoute() |
24 | 24 | { |
25 | 25 | foreach ($this->specifications as $specification) { |
26 | - if (! $specification->isMatchingRoute()) { |
|
26 | + if ( ! $specification->isMatchingRoute()) { |
|
27 | 27 | return false; |
28 | 28 | } |
29 | 29 | } |
@@ -14,18 +14,18 @@ |
||
14 | 14 | */ |
15 | 15 | class EspressoEventsListTable extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return $this->request->getRequestParam('page') === 'espresso_events' |
|
26 | - && ( |
|
27 | - $this->request->getRequestParam('action') === 'default' |
|
28 | - || $this->request->requestParamIsSet('action') === false |
|
29 | - ); |
|
30 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return $this->request->getRequestParam('page') === 'espresso_events' |
|
26 | + && ( |
|
27 | + $this->request->getRequestParam('action') === 'default' |
|
28 | + || $this->request->requestParamIsSet('action') === false |
|
29 | + ); |
|
30 | + } |
|
31 | 31 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | */ |
15 | 15 | class EspressoEventEditorAddNew extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return $this->request->getRequestParam('page') === 'espresso_events' |
|
26 | - && $this->request->getRequestParam('action') === 'create_new'; |
|
27 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return $this->request->getRequestParam('page') === 'espresso_events' |
|
26 | + && $this->request->getRequestParam('action') === 'create_new'; |
|
27 | + } |
|
28 | 28 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | */ |
15 | 15 | class EspressoEventEditorEdit extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since $VID:$ |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return $this->request->getRequestParam('page') === 'espresso_events' |
|
26 | - && $this->request->getRequestParam('action') === 'edit'; |
|
27 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since $VID:$ |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return $this->request->getRequestParam('page') === 'espresso_events' |
|
26 | + && $this->request->getRequestParam('action') === 'edit'; |
|
27 | + } |
|
28 | 28 | } |
@@ -17,165 +17,165 @@ |
||
17 | 17 | class ClassInterfaceCache |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
|
22 | - * |
|
23 | - * @var string[][] $interfaces |
|
24 | - */ |
|
25 | - private $interfaces = array(); |
|
26 | - |
|
27 | - /** |
|
28 | - * @type string[][] $aliases |
|
29 | - */ |
|
30 | - protected $aliases = array(); |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @param string $fqn |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function getFqn($fqn) |
|
38 | - { |
|
39 | - $fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn; |
|
40 | - return ltrim($fqn, '\\'); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @param string $fqn |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function getInterfaces($fqn) |
|
49 | - { |
|
50 | - $fqn = $this->getFqn($fqn); |
|
51 | - // have we already seen this FQCN ? |
|
52 | - if (! array_key_exists($fqn, $this->interfaces)) { |
|
53 | - $this->interfaces[ $fqn ] = array(); |
|
54 | - if (class_exists($fqn)) { |
|
55 | - $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
56 | - $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
57 | - ? $this->interfaces[ $fqn ] |
|
58 | - : array(); |
|
59 | - } |
|
60 | - } |
|
61 | - return $this->interfaces[ $fqn ]; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $fqn |
|
67 | - * @param string $interface |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function hasInterface($fqn, $interface) |
|
71 | - { |
|
72 | - $fqn = $this->getFqn($fqn); |
|
73 | - $interfaces = $this->getInterfaces($fqn); |
|
74 | - return in_array($interface, $interfaces, true); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * adds an alias for a classname |
|
80 | - * |
|
81 | - * @param string $fqn the class name that should be used (concrete class to replace interface) |
|
82 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
83 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
84 | - * @throws InvalidAliasException |
|
85 | - */ |
|
86 | - public function addAlias($fqn, $alias, $for_class = '') |
|
87 | - { |
|
88 | - $fqn = $this->getFqn($fqn); |
|
89 | - $alias = $this->getFqn($alias); |
|
90 | - if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) { |
|
91 | - throw new InvalidAliasException($fqn, $alias); |
|
92 | - } |
|
93 | - // are we adding an alias for a specific class? |
|
94 | - if ($for_class !== '') { |
|
95 | - // make sure it's set up as an array |
|
96 | - if (! isset($this->aliases[ $for_class ])) { |
|
97 | - $this->aliases[ $for_class ] = array(); |
|
98 | - } |
|
99 | - $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
100 | - return; |
|
101 | - } |
|
102 | - $this->aliases[ $alias ] = $fqn; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * returns TRUE if the provided FQN is an alias |
|
108 | - * |
|
109 | - * @param string $fqn |
|
110 | - * @param string $for_class |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function isAlias($fqn = '', $for_class = '') |
|
114 | - { |
|
115 | - $fqn = $this->getFqn($fqn); |
|
116 | - if ($this->isAliasForClass($fqn, $for_class)) { |
|
117 | - return true; |
|
118 | - } |
|
119 | - if ($for_class === '' && $this->isDirectAlias($fqn)) { |
|
120 | - return true; |
|
121 | - } |
|
122 | - return false; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * returns TRUE if the provided FQN is an alias |
|
128 | - * |
|
129 | - * @param string $fqn |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - protected function isDirectAlias($fqn = '') |
|
133 | - { |
|
134 | - return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * returns TRUE if the provided FQN is an alias for the specified class |
|
140 | - * |
|
141 | - * @param string $fqn |
|
142 | - * @param string $for_class |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - protected function isAliasForClass($fqn = '', $for_class = '') |
|
146 | - { |
|
147 | - return ( |
|
148 | - $for_class !== '' |
|
149 | - && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * returns FQN for provided alias if one exists, otherwise returns the original FQN |
|
156 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
157 | - * for example: |
|
158 | - * if the following two entries were added to the aliases array: |
|
159 | - * array( |
|
160 | - * 'interface_alias' => 'some\namespace\interface' |
|
161 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
162 | - * ) |
|
163 | - * then one could use Loader::getNew( 'interface_alias' ) |
|
164 | - * to load an instance of 'some\namespace\classname' |
|
165 | - * |
|
166 | - * @param string $alias |
|
167 | - * @param string $for_class |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
171 | - { |
|
172 | - $alias = $this->getFqn($alias); |
|
173 | - if ($this->isAliasForClass($alias, $for_class)) { |
|
174 | - return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
175 | - } |
|
176 | - if ($this->isDirectAlias($alias)) { |
|
177 | - return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
178 | - } |
|
179 | - return $alias; |
|
180 | - } |
|
20 | + /** |
|
21 | + * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
|
22 | + * |
|
23 | + * @var string[][] $interfaces |
|
24 | + */ |
|
25 | + private $interfaces = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * @type string[][] $aliases |
|
29 | + */ |
|
30 | + protected $aliases = array(); |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @param string $fqn |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function getFqn($fqn) |
|
38 | + { |
|
39 | + $fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn; |
|
40 | + return ltrim($fqn, '\\'); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @param string $fqn |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function getInterfaces($fqn) |
|
49 | + { |
|
50 | + $fqn = $this->getFqn($fqn); |
|
51 | + // have we already seen this FQCN ? |
|
52 | + if (! array_key_exists($fqn, $this->interfaces)) { |
|
53 | + $this->interfaces[ $fqn ] = array(); |
|
54 | + if (class_exists($fqn)) { |
|
55 | + $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
56 | + $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
57 | + ? $this->interfaces[ $fqn ] |
|
58 | + : array(); |
|
59 | + } |
|
60 | + } |
|
61 | + return $this->interfaces[ $fqn ]; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $fqn |
|
67 | + * @param string $interface |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function hasInterface($fqn, $interface) |
|
71 | + { |
|
72 | + $fqn = $this->getFqn($fqn); |
|
73 | + $interfaces = $this->getInterfaces($fqn); |
|
74 | + return in_array($interface, $interfaces, true); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * adds an alias for a classname |
|
80 | + * |
|
81 | + * @param string $fqn the class name that should be used (concrete class to replace interface) |
|
82 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
83 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
84 | + * @throws InvalidAliasException |
|
85 | + */ |
|
86 | + public function addAlias($fqn, $alias, $for_class = '') |
|
87 | + { |
|
88 | + $fqn = $this->getFqn($fqn); |
|
89 | + $alias = $this->getFqn($alias); |
|
90 | + if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) { |
|
91 | + throw new InvalidAliasException($fqn, $alias); |
|
92 | + } |
|
93 | + // are we adding an alias for a specific class? |
|
94 | + if ($for_class !== '') { |
|
95 | + // make sure it's set up as an array |
|
96 | + if (! isset($this->aliases[ $for_class ])) { |
|
97 | + $this->aliases[ $for_class ] = array(); |
|
98 | + } |
|
99 | + $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
100 | + return; |
|
101 | + } |
|
102 | + $this->aliases[ $alias ] = $fqn; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * returns TRUE if the provided FQN is an alias |
|
108 | + * |
|
109 | + * @param string $fqn |
|
110 | + * @param string $for_class |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function isAlias($fqn = '', $for_class = '') |
|
114 | + { |
|
115 | + $fqn = $this->getFqn($fqn); |
|
116 | + if ($this->isAliasForClass($fqn, $for_class)) { |
|
117 | + return true; |
|
118 | + } |
|
119 | + if ($for_class === '' && $this->isDirectAlias($fqn)) { |
|
120 | + return true; |
|
121 | + } |
|
122 | + return false; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * returns TRUE if the provided FQN is an alias |
|
128 | + * |
|
129 | + * @param string $fqn |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + protected function isDirectAlias($fqn = '') |
|
133 | + { |
|
134 | + return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * returns TRUE if the provided FQN is an alias for the specified class |
|
140 | + * |
|
141 | + * @param string $fqn |
|
142 | + * @param string $for_class |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + protected function isAliasForClass($fqn = '', $for_class = '') |
|
146 | + { |
|
147 | + return ( |
|
148 | + $for_class !== '' |
|
149 | + && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * returns FQN for provided alias if one exists, otherwise returns the original FQN |
|
156 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
157 | + * for example: |
|
158 | + * if the following two entries were added to the aliases array: |
|
159 | + * array( |
|
160 | + * 'interface_alias' => 'some\namespace\interface' |
|
161 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
162 | + * ) |
|
163 | + * then one could use Loader::getNew( 'interface_alias' ) |
|
164 | + * to load an instance of 'some\namespace\classname' |
|
165 | + * |
|
166 | + * @param string $alias |
|
167 | + * @param string $for_class |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
171 | + { |
|
172 | + $alias = $this->getFqn($alias); |
|
173 | + if ($this->isAliasForClass($alias, $for_class)) { |
|
174 | + return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
175 | + } |
|
176 | + if ($this->isDirectAlias($alias)) { |
|
177 | + return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
178 | + } |
|
179 | + return $alias; |
|
180 | + } |
|
181 | 181 | } |