Skip to content

Commit

Permalink
[DI][Config] Add & use ReflectionClassResource
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Feb 2, 2017
1 parent 1525be8 commit 928e358
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions DependencyInjection/AddConsoleCommandPass.php
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Component\Console\DependencyInjection;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

/**
* Registers console commands.
Expand All @@ -34,9 +36,14 @@ public function process(ContainerBuilder $container)
}

$class = $container->getParameterBag()->resolveValue($definition->getClass());
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));

if (!$r = $container->getReflectionClass($class)) {
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
}
if (!$r->isSubclassOf(Command::class)) {
throw new InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "%s".', $id, Command::class));
}

$container->setAlias($serviceId = 'console.command.'.strtolower(str_replace('\\', '_', $class)), $id);
$serviceIds[] = $definition->isPublic() ? $id : $serviceId;
}
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Expand Up @@ -23,7 +23,7 @@
"require-dev": {
"symfony/http-kernel": "~2.8|~3.0",
"symfony/event-dispatcher": "~2.8|~3.0",
"symfony/dependency-injection": "~2.8|~3.0",
"symfony/dependency-injection": "~3.3",
"symfony/filesystem": "~2.8|~3.0",
"symfony/process": "~2.8|~3.0",
"psr/log": "~1.0"
Expand All @@ -34,6 +34,9 @@
"symfony/process": "",
"psr/log": "For using the console logger"
},
"conflict": {
"symfony/dependency-injection": "<3.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Console\\": "" },
"exclude-from-classmap": [
Expand Down

0 comments on commit 928e358

Please sign in to comment.