diff options
author | Florian Pritz <bluewind@xinu.at> | 2016-06-09 18:05:02 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2016-06-09 22:07:40 +0200 |
commit | 8c572f55b17b86cbfa56f18f0491e05092f755b1 (patch) | |
tree | 1a519e4148e8234dbfbf5affda7866e46ce113e8 /application | |
parent | fc83ca2a898b5ab29fedad2dfb380e28f261e92c (diff) |
Autoloader: Support PSR-4 style namespace/directory mapping
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r-- | application/libraries/Customautoloader.php | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/application/libraries/Customautoloader.php b/application/libraries/Customautoloader.php index c59847eb3..6a616ba7f 100644 --- a/application/libraries/Customautoloader.php +++ b/application/libraries/Customautoloader.php @@ -16,16 +16,23 @@ class CustomAutoloader{ public function loader($className) { - $base_paths = array( - APPPATH, - APPPATH."/third_party/mockery/library/", + $namespaces = array( + '' => [ + ["path" => APPPATH], + ["path" => APPPATH."/third_party/mockery/library/"] + ], ); - foreach ($base_paths as $base_path) { - $path = $base_path.str_replace('\\', DIRECTORY_SEPARATOR, $className).'.php'; - if (file_exists($path)) { - require $path; - return; + foreach ($namespaces as $namespace => $search_items) { + if ($namespace === '' || strpos($className, $namespace) === 0) { + foreach ($search_items as $search_item) { + $nameToLoad = str_replace($namespace, '', $className); + $path = $search_item['path'].str_replace('\\', DIRECTORY_SEPARATOR, $nameToLoad).'.php'; + if (file_exists($path)) { + require $path; + return; + } + } } } } |