bug #11232 [Routing] Fixes fatal errors with object resources in AnnotationDirectoryLoader::supports (Tischoi)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11232).

Discussion
----------

[Routing] Fixes fatal errors with object resources in AnnotationDirectoryLoader::supports

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Fixes fatal errors that occur in the supports method with objects that aren't string convertible / don't implement ArrayAccess. This is mostly a problem because some locators try to access a specific character in the resource name.
Since the resource is checked if it's a string either way, it's the most simple solution to just move that check a bit ahead.

Commits
-------

5e80585 Update AnnotationDirectoryLoader.php
This commit is contained in:
Fabien Potencier 2016-01-25 17:58:14 +01:00
commit a0a97d7521

View File

@ -66,12 +66,16 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader
*/
public function supports($resource, $type = null)
{
if (!is_string($resource)) {
return false;
}
try {
$path = $this->locator->locate($resource);
} catch (\Exception $e) {
return false;
}
return is_string($resource) && is_dir($path) && (!$type || 'annotation' === $type);
return is_dir($path) && (!$type || 'annotation' === $type);
}
}