Exemplo n.º 1
0
 public function normalize(Field $entity)
 {
     $normalized = [];
     $constraints = $entity->getConstraints();
     if (isset($constraints['expression'])) {
         $normalized[] = new Assert\Expression($constraints['expression']);
     }
     return $normalized;
 }
Exemplo n.º 2
0
 public function getConstraintsData(BuilderInterface $builder, Field $entity, $normalize = false)
 {
     $config = $entity->getConstraints();
     foreach ($builder->supportsConstraints($entity) as $constraintClass) {
         $constraint = $this->getCachedObject($constraintClass);
         foreach ($constraint->getDefaults($entity) as $key => $value) {
             if (!isset($config[$key])) {
                 $config[$key] = $value;
             }
         }
     }
     $entity->setConstraints($config);
     if (!$normalize) {
         return $entity->getConstraints();
     }
     $constraints = [];
     foreach ($builder->supportsConstraints($entity) as $constraintClass) {
         $constraint = $this->getCachedObject($constraintClass);
         $test = $constraint->normalize($entity, $constraints);
         if (is_array($test)) {
             $constraints += $test;
         }
     }
     if ($entity->isRequired()) {
         $constraints[] = new Assert\NotBlank();
     }
     return $constraints;
 }