@@ -17,158 +17,158 @@ |
||
| 17 | 17 | class FqcnLocator extends Locator |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var array $FQCNs |
|
| 22 | - */ |
|
| 23 | - protected $FQCNs = array(); |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var array $namespaces |
|
| 27 | - */ |
|
| 28 | - protected $namespaces = array(); |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @access protected |
|
| 33 | - * @param string $namespace |
|
| 34 | - * @param string $namespace_base_dir |
|
| 35 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 36 | - */ |
|
| 37 | - protected function setNamespace($namespace, $namespace_base_dir) |
|
| 38 | - { |
|
| 39 | - if (! is_string($namespace)) { |
|
| 40 | - throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
|
| 41 | - } |
|
| 42 | - if (! is_string($namespace_base_dir)) { |
|
| 43 | - throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
|
| 44 | - } |
|
| 45 | - $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @access public |
|
| 51 | - * @return array |
|
| 52 | - */ |
|
| 53 | - public function getFQCNs() |
|
| 54 | - { |
|
| 55 | - return $this->FQCNs; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @access public |
|
| 61 | - * @return int |
|
| 62 | - */ |
|
| 63 | - public function count() |
|
| 64 | - { |
|
| 65 | - return count($this->FQCNs); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * given a valid namespace, will find all files that match the provided mask |
|
| 71 | - * |
|
| 72 | - * @access public |
|
| 73 | - * @param string|array $namespaces |
|
| 74 | - * @return FilesystemIterator |
|
| 75 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 76 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 77 | - */ |
|
| 78 | - public function locate($namespaces) |
|
| 79 | - { |
|
| 80 | - if (! (is_string($namespaces) || is_array($namespaces))) { |
|
| 81 | - throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
|
| 82 | - } |
|
| 83 | - foreach ((array) $namespaces as $namespace) { |
|
| 84 | - foreach ($this->FindFQCNsByNamespace($namespace) as $key => $file) { |
|
| 85 | - $this->FQCNs[ $key ] = $file; |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - return $this->FQCNs; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * given a partial namespace, will find all files in that folder |
|
| 96 | - * ** PLZ NOTE ** |
|
| 97 | - * This assumes that all files within the specified folder should be loaded |
|
| 98 | - * |
|
| 99 | - * @access protected |
|
| 100 | - * @param array $partial_namespace |
|
| 101 | - * @return FilesystemIterator |
|
| 102 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 103 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 104 | - */ |
|
| 105 | - protected function FindFQCNsByNamespace($partial_namespace) |
|
| 106 | - { |
|
| 107 | - $iterator = new FilesystemIterator( |
|
| 108 | - $this->getDirectoryFromPartialNamespace($partial_namespace) |
|
| 109 | - ); |
|
| 110 | - foreach ($this->flags as $flag) { |
|
| 111 | - $iterator->setFlags($flag); |
|
| 112 | - } |
|
| 113 | - if (iterator_count($iterator) === 0) { |
|
| 114 | - return array(); |
|
| 115 | - } |
|
| 116 | - foreach ($iterator as $file) { |
|
| 117 | - $file = \EEH_File::standardise_directory_separators($file); |
|
| 118 | - foreach ($this->namespaces as $namespace => $base_dir) { |
|
| 119 | - $namespace .= Psr4Autoloader::NS; |
|
| 120 | - if (strpos($file, $base_dir) === 0) { |
|
| 121 | - $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
| 122 | - array($base_dir, DS, '.php'), |
|
| 123 | - array($namespace, Psr4Autoloader::NS, ''), |
|
| 124 | - $file |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - return $this->FQCNs; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * getDirectoryFromPartialNamespace |
|
| 135 | - * |
|
| 136 | - * @access protected |
|
| 137 | - * @param string $partial_namespace almost fully qualified class name ? |
|
| 138 | - * @return string |
|
| 139 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 140 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 141 | - */ |
|
| 142 | - protected function getDirectoryFromPartialNamespace($partial_namespace) |
|
| 143 | - { |
|
| 144 | - if (empty($partial_namespace)) { |
|
| 145 | - throw new InvalidClassException($partial_namespace); |
|
| 146 | - } |
|
| 147 | - // load our PSR-4 Autoloader so we can get the list of registered namespaces from it |
|
| 148 | - $psr4_loader = \EE_Psr4AutoloaderInit::psr4_loader(); |
|
| 149 | - // breakup the incoming namespace into segments then loop thru them |
|
| 150 | - $namespace_segments = explode(Psr4Autoloader::NS, trim($partial_namespace, Psr4Autoloader::NS)); |
|
| 151 | - $prefix = null; |
|
| 152 | - $namespace_segments_to_try = $namespace_segments; |
|
| 153 | - $removed_namespace_segments = []; |
|
| 154 | - while( ! empty($namespace_segments_to_try)) { |
|
| 155 | - $namespace_to_try = implode( Psr4Autoloader::NS, $namespace_segments_to_try); |
|
| 156 | - // check if there's a base directory registered for that namespace |
|
| 157 | - $prefix = $psr4_loader->prefixes($namespace_to_try . Psr4Autoloader::NS); |
|
| 158 | - // nope? then the incoming namespace is invalid |
|
| 159 | - if (! empty($prefix) && ! empty($prefix[0])) { |
|
| 160 | - break; |
|
| 161 | - } |
|
| 162 | - array_unshift( |
|
| 163 | - $removed_namespace_segments, |
|
| 164 | - array_pop($namespace_segments_to_try) |
|
| 165 | - ); |
|
| 166 | - }// nope? then the incoming namespace is invalid |
|
| 167 | - if (empty($prefix) || empty($prefix[0])) { |
|
| 168 | - throw new InvalidClassException($partial_namespace); |
|
| 169 | - } |
|
| 170 | - $this->setNamespace($namespace_to_try, $prefix[0]); |
|
| 171 | - // but if it's good, add that base directory to the rest of the path, and return it |
|
| 172 | - return $prefix[0] . implode(DS, $removed_namespace_segments) . DS; |
|
| 173 | - } |
|
| 20 | + /** |
|
| 21 | + * @var array $FQCNs |
|
| 22 | + */ |
|
| 23 | + protected $FQCNs = array(); |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var array $namespaces |
|
| 27 | + */ |
|
| 28 | + protected $namespaces = array(); |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @access protected |
|
| 33 | + * @param string $namespace |
|
| 34 | + * @param string $namespace_base_dir |
|
| 35 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 36 | + */ |
|
| 37 | + protected function setNamespace($namespace, $namespace_base_dir) |
|
| 38 | + { |
|
| 39 | + if (! is_string($namespace)) { |
|
| 40 | + throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
|
| 41 | + } |
|
| 42 | + if (! is_string($namespace_base_dir)) { |
|
| 43 | + throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
|
| 44 | + } |
|
| 45 | + $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @access public |
|
| 51 | + * @return array |
|
| 52 | + */ |
|
| 53 | + public function getFQCNs() |
|
| 54 | + { |
|
| 55 | + return $this->FQCNs; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @access public |
|
| 61 | + * @return int |
|
| 62 | + */ |
|
| 63 | + public function count() |
|
| 64 | + { |
|
| 65 | + return count($this->FQCNs); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * given a valid namespace, will find all files that match the provided mask |
|
| 71 | + * |
|
| 72 | + * @access public |
|
| 73 | + * @param string|array $namespaces |
|
| 74 | + * @return FilesystemIterator |
|
| 75 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 76 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 77 | + */ |
|
| 78 | + public function locate($namespaces) |
|
| 79 | + { |
|
| 80 | + if (! (is_string($namespaces) || is_array($namespaces))) { |
|
| 81 | + throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
|
| 82 | + } |
|
| 83 | + foreach ((array) $namespaces as $namespace) { |
|
| 84 | + foreach ($this->FindFQCNsByNamespace($namespace) as $key => $file) { |
|
| 85 | + $this->FQCNs[ $key ] = $file; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + return $this->FQCNs; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * given a partial namespace, will find all files in that folder |
|
| 96 | + * ** PLZ NOTE ** |
|
| 97 | + * This assumes that all files within the specified folder should be loaded |
|
| 98 | + * |
|
| 99 | + * @access protected |
|
| 100 | + * @param array $partial_namespace |
|
| 101 | + * @return FilesystemIterator |
|
| 102 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 103 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 104 | + */ |
|
| 105 | + protected function FindFQCNsByNamespace($partial_namespace) |
|
| 106 | + { |
|
| 107 | + $iterator = new FilesystemIterator( |
|
| 108 | + $this->getDirectoryFromPartialNamespace($partial_namespace) |
|
| 109 | + ); |
|
| 110 | + foreach ($this->flags as $flag) { |
|
| 111 | + $iterator->setFlags($flag); |
|
| 112 | + } |
|
| 113 | + if (iterator_count($iterator) === 0) { |
|
| 114 | + return array(); |
|
| 115 | + } |
|
| 116 | + foreach ($iterator as $file) { |
|
| 117 | + $file = \EEH_File::standardise_directory_separators($file); |
|
| 118 | + foreach ($this->namespaces as $namespace => $base_dir) { |
|
| 119 | + $namespace .= Psr4Autoloader::NS; |
|
| 120 | + if (strpos($file, $base_dir) === 0) { |
|
| 121 | + $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
| 122 | + array($base_dir, DS, '.php'), |
|
| 123 | + array($namespace, Psr4Autoloader::NS, ''), |
|
| 124 | + $file |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + return $this->FQCNs; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * getDirectoryFromPartialNamespace |
|
| 135 | + * |
|
| 136 | + * @access protected |
|
| 137 | + * @param string $partial_namespace almost fully qualified class name ? |
|
| 138 | + * @return string |
|
| 139 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 140 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 141 | + */ |
|
| 142 | + protected function getDirectoryFromPartialNamespace($partial_namespace) |
|
| 143 | + { |
|
| 144 | + if (empty($partial_namespace)) { |
|
| 145 | + throw new InvalidClassException($partial_namespace); |
|
| 146 | + } |
|
| 147 | + // load our PSR-4 Autoloader so we can get the list of registered namespaces from it |
|
| 148 | + $psr4_loader = \EE_Psr4AutoloaderInit::psr4_loader(); |
|
| 149 | + // breakup the incoming namespace into segments then loop thru them |
|
| 150 | + $namespace_segments = explode(Psr4Autoloader::NS, trim($partial_namespace, Psr4Autoloader::NS)); |
|
| 151 | + $prefix = null; |
|
| 152 | + $namespace_segments_to_try = $namespace_segments; |
|
| 153 | + $removed_namespace_segments = []; |
|
| 154 | + while( ! empty($namespace_segments_to_try)) { |
|
| 155 | + $namespace_to_try = implode( Psr4Autoloader::NS, $namespace_segments_to_try); |
|
| 156 | + // check if there's a base directory registered for that namespace |
|
| 157 | + $prefix = $psr4_loader->prefixes($namespace_to_try . Psr4Autoloader::NS); |
|
| 158 | + // nope? then the incoming namespace is invalid |
|
| 159 | + if (! empty($prefix) && ! empty($prefix[0])) { |
|
| 160 | + break; |
|
| 161 | + } |
|
| 162 | + array_unshift( |
|
| 163 | + $removed_namespace_segments, |
|
| 164 | + array_pop($namespace_segments_to_try) |
|
| 165 | + ); |
|
| 166 | + }// nope? then the incoming namespace is invalid |
|
| 167 | + if (empty($prefix) || empty($prefix[0])) { |
|
| 168 | + throw new InvalidClassException($partial_namespace); |
|
| 169 | + } |
|
| 170 | + $this->setNamespace($namespace_to_try, $prefix[0]); |
|
| 171 | + // but if it's good, add that base directory to the rest of the path, and return it |
|
| 172 | + return $prefix[0] . implode(DS, $removed_namespace_segments) . DS; |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -36,13 +36,13 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | protected function setNamespace($namespace, $namespace_base_dir) |
| 38 | 38 | { |
| 39 | - if (! is_string($namespace)) { |
|
| 39 | + if ( ! is_string($namespace)) { |
|
| 40 | 40 | throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
| 41 | 41 | } |
| 42 | - if (! is_string($namespace_base_dir)) { |
|
| 42 | + if ( ! is_string($namespace_base_dir)) { |
|
| 43 | 43 | throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
| 44 | 44 | } |
| 45 | - $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
| 45 | + $this->namespaces[$namespace] = $namespace_base_dir; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function locate($namespaces) |
| 79 | 79 | { |
| 80 | - if (! (is_string($namespaces) || is_array($namespaces))) { |
|
| 80 | + if ( ! (is_string($namespaces) || is_array($namespaces))) { |
|
| 81 | 81 | throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
| 82 | 82 | } |
| 83 | 83 | foreach ((array) $namespaces as $namespace) { |
| 84 | 84 | foreach ($this->FindFQCNsByNamespace($namespace) as $key => $file) { |
| 85 | - $this->FQCNs[ $key ] = $file; |
|
| 85 | + $this->FQCNs[$key] = $file; |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | return $this->FQCNs; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | foreach ($this->namespaces as $namespace => $base_dir) { |
| 119 | 119 | $namespace .= Psr4Autoloader::NS; |
| 120 | 120 | if (strpos($file, $base_dir) === 0) { |
| 121 | - $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
| 121 | + $this->FQCNs[] = Psr4Autoloader::NS.str_replace( |
|
| 122 | 122 | array($base_dir, DS, '.php'), |
| 123 | 123 | array($namespace, Psr4Autoloader::NS, ''), |
| 124 | 124 | $file |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | $prefix = null; |
| 152 | 152 | $namespace_segments_to_try = $namespace_segments; |
| 153 | 153 | $removed_namespace_segments = []; |
| 154 | - while( ! empty($namespace_segments_to_try)) { |
|
| 155 | - $namespace_to_try = implode( Psr4Autoloader::NS, $namespace_segments_to_try); |
|
| 154 | + while ( ! empty($namespace_segments_to_try)) { |
|
| 155 | + $namespace_to_try = implode(Psr4Autoloader::NS, $namespace_segments_to_try); |
|
| 156 | 156 | // check if there's a base directory registered for that namespace |
| 157 | - $prefix = $psr4_loader->prefixes($namespace_to_try . Psr4Autoloader::NS); |
|
| 157 | + $prefix = $psr4_loader->prefixes($namespace_to_try.Psr4Autoloader::NS); |
|
| 158 | 158 | // nope? then the incoming namespace is invalid |
| 159 | - if (! empty($prefix) && ! empty($prefix[0])) { |
|
| 159 | + if ( ! empty($prefix) && ! empty($prefix[0])) { |
|
| 160 | 160 | break; |
| 161 | 161 | } |
| 162 | 162 | array_unshift( |
@@ -169,6 +169,6 @@ discard block |
||
| 169 | 169 | } |
| 170 | 170 | $this->setNamespace($namespace_to_try, $prefix[0]); |
| 171 | 171 | // but if it's good, add that base directory to the rest of the path, and return it |
| 172 | - return $prefix[0] . implode(DS, $removed_namespace_segments) . DS; |
|
| 172 | + return $prefix[0].implode(DS, $removed_namespace_segments).DS; |
|
| 173 | 173 | } |
| 174 | 174 | } |