/**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setNormalizer('constraints', function (Options $options, $constraints) {
         $constraints = is_object($constraints) ? array($constraints) : (array) $constraints;
         $constraintObjects = array();
         foreach ($constraints as $constraint) {
             if (is_array($constraint)) {
                 foreach ($constraint as $name => $options) {
                     $constraintObjects[] = $this->constraintFactory->create($name, $options);
                 }
             } elseif (is_object($constraint)) {
                 $constraintObjects[] = $constraint;
             }
         }
         return $constraintObjects;
     });
 }
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $constraintsNormalizer = function (Options $options, $constraints) {
         $constraints = is_object($constraints) ? array($constraints) : (array) $constraints;
         $constraintObjects = array();
         foreach ($constraints as $constraint) {
             if (is_array($constraint)) {
                 foreach ($constraint as $name => $options) {
                     $constraintObjects[] = $this->constraintFactory->create($name, $options);
                 }
             } elseif (is_object($constraint)) {
                 $constraintObjects[] = $constraint;
             }
         }
         return $constraintObjects;
     };
     $resolver->setNormalizers(array('constraints' => $constraintsNormalizer));
 }
 /**
  * @param array $constraints
  * @return array|Constraint[]
  */
 protected function getFieldConstraints(array $constraints)
 {
     $constraintObjects = [];
     foreach ($constraints as $constraint) {
         foreach ($constraint as $name => $options) {
             $constraintObjects[] = $this->constraintFactory->create($name, $options);
         }
     }
     return $constraintObjects;
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testCreateInvalidConstraint()
 {
     $factory = new ConstraintFactory();
     $factory->create('test');
 }
Esempio n. 5
0
 /**
  * @param string $expectedClass
  * @param string $name
  * @param mixed $options
  * @dataProvider createDataProvider
  */
 public function testCreate($expectedClass, $name, $options)
 {
     $factory = new ConstraintFactory();
     $this->assertInstanceOf($expectedClass, $factory->create($name, $options));
 }