2011-01-05 11:13:27 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-05 11:13:27 +00:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
2016-10-05 17:00:01 +01:00
|
|
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
2011-01-05 11:13:27 +00:00
|
|
|
|
|
|
|
class AddConstraintValidatorsPass implements CompilerPassInterface
|
|
|
|
{
|
|
|
|
public function process(ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
if (!$container->hasDefinition('validator.validator_factory')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$validators = array();
|
|
|
|
foreach ($container->findTaggedServiceIds('validator.constraint_validator') as $id => $attributes) {
|
|
|
|
if (isset($attributes[0]['alias'])) {
|
|
|
|
$validators[$attributes[0]['alias']] = $id;
|
|
|
|
}
|
2015-12-05 01:08:46 +00:00
|
|
|
|
2016-09-30 19:57:07 +01:00
|
|
|
$definition = $container->getDefinition($id);
|
|
|
|
|
|
|
|
if (!$definition->isPublic()) {
|
|
|
|
throw new InvalidArgumentException(sprintf('The service "%s" must be public as it can be lazy-loaded.', $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($definition->isAbstract()) {
|
|
|
|
throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as it can be lazy-loaded.', $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
$validators[$definition->getClass()] = $id;
|
2011-01-05 11:13:27 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 22:29:10 +01:00
|
|
|
$container->getDefinition('validator.validator_factory')->replaceArgument(1, $validators);
|
2011-01-05 11:13:27 +00:00
|
|
|
}
|
2011-06-08 11:16:48 +01:00
|
|
|
}
|