Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Silent autoloaders support #216

Merged
merged 2 commits into from

4 participants

Marco Pivetta doctrinebot Christophe Coevoet Benjamin Eberlei
Marco Pivetta
Owner

Fixing support for silent autoloaders

doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DCOM-136

Christophe Coevoet
Collaborator

btw, this code does not seem to support traits

Marco Pivetta
Owner

@stof can you elaborate a bit? You mean the class_exists(...) || interface_exists(...) part?

Christophe Coevoet
Collaborator
Marco Pivetta
Owner

Opened #217 for that one

Marco Pivetta
Owner

Mergeable?

Benjamin Eberlei beberlei merged commit edeaab2 into from
Marco Pivetta Ocramius deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
6 lib/Doctrine/Common/ClassLoader.php
View
@@ -234,9 +234,13 @@ public static function classExists($className)
} else if (is_string($loader) && $loader($className)) { // "MyClass::loadClass"
return true;
}
+
+ if (class_exists($className, false) || interface_exists($className, false)) {
+ return true;
+ }
}
- return class_exists($className, false) || interface_exists($className, false);
+ return false;
}
/**
19 tests/Doctrine/Tests/Common/ClassLoaderTest.php
View
@@ -42,4 +42,23 @@ public function testGetClassLoader()
$this->assertNull(ClassLoader::getClassLoader('This\Class\Does\Not\Exist'));
$cl->unregister();
}
+
+ public function testClassExistsWithSilentAutoloader()
+ {
+ $test = $this;
+ $silentLoader = function ($className) use ($test) {
+ $test->assertSame('ClassLoaderTest\ClassE', $className);
+ require __DIR__ . '/ClassLoaderTest/ClassE.php';
+ };
+ $additionalLoader = function () use ($test) {
+ $test->fail('Should not call this loader, class was already loaded');
+ };
+
+ $this->assertFalse(ClassLoader::classExists('ClassLoaderTest\ClassE'));
+ spl_autoload_register($silentLoader);
+ spl_autoload_register($additionalLoader);
+ $this->assertTrue(ClassLoader::classExists('ClassLoaderTest\ClassE'));
+ spl_autoload_unregister($additionalLoader);
+ spl_autoload_unregister($silentLoader);
+ }
}
5 tests/Doctrine/Tests/Common/ClassLoaderTest/ClassE.php
View
@@ -0,0 +1,5 @@
+<?php
+
+namespace ClassLoaderTest;
+
+class ClassE {}
Something went wrong with that request. Please try again.