[DI] Make tagged abstract services throw earlier
This commit is contained in:
parent
cd06c1297b
commit
388e4b3389
@ -55,8 +55,8 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$taggedSubscribers = $container->findTaggedServiceIds($this->tagPrefix.'.event_subscriber');
|
$taggedSubscribers = $container->findTaggedServiceIds($this->tagPrefix.'.event_subscriber', true);
|
||||||
$taggedListeners = $container->findTaggedServiceIds($this->tagPrefix.'.event_listener');
|
$taggedListeners = $container->findTaggedServiceIds($this->tagPrefix.'.event_listener', true);
|
||||||
|
|
||||||
if (empty($taggedSubscribers) && empty($taggedListeners)) {
|
if (empty($taggedSubscribers) && empty($taggedListeners)) {
|
||||||
return;
|
return;
|
||||||
@ -78,10 +78,6 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
|
|||||||
|
|
||||||
uasort($subscribers, $sortFunc);
|
uasort($subscribers, $sortFunc);
|
||||||
foreach ($subscribers as $id => $instance) {
|
foreach ($subscribers as $id => $instance) {
|
||||||
if ($container->getDefinition($id)->isAbstract()) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event subscriber.', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
$em->addMethodCall('addEventSubscriber', array(new Reference($id)));
|
$em->addMethodCall('addEventSubscriber', array(new Reference($id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,10 +90,6 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
|
|||||||
|
|
||||||
uasort($listeners, $sortFunc);
|
uasort($listeners, $sortFunc);
|
||||||
foreach ($listeners as $id => $instance) {
|
foreach ($listeners as $id => $instance) {
|
||||||
if ($container->getDefinition($id)->isAbstract()) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event listener.', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
$em->addMethodCall('addEventListener', array(
|
$em->addMethodCall('addEventListener', array(
|
||||||
array_unique($instance['event']),
|
array_unique($instance['event']),
|
||||||
isset($instance['lazy']) && $instance['lazy'] ? $id : new Reference($id),
|
isset($instance['lazy']) && $instance['lazy'] ? $id : new Reference($id),
|
||||||
|
@ -32,7 +32,7 @@ class AddCacheClearerPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$clearers = array();
|
$clearers = array();
|
||||||
foreach ($container->findTaggedServiceIds('kernel.cache_clearer') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('kernel.cache_clearer', true) as $id => $attributes) {
|
||||||
$clearers[] = new Reference($id);
|
$clearers[] = new Reference($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class AddExpressionLanguageProvidersPass implements CompilerPassInterface
|
|||||||
// routing
|
// routing
|
||||||
if ($container->has('router')) {
|
if ($container->has('router')) {
|
||||||
$definition = $container->findDefinition('router');
|
$definition = $container->findDefinition('router');
|
||||||
foreach ($container->findTaggedServiceIds('routing.expression_language_provider') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('routing.expression_language_provider', true) as $id => $attributes) {
|
||||||
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));
|
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ class AddExpressionLanguageProvidersPass implements CompilerPassInterface
|
|||||||
// security
|
// security
|
||||||
if ($container->has('security.access.expression_voter')) {
|
if ($container->has('security.access.expression_voter')) {
|
||||||
$definition = $container->findDefinition('security.access.expression_voter');
|
$definition = $container->findDefinition('security.access.expression_voter');
|
||||||
foreach ($container->findTaggedServiceIds('security.expression_language_provider') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('security.expression_language_provider', true) as $id => $attributes) {
|
||||||
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));
|
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class ProfilerPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$collectors = new \SplPriorityQueue();
|
$collectors = new \SplPriorityQueue();
|
||||||
$order = PHP_INT_MAX;
|
$order = PHP_INT_MAX;
|
||||||
foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('data_collector', true) as $id => $attributes) {
|
||||||
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
|
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
|
||||||
$template = null;
|
$template = null;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class TemplatingPass implements CompilerPassInterface
|
|||||||
|
|
||||||
if ($container->hasDefinition('templating.engine.php')) {
|
if ($container->hasDefinition('templating.engine.php')) {
|
||||||
$helpers = array();
|
$helpers = array();
|
||||||
foreach ($container->findTaggedServiceIds('templating.helper') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('templating.helper', true) as $id => $attributes) {
|
||||||
if (isset($attributes[0]['alias'])) {
|
if (isset($attributes[0]['alias'])) {
|
||||||
$helpers[$attributes[0]['alias']] = $id;
|
$helpers[$attributes[0]['alias']] = $id;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class TranslationDumperPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$definition = $container->getDefinition('translation.writer');
|
$definition = $container->getDefinition('translation.writer');
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds('translation.dumper') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('translation.dumper', true) as $id => $attributes) {
|
||||||
$definition->addMethodCall('addDumper', array($attributes[0]['alias'], new Reference($id)));
|
$definition->addMethodCall('addDumper', array($attributes[0]['alias'], new Reference($id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class TranslationExtractorPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$definition = $container->getDefinition('translation.extractor');
|
$definition = $container->getDefinition('translation.extractor');
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds('translation.extractor') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('translation.extractor', true) as $id => $attributes) {
|
||||||
if (!isset($attributes[0]['alias'])) {
|
if (!isset($attributes[0]['alias'])) {
|
||||||
throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
|
throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ class TranslatorPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$loaders = array();
|
$loaders = array();
|
||||||
$loaderRefs = array();
|
$loaderRefs = array();
|
||||||
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('translation.loader', true) as $id => $attributes) {
|
||||||
$loaderRefs[$id] = new Reference($id);
|
$loaderRefs[$id] = new Reference($id);
|
||||||
$loaders[$id][] = $attributes[0]['alias'];
|
$loaders[$id][] = $attributes[0]['alias'];
|
||||||
if (isset($attributes[0]['legacy-alias'])) {
|
if (isset($attributes[0]['legacy-alias'])) {
|
||||||
|
@ -25,7 +25,7 @@ class ValidateWorkflowsPass implements CompilerPassInterface
|
|||||||
{
|
{
|
||||||
public function process(ContainerBuilder $container)
|
public function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$taggedServices = $container->findTaggedServiceIds('workflow.definition');
|
$taggedServices = $container->findTaggedServiceIds('workflow.definition', true);
|
||||||
foreach ($taggedServices as $id => $tags) {
|
foreach ($taggedServices as $id => $tags) {
|
||||||
$definition = $container->get($id);
|
$definition = $container->get($id);
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
|
@ -34,9 +34,6 @@ class AddConstraintValidatorsPassTest extends TestCase
|
|||||||
->addTag('validator.constraint_validator', array('alias' => 'my_constraint_validator_alias1'));
|
->addTag('validator.constraint_validator', array('alias' => 'my_constraint_validator_alias1'));
|
||||||
$container->register('my_constraint_validator_service2', Validator2::class)
|
$container->register('my_constraint_validator_service2', Validator2::class)
|
||||||
->addTag('validator.constraint_validator');
|
->addTag('validator.constraint_validator');
|
||||||
$container->register('my_abstract_constraint_validator')
|
|
||||||
->setAbstract(true)
|
|
||||||
->addTag('validator.constraint_validator');
|
|
||||||
|
|
||||||
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||||
$addConstraintValidatorsPass->process($container);
|
$addConstraintValidatorsPass->process($container);
|
||||||
@ -49,6 +46,24 @@ class AddConstraintValidatorsPassTest extends TestCase
|
|||||||
$this->assertEquals($expected, $container->getDefinition((string) $validatorFactory->getArgument(0)));
|
$this->assertEquals($expected, $container->getDefinition((string) $validatorFactory->getArgument(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage The service "my_abstract_constraint_validator" tagged "validator.constraint_validator" must not be abstract.
|
||||||
|
*/
|
||||||
|
public function testAbstractConstraintValidator()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$validatorFactory = $container->register('validator.validator_factory')
|
||||||
|
->addArgument(array());
|
||||||
|
|
||||||
|
$container->register('my_abstract_constraint_validator')
|
||||||
|
->setAbstract(true)
|
||||||
|
->addTag('validator.constraint_validator');
|
||||||
|
|
||||||
|
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||||
|
$addConstraintValidatorsPass->process($container);
|
||||||
|
}
|
||||||
|
|
||||||
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
|
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
|
||||||
{
|
{
|
||||||
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
|
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
|
||||||
|
@ -29,13 +29,8 @@ class RuntimeLoaderPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$definition = $container->getDefinition('twig.runtime_loader');
|
$definition = $container->getDefinition('twig.runtime_loader');
|
||||||
$mapping = array();
|
$mapping = array();
|
||||||
foreach ($container->findTaggedServiceIds('twig.runtime') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('twig.runtime', true) as $id => $attributes) {
|
||||||
$def = $container->getDefinition($id);
|
$def = $container->getDefinition($id);
|
||||||
|
|
||||||
if ($def->isAbstract()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mapping[$def->getClass()] = new Reference($id);
|
$mapping[$def->getClass()] = new Reference($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class TwigEnvironmentPass implements CompilerPassInterface
|
|||||||
// be registered.
|
// be registered.
|
||||||
$calls = $definition->getMethodCalls();
|
$calls = $definition->getMethodCalls();
|
||||||
$definition->setMethodCalls(array());
|
$definition->setMethodCalls(array());
|
||||||
foreach ($container->findTaggedServiceIds('twig.extension') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('twig.extension', true) as $id => $attributes) {
|
||||||
$definition->addMethodCall('addExtension', array(new Reference($id)));
|
$definition->addMethodCall('addExtension', array(new Reference($id)));
|
||||||
}
|
}
|
||||||
$definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
|
$definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
|
||||||
|
@ -32,7 +32,7 @@ class TwigLoaderPass implements CompilerPassInterface
|
|||||||
$prioritizedLoaders = array();
|
$prioritizedLoaders = array();
|
||||||
$found = 0;
|
$found = 0;
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds('twig.loader') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('twig.loader', true) as $id => $attributes) {
|
||||||
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
|
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
|
||||||
$prioritizedLoaders[$priority][] = $id;
|
$prioritizedLoaders[$priority][] = $id;
|
||||||
++$found;
|
++$found;
|
||||||
|
@ -25,16 +25,11 @@ class AddConsoleCommandPass implements CompilerPassInterface
|
|||||||
{
|
{
|
||||||
public function process(ContainerBuilder $container)
|
public function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$commandServices = $container->findTaggedServiceIds('console.command');
|
$commandServices = $container->findTaggedServiceIds('console.command', true);
|
||||||
$serviceIds = array();
|
$serviceIds = array();
|
||||||
|
|
||||||
foreach ($commandServices as $id => $tags) {
|
foreach ($commandServices as $id => $tags) {
|
||||||
$definition = $container->getDefinition($id);
|
$definition = $container->getDefinition($id);
|
||||||
|
|
||||||
if ($definition->isAbstract()) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must not be abstract.', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
$class = $container->getParameterBag()->resolveValue($definition->getClass());
|
$class = $container->getParameterBag()->resolveValue($definition->getClass());
|
||||||
|
|
||||||
if (!$r = $container->getReflectionClass($class)) {
|
if (!$r = $container->getReflectionClass($class)) {
|
||||||
|
@ -40,7 +40,7 @@ trait PriorityTaggedServiceTrait
|
|||||||
{
|
{
|
||||||
$services = array();
|
$services = array();
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds($tagName) as $serviceId => $attributes) {
|
foreach ($container->findTaggedServiceIds($tagName, true) as $serviceId => $attributes) {
|
||||||
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
|
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
|
||||||
$services[$priority][] = new Reference($serviceId);
|
$services[$priority][] = new Reference($serviceId);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,6 +22,24 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
|||||||
*/
|
*/
|
||||||
class ResolveTagsInheritancePass extends AbstractRecursivePass
|
class ResolveTagsInheritancePass extends AbstractRecursivePass
|
||||||
{
|
{
|
||||||
|
private $abstractInheritedParents = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function process(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
parent::process($container);
|
||||||
|
|
||||||
|
foreach ($this->abstractInheritedParents as $id) {
|
||||||
|
$container->findDefinition($id)->setTags(array());
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
$this->abstractInheritedParents = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -36,6 +55,9 @@ class ResolveTagsInheritancePass extends AbstractRecursivePass
|
|||||||
}
|
}
|
||||||
|
|
||||||
$parentDef = $this->container->findDefinition($parent);
|
$parentDef = $this->container->findDefinition($parent);
|
||||||
|
if ($parentDef->isAbstract()) {
|
||||||
|
$this->abstractInheritedParents[$parent] = $parent;
|
||||||
|
}
|
||||||
|
|
||||||
if ($parentDef instanceof ChildDefinition) {
|
if ($parentDef instanceof ChildDefinition) {
|
||||||
$this->processValue($parentDef);
|
$this->processValue($parentDef);
|
||||||
|
@ -1200,16 +1200,20 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @param string $name The tag name
|
* @param string $name
|
||||||
|
* @param bool $throwOnAbstract
|
||||||
*
|
*
|
||||||
* @return array An array of tags with the tagged service as key, holding a list of attribute arrays
|
* @return array An array of tags with the tagged service as key, holding a list of attribute arrays
|
||||||
*/
|
*/
|
||||||
public function findTaggedServiceIds($name)
|
public function findTaggedServiceIds($name, $throwOnAbstract = false)
|
||||||
{
|
{
|
||||||
$this->usedTags[] = $name;
|
$this->usedTags[] = $name;
|
||||||
$tags = array();
|
$tags = array();
|
||||||
foreach ($this->getDefinitions() as $id => $definition) {
|
foreach ($this->getDefinitions() as $id => $definition) {
|
||||||
if ($definition->hasTag($name)) {
|
if ($definition->hasTag($name)) {
|
||||||
|
if ($throwOnAbstract && $definition->isAbstract()) {
|
||||||
|
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must not be abstract.', $id, $name));
|
||||||
|
}
|
||||||
$tags[$id] = $definition->getTag($name);
|
$tags[$id] = $definition->getTag($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,13 @@ class ResolveTagsInheritancePassTest extends TestCase
|
|||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
$container->register('grandpa', self::class)->addTag('g');
|
$container->register('grandpa', self::class)->addTag('g');
|
||||||
$container->setDefinition('parent', new ChildDefinition('grandpa'))->addTag('p')->setInheritTags(true);
|
$container->setDefinition('parent', new ChildDefinition('grandpa'))->addTag('p')->setInheritTags(true)->setAbstract(true);
|
||||||
$container->setDefinition('child', new ChildDefinition('parent'))->setInheritTags(true);
|
$container->setDefinition('child', new ChildDefinition('parent'))->setInheritTags(true);
|
||||||
|
|
||||||
(new ResolveTagsInheritancePass())->process($container);
|
(new ResolveTagsInheritancePass())->process($container);
|
||||||
|
|
||||||
$expected = array('p' => array(array()), 'g' => array(array()));
|
$expected = array('p' => array(array()), 'g' => array(array()));
|
||||||
$this->assertSame($expected, $container->getDefinition('parent')->getTags());
|
|
||||||
$this->assertSame($expected, $container->getDefinition('child')->getTags());
|
$this->assertSame($expected, $container->getDefinition('child')->getTags());
|
||||||
|
$this->assertSame(array(), $container->getDefinition('parent')->getTags());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,8 @@ class RegisterListenersPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$definition = $container->findDefinition($this->dispatcherService);
|
$definition = $container->findDefinition($this->dispatcherService);
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) {
|
foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) {
|
||||||
$def = $container->getDefinition($id);
|
$def = $container->getDefinition($id);
|
||||||
if ($def->isAbstract()) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
$priority = isset($event['priority']) ? $event['priority'] : 0;
|
$priority = isset($event['priority']) ? $event['priority'] : 0;
|
||||||
@ -87,11 +84,8 @@ class RegisterListenersPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$extractingDispatcher = new ExtractingEventDispatcher();
|
$extractingDispatcher = new ExtractingEventDispatcher();
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds($this->subscriberTag, true) as $id => $attributes) {
|
||||||
$def = $container->getDefinition($id);
|
$def = $container->getDefinition($id);
|
||||||
if ($def->isAbstract()) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
// We must assume that the class value has been correctly filled, even if the service is created by a factory
|
// We must assume that the class value has been correctly filled, even if the service is created by a factory
|
||||||
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
||||||
|
@ -89,7 +89,7 @@ class RegisterListenersPassTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
* @expectedExceptionMessage The service "foo" must not be abstract as event listeners are lazy-loaded.
|
* @expectedExceptionMessage The service "foo" tagged "kernel.event_listener" must not be abstract.
|
||||||
*/
|
*/
|
||||||
public function testAbstractEventListener()
|
public function testAbstractEventListener()
|
||||||
{
|
{
|
||||||
@ -103,7 +103,7 @@ class RegisterListenersPassTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
* @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded.
|
* @expectedExceptionMessage The service "foo" tagged "kernel.event_subscriber" must not be abstract.
|
||||||
*/
|
*/
|
||||||
public function testAbstractEventSubscriber()
|
public function testAbstractEventSubscriber()
|
||||||
{
|
{
|
||||||
|
@ -61,10 +61,9 @@ class FormPass implements CompilerPassInterface
|
|||||||
$servicesMap = array();
|
$servicesMap = array();
|
||||||
|
|
||||||
// Builds an array with fully-qualified type class names as keys and service IDs as values
|
// Builds an array with fully-qualified type class names as keys and service IDs as values
|
||||||
foreach ($container->findTaggedServiceIds($this->formTypeTag) as $serviceId => $tag) {
|
foreach ($container->findTaggedServiceIds($this->formTypeTag, true) as $serviceId => $tag) {
|
||||||
$serviceDefinition = $container->getDefinition($serviceId);
|
|
||||||
|
|
||||||
// Add form type service to the service locator
|
// Add form type service to the service locator
|
||||||
|
$serviceDefinition = $container->getDefinition($serviceId);
|
||||||
$servicesMap[$serviceDefinition->getClass()] = new Reference($serviceId);
|
$servicesMap[$serviceDefinition->getClass()] = new Reference($serviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +97,7 @@ class FormPass implements CompilerPassInterface
|
|||||||
private function processFormTypeGuessers(ContainerBuilder $container)
|
private function processFormTypeGuessers(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$guessers = array();
|
$guessers = array();
|
||||||
foreach ($container->findTaggedServiceIds($this->formTypeGuesserTag) as $serviceId => $tags) {
|
foreach ($container->findTaggedServiceIds($this->formTypeGuesserTag, true) as $serviceId => $tags) {
|
||||||
$guessers[] = new Reference($serviceId);
|
$guessers[] = new Reference($serviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +46,8 @@ class FragmentRendererPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$definition = $container->getDefinition($this->handlerService);
|
$definition = $container->getDefinition($this->handlerService);
|
||||||
$renderers = array();
|
$renderers = array();
|
||||||
foreach ($container->findTaggedServiceIds($this->rendererTag) as $id => $tags) {
|
foreach ($container->findTaggedServiceIds($this->rendererTag, true) as $id => $tags) {
|
||||||
$def = $container->getDefinition($id);
|
$def = $container->getDefinition($id);
|
||||||
if ($def->isAbstract()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
||||||
|
|
||||||
if (!$r = $container->getReflectionClass($class)) {
|
if (!$r = $container->getReflectionClass($class)) {
|
||||||
|
@ -48,12 +48,8 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
|||||||
$parameterBag = $container->getParameterBag();
|
$parameterBag = $container->getParameterBag();
|
||||||
$controllers = array();
|
$controllers = array();
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds($this->controllerTag) as $id => $tags) {
|
foreach ($container->findTaggedServiceIds($this->controllerTag, true) as $id => $tags) {
|
||||||
$def = $container->getDefinition($id);
|
$def = $container->getDefinition($id);
|
||||||
|
|
||||||
if ($def->isAbstract()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$class = $def->getClass();
|
$class = $def->getClass();
|
||||||
$autowire = $def->isAutowired();
|
$autowire = $def->isAutowired();
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class RoutingResolverPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$definition = $container->getDefinition($this->resolverServiceId);
|
$definition = $container->getDefinition($this->resolverServiceId);
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds($this->loaderTag) as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds($this->loaderTag, true) as $id => $attributes) {
|
||||||
$definition->addMethodCall('addLoader', array(new Reference($id)));
|
$definition->addMethodCall('addLoader', array(new Reference($id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,13 +38,9 @@ class AddConstraintValidatorsPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$validators = array();
|
$validators = array();
|
||||||
foreach ($container->findTaggedServiceIds($this->constraintValidatorTag) as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds($this->constraintValidatorTag, true) as $id => $attributes) {
|
||||||
$definition = $container->getDefinition($id);
|
$definition = $container->getDefinition($id);
|
||||||
|
|
||||||
if ($definition->isAbstract()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($attributes[0]['alias'])) {
|
if (isset($attributes[0]['alias'])) {
|
||||||
$validators[$attributes[0]['alias']] = new Reference($id);
|
$validators[$attributes[0]['alias']] = new Reference($id);
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,7 @@ class AddValidatorInitializersPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$initializers = array();
|
$initializers = array();
|
||||||
foreach ($container->findTaggedServiceIds($this->initializerTag) as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds($this->initializerTag, true) as $id => $attributes) {
|
||||||
if ($container->getDefinition($id)->isAbstract()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$initializers[] = new Reference($id);
|
$initializers[] = new Reference($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +31,6 @@ class AddConstraintValidatorsPassTest extends TestCase
|
|||||||
->addTag('validator.constraint_validator', array('alias' => 'my_constraint_validator_alias1'));
|
->addTag('validator.constraint_validator', array('alias' => 'my_constraint_validator_alias1'));
|
||||||
$container->register('my_constraint_validator_service2', Validator2::class)
|
$container->register('my_constraint_validator_service2', Validator2::class)
|
||||||
->addTag('validator.constraint_validator');
|
->addTag('validator.constraint_validator');
|
||||||
$container->register('my_abstract_constraint_validator')
|
|
||||||
->setAbstract(true)
|
|
||||||
->addTag('validator.constraint_validator');
|
|
||||||
|
|
||||||
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||||
$addConstraintValidatorsPass->process($container);
|
$addConstraintValidatorsPass->process($container);
|
||||||
@ -46,6 +43,24 @@ class AddConstraintValidatorsPassTest extends TestCase
|
|||||||
$this->assertEquals($expected, $container->getDefinition((string) $validatorFactory->getArgument(0)));
|
$this->assertEquals($expected, $container->getDefinition((string) $validatorFactory->getArgument(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage The service "my_abstract_constraint_validator" tagged "validator.constraint_validator" must not be abstract.
|
||||||
|
*/
|
||||||
|
public function testAbstractConstraintValidator()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$validatorFactory = $container->register('validator.validator_factory')
|
||||||
|
->addArgument(array());
|
||||||
|
|
||||||
|
$container->register('my_abstract_constraint_validator')
|
||||||
|
->setAbstract(true)
|
||||||
|
->addTag('validator.constraint_validator');
|
||||||
|
|
||||||
|
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||||
|
$addConstraintValidatorsPass->process($container);
|
||||||
|
}
|
||||||
|
|
||||||
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
|
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
|
||||||
{
|
{
|
||||||
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
|
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
|
||||||
|
Reference in New Issue
Block a user