Skip to content

Commit

Permalink
bug #20116 fixed AddConstraintValidatorsPass config (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.2-dev branch.

Discussion
----------

fixed AddConstraintValidatorsPass config

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

Commits
-------

65131e2 added checks for public services on compiler passes that use service id and not references
  • Loading branch information
fabpot committed Oct 1, 2016
2 parents d10f5d2 + 9d86da8 commit 568247e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion DependencyInjection/Compiler/AddConstraintValidatorsPass.php
Expand Up @@ -28,7 +28,17 @@ public function process(ContainerBuilder $container)
$validators[$attributes[0]['alias']] = $id;
}

$validators[$container->getDefinition($id)->getClass()] = $id;
$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;
}

$container->getDefinition('validator.validator_factory')->replaceArgument(1, $validators);
Expand Down
2 changes: 1 addition & 1 deletion FrameworkBundle.php
Expand Up @@ -76,7 +76,7 @@ public function build(ContainerBuilder $container)
// but as late as possible to get resolved parameters
$container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new TemplatingPass());
$container->addCompilerPass(new AddConstraintValidatorsPass());
$container->addCompilerPass(new AddConstraintValidatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new AddValidatorInitializersPass());
$container->addCompilerPass(new AddConsoleCommandPass());
$container->addCompilerPass(new FormPass());
Expand Down

0 comments on commit 568247e

Please sign in to comment.