minor #17401 [2.7] Use is_subclass_of instead of reflection (Ener-Getick)

This PR was merged into the 2.7 branch.

Discussion
----------

[2.7] Use is_subclass_of instead of reflection

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

Follows https://github.com/symfony/symfony/pull/17400

>
For performance reason, I replaced a reflection instantiation by ``is_subclass_of``.

Commits
-------

5af5d06 Use is_subclass_of instead of reflection
This commit is contained in:
Fabien Potencier 2016-01-16 19:10:37 +01:00
commit ab43f389e2
1 changed files with 1 additions and 2 deletions

View File

@ -37,8 +37,7 @@ class AddConsoleCommandPass implements CompilerPassInterface
}
$class = $container->getParameterBag()->resolveValue($definition->getClass());
$r = new \ReflectionClass($class);
if (!$r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command')) {
if (!is_subclass_of($class, 'Symfony\\Component\\Console\\Command\\Command')) {
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "Symfony\\Component\\Console\\Command\\Command".', $id));
}
$container->setAlias('console.command.'.strtolower(str_replace('\\', '_', $class)), $id);