aboutsummaryrefslogtreecommitdiffstats
path: root/lib/autoloader.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-05-07 22:39:35 +0200
committerRobin Appelman <icewind@owncloud.com>2013-05-07 22:39:35 +0200
commit6d903cf7ae30ef3b9fb9faa34ee8b8347ac47e93 (patch)
tree9f8ea4b0ff73fe742e10de7595e77f462e21727b /lib/autoloader.php
parent72ed74f28acc9f7897e1591e1d7f6e4e28e8b107 (diff)
downloadnextcloud-server-6d903cf7ae30ef3b9fb9faa34ee8b8347ac47e93.tar.gz
nextcloud-server-6d903cf7ae30ef3b9fb9faa34ee8b8347ac47e93.zip
Autoloader: add support for custom namespace paths
Diffstat (limited to 'lib/autoloader.php')
-rw-r--r--lib/autoloader.php20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/autoloader.php b/lib/autoloader.php
index 95b73fe8903..976ec6b1a87 100644
--- a/lib/autoloader.php
+++ b/lib/autoloader.php
@@ -11,9 +11,21 @@ namespace OC;
class Autoloader {
private $useGlobalClassPath = true;
+ private $namespacePaths = array();
+
private $classPaths = array();
/**
+ * Add a custom namespace to the autoloader
+ *
+ * @param string $namespace
+ * @param string $path
+ */
+ public function registerNamespace($namespace, $path) {
+ $this->namespacePaths[$namespace] = $path;
+ }
+
+ /**
* Add a custom classpath to the autoloader
*
* @param string $class
@@ -60,6 +72,8 @@ class Autoloader {
$paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]);
}
} elseif (strpos($class, 'OC_') === 0) {
+ // first check for legacy classes if underscores are used
+ $paths[] = 'legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php');
$paths[] = strtolower(str_replace('_', '/', substr($class, 3)) . '.php');
} elseif (strpos($class, 'OC\\') === 0) {
$paths[] = strtolower(str_replace('\\', '/', substr($class, 3)) . '.php');
@@ -82,7 +96,11 @@ class Autoloader {
} elseif (strpos($class, 'Test\\') === 0) {
$paths[] = 'tests/lib/' . strtolower(str_replace('\\', '/', substr($class, 5)) . '.php');
} else {
- return false;
+ foreach ($this->namespacePaths as $namespace => $dir) {
+ if (0 === strpos($class, $namespace)) {
+ $paths[] = $dir . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
+ }
+ }
}
return $paths;
}