diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-05-07 22:21:59 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-05-07 22:21:59 +0200 |
commit | d1fcb7eb5237d597a878e5f7b61693e7dee29ca8 (patch) | |
tree | a61f2af5bfd22b0cd8413748812a48d760a4d412 /lib/autoloader.php | |
parent | 19cfe74bf5d74c6f761513baf60da9ef7945f30e (diff) | |
download | nextcloud-server-d1fcb7eb5237d597a878e5f7b61693e7dee29ca8.tar.gz nextcloud-server-d1fcb7eb5237d597a878e5f7b61693e7dee29ca8.zip |
Allow the autoloader to try mutliple possible paths for each path
Diffstat (limited to 'lib/autoloader.php')
-rw-r--r-- | lib/autoloader.php | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/lib/autoloader.php b/lib/autoloader.php index 091c4de9674..9547ddc7d91 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -30,10 +30,11 @@ class Autoloader { public function load($class) { $class = trim($class, '\\'); + $paths = array(); if (array_key_exists($class, $this->classPaths)) { - $path = $this->classPaths[$class]; + $paths[] = $this->classPaths[$class]; } else if (array_key_exists($class, \OC::$CLASSPATH)) { - $path = \OC::$CLASSPATH[$class]; + $paths[] = \OC::$CLASSPATH[$class]; /** * @TODO: Remove this when necessary * Remove "apps/" from inclusion path for smooth migration to mutli app dir @@ -43,43 +44,35 @@ class Autoloader { $path = str_replace('apps/', '', $path); } } elseif (strpos($class, 'OC_') === 0) { - $path = strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); + $paths[] = strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); } elseif (strpos($class, 'OC\\') === 0) { - $path = strtolower(str_replace('\\', '/', substr($class, 3)) . '.php'); + $paths[] = strtolower(str_replace('\\', '/', substr($class, 3)) . '.php'); } elseif (strpos($class, 'OCP\\') === 0) { - $path = 'public/' . strtolower(str_replace('\\', '/', substr($class, 3)) . '.php'); + $paths[] = 'public/' . strtolower(str_replace('\\', '/', substr($class, 3)) . '.php'); } elseif (strpos($class, 'OCA\\') === 0) { foreach (\OC::$APPSROOTS as $appDir) { - $path = strtolower(str_replace('\\', '/', substr($class, 4)) . '.php'); - $fullPath = stream_resolve_include_path($appDir['path'] . '/' . $path); - if (file_exists($fullPath)) { - require_once $fullPath; - return false; - } + $paths[] = $appDir['path'] . '/' . strtolower(str_replace('\\', '/', substr($class, 4)) . '.php'); // If not found in the root of the app directory, insert '/lib' after app id and try again. - $libpath = substr($path, 0, strpos($path, '/')) . '/lib' . substr($path, strpos($path, '/')); - $fullPath = stream_resolve_include_path($appDir['path'] . '/' . $libpath); - if (file_exists($fullPath)) { - require_once $fullPath; - return false; - } + $paths[] = $appDir['path'] . '/lib/' . strtolower(str_replace('\\', '/', substr($class, 4)) . '.php'); } } elseif (strpos($class, 'Sabre_') === 0) { - $path = str_replace('_', '/', $class) . '.php'; + $paths[] = str_replace('_', '/', $class) . '.php'; } elseif (strpos($class, 'Symfony\\Component\\Routing\\') === 0) { - $path = 'symfony/routing/' . str_replace('\\', '/', $class) . '.php'; + $paths[] = 'symfony/routing/' . str_replace('\\', '/', $class) . '.php'; } elseif (strpos($class, 'Sabre\\VObject') === 0) { - $path = str_replace('\\', '/', $class) . '.php'; + $paths[] = str_replace('\\', '/', $class) . '.php'; } elseif (strpos($class, 'Test_') === 0) { - $path = 'tests/lib/' . strtolower(str_replace('_', '/', substr($class, 5)) . '.php'); + $paths[] = 'tests/lib/' . strtolower(str_replace('_', '/', substr($class, 5)) . '.php'); } elseif (strpos($class, 'Test\\') === 0) { - $path = 'tests/lib/' . strtolower(str_replace('\\', '/', substr($class, 5)) . '.php'); + $paths[] = 'tests/lib/' . strtolower(str_replace('\\', '/', substr($class, 5)) . '.php'); } else { return false; } - if ($fullPath = stream_resolve_include_path($path)) { - require_once $fullPath; + foreach ($paths as $path) { + if ($fullPath = stream_resolve_include_path($path)) { + require_once $fullPath; + } } return false; } |