Merge pull request #24617 from owncloud/autoloader_no_private

our autoloader should not load classes in \OC
This commit is contained in:
Vincent Petry 2016-05-13 17:30:10 +02:00
commit e383a9506d
2 changed files with 4 additions and 36 deletions

View File

@ -102,24 +102,6 @@ class Autoloader {
}
} elseif (strpos($class, 'OC_') === 0) {
$paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php');
$paths[] = \OC::$SERVERROOT . '/lib/private/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php');
} elseif (strpos($class, 'OC\\') === 0) {
$split = explode('\\', $class, 3);
if (count($split) === 3) {
$split[1] = strtolower($split[1]);
if ($split[1] === 'core') {
// Covered by PSR-4 autoloader
} else if ($split[1] === 'settings') {
// Covered by PSR-4 autoloader
} else {
$paths[] = \OC::$SERVERROOT . '/lib/private/' . $split[1] . '/' . strtolower(str_replace('\\', '/', $split[2])) . '.php';
}
} else {
$paths[] = \OC::$SERVERROOT . '/lib/private/' . strtolower(str_replace('\\', '/', $split[1])) . '.php';
}
} elseif (strpos($class, 'OCP\\') === 0) {
$paths[] = \OC::$SERVERROOT . '/lib/public/' . strtolower(str_replace('\\', '/', substr($class, 4)) . '.php');
} elseif (strpos($class, 'OCA\\') === 0) {

View File

@ -21,20 +21,19 @@ class AutoLoader extends TestCase {
public function testLeadingSlashOnClassName() {
$this->assertEquals([
\OC::$SERVERROOT . '/lib/private/files/storage/local.php',
], $this->loader->findClass('\OC\Files\Storage\Local'));
\OC::$SERVERROOT . '/lib/public/files/storage/local.php',
], $this->loader->findClass('\OCP\Files\Storage\Local'));
}
public function testNoLeadingSlashOnClassName() {
$this->assertEquals([
\OC::$SERVERROOT . '/lib/private/files/storage/local.php',
], $this->loader->findClass('OC\Files\Storage\Local'));
\OC::$SERVERROOT . '/lib/public/files/storage/local.php',
], $this->loader->findClass('OCP\Files\Storage\Local'));
}
public function testLegacyPath() {
$this->assertEquals([
\OC::$SERVERROOT . '/lib/private/legacy/files.php',
\OC::$SERVERROOT . '/lib/private/files.php',
], $this->loader->findClass('OC_Files'));
}
@ -50,16 +49,9 @@ class AutoLoader extends TestCase {
], $this->loader->findClass('Test_Foo_Bar'));
}
public function testLoadCoreNamespace() {
$this->assertEquals([
\OC::$SERVERROOT . '/lib/private/foo/bar.php',
], $this->loader->findClass('OC\Foo\Bar'));
}
public function testLoadCore() {
$this->assertEquals([
\OC::$SERVERROOT . '/lib/private/legacy/foo/bar.php',
\OC::$SERVERROOT . '/lib/private/foo/bar.php',
], $this->loader->findClass('OC_Foo_Bar'));
}
@ -83,10 +75,4 @@ class AutoLoader extends TestCase {
public function testLoadCoreNamespaceSettings() {
$this->assertEquals([], $this->loader->findClass('OC\Settings\Foo\Bar'));
}
public function testLoadCoreNamespaceRepair() {
$this->assertEquals([
\OC::$SERVERROOT . '/lib/private/repair/foo/bar.php',
], $this->loader->findClass('OC\Repair\Foo\Bar'));
}
}