Skip to content

Commit d768aa5

Browse files
Merge branch '3.3' into 3.4
* 3.3: [DI] Dont resolve envs in service ids Add tests proving it can load annotated files [WebProfilerBundle] Reset letter-spacing in toolbar Prefer overflow-wrap to word-break [Routing] Fix "config-file-relative" annotation loader resources Make search in debug:container command case-insensitive `resolveEnvPlaceholders` will return a mixed value
2 parents fb3865c + 4788b7e commit d768aa5

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

Loader/AnnotationDirectoryLoader.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader
3434
*/
3535
public function load($path, $type = null)
3636
{
37-
$dir = $this->locator->locate($path);
37+
if (!is_dir($dir = $this->locator->locate($path))) {
38+
return parent::supports($path, $type) ? parent::load($path, $type) : new RouteCollection();
39+
}
3840

3941
$collection = new RouteCollection();
4042
$collection->addResource(new DirectoryResource($dir, '/\.php$/'));
@@ -74,16 +76,18 @@ function (\SplFileInfo $current) {
7476
*/
7577
public function supports($resource, $type = null)
7678
{
77-
if (!is_string($resource)) {
79+
if ('annotation' === $type) {
80+
return true;
81+
}
82+
83+
if ($type || !is_string($resource)) {
7884
return false;
7985
}
8086

8187
try {
82-
$path = $this->locator->locate($resource);
88+
return is_dir($this->locator->locate($resource));
8389
} catch (\Exception $e) {
8490
return false;
8591
}
86-
87-
return is_dir($path) && (!$type || 'annotation' === $type);
8892
}
8993
}

Tests/Loader/AnnotationDirectoryLoaderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ public function testSupports()
6969
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
7070
}
7171

72+
public function testItSupportsAnyAnnotation()
73+
{
74+
$this->assertTrue($this->loader->supports(__DIR__.'/../Fixtures/even-with-not-existing-folder', 'annotation'));
75+
}
76+
77+
public function testLoadFileIfLocatedResourceIsFile()
78+
{
79+
$this->reader->expects($this->exactly(1))->method('getClassAnnotation');
80+
81+
$this->reader
82+
->expects($this->any())
83+
->method('getMethodAnnotations')
84+
->will($this->returnValue(array()))
85+
;
86+
87+
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
88+
}
89+
7290
private function expectAnnotationsToBeReadFrom(array $classes)
7391
{
7492
$this->reader->expects($this->exactly(count($classes)))

0 commit comments

Comments
 (0)