diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-05-07 22:26:55 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-05-07 22:26:55 +0200 |
commit | 72ed74f28acc9f7897e1591e1d7f6e4e28e8b107 (patch) | |
tree | 309aab48943df1edd641a73a0999ece5879616d6 /lib/autoloader.php | |
parent | cac86bb4db670e868ae61aef176d229c814452c0 (diff) | |
download | nextcloud-server-72ed74f28acc9f7897e1591e1d7f6e4e28e8b107.tar.gz nextcloud-server-72ed74f28acc9f7897e1591e1d7f6e4e28e8b107.zip |
Autoloader: split getting the class paths and loading the class
Diffstat (limited to 'lib/autoloader.php')
-rw-r--r-- | lib/autoloader.php | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/autoloader.php b/lib/autoloader.php index 94c0ac7cb5d..95b73fe8903 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -38,12 +38,12 @@ class Autoloader { } /** - * Load the specified class + * get the possible paths for a class * * @param string $class - * @return bool + * @return array|bool an array of possible paths or false if the class is not part of ownCloud */ - public function load($class) { + public function findClass($class) { $class = trim($class, '\\'); $paths = array(); @@ -57,7 +57,7 @@ class Autoloader { */ if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { \OC_Log::write('core', 'include path for class "' . $class . '" starts with "apps/"', \OC_Log::DEBUG); - $path = str_replace('apps/', '', \OC::$CLASSPATH[$class]); + $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); } } elseif (strpos($class, 'OC_') === 0) { $paths[] = strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); @@ -84,10 +84,23 @@ class Autoloader { } else { return false; } + return $paths; + } + + /** + * Load the specified class + * + * @param string $class + * @return bool + */ + public function load($class) { + $paths = $this->findClass($class); - foreach ($paths as $path) { - if ($fullPath = stream_resolve_include_path($path)) { - require_once $fullPath; + if (is_array($paths)) { + foreach ($paths as $path) { + if ($fullPath = stream_resolve_include_path($path)) { + require_once $fullPath; + } } } return false; |