diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php index cd3af44a81..8b6555cfe2 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php @@ -107,7 +107,7 @@ class ProxyDumperTest extends \PHPUnit_Framework_TestCase $definitions = array( array(new Definition(__CLASS__), true), array(new Definition('stdClass'), true), - array(new Definition('foo'.uniqid()), false), + array(new Definition(uniqid('foo', true)), false), array(new Definition(), false), ); diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index 3581641d2d..1f43afcdc4 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -105,7 +105,7 @@ EOF $template .= fread(STDIN, 1024); } - return $this->display($input, $output, $io, array($this->validate($twig, $template, uniqid('sf_')))); + return $this->display($input, $output, $io, array($this->validate($twig, $template, uniqid('sf_', true)))); } $filesInfo = $this->getFilesInfo($twig, $filenames); diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php index e1e1edc416..800a32e2f3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php @@ -28,7 +28,17 @@ class AddConstraintValidatorsPass implements CompilerPassInterface $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); diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 7ed44c5bb8..dd0e839bf9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -75,7 +75,7 @@ class FrameworkBundle extends Bundle // 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()); diff --git a/src/Symfony/Component/Validator/Constraint.php b/src/Symfony/Component/Validator/Constraint.php index 4d6ab3eaac..fc5288d13b 100644 --- a/src/Symfony/Component/Validator/Constraint.php +++ b/src/Symfony/Component/Validator/Constraint.php @@ -129,6 +129,9 @@ abstract class Constraint unset($options['value']); } + if (is_array($options)) { + reset($options); + } if (is_array($options) && count($options) > 0 && is_string(key($options))) { foreach ($options as $option => $value) { if (array_key_exists($option, $knownOptions)) { diff --git a/src/Symfony/Component/Validator/Tests/ConstraintTest.php b/src/Symfony/Component/Validator/Tests/ConstraintTest.php index f63570c5d2..d473f14f65 100644 --- a/src/Symfony/Component/Validator/Tests/ConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/ConstraintTest.php @@ -206,4 +206,35 @@ class ConstraintTest extends \PHPUnit_Framework_TestCase { Constraint::getErrorName(1); } + + public function testOptionsAsDefaultOption() + { + $constraint = new ConstraintA($options = array('value1')); + + $this->assertEquals($options, $constraint->property2); + + $constraint = new ConstraintA($options = array('value1', 'property1' => 'value2')); + + $this->assertEquals($options, $constraint->property2); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\InvalidOptionsException + * @expectedExceptionMessage The options "0", "5" do not exist + */ + public function testInvalidOptions() + { + new ConstraintA(array('property2' => 'foo', 'bar', 5 => 'baz')); + } + + public function testOptionsWithInvalidInternalPointer() + { + $options = array('property1' => 'foo'); + next($options); + next($options); + + $constraint = new ConstraintA($options); + + $this->assertEquals('foo', $constraint->property1); + } }