Symfony\Component\Validator\ConstraintViolationList::addAll PHP Method

addAll() public method

Merge an existing ConstraintViolationList into this list.
public addAll ( ConstraintViolationList $otherList )
$otherList ConstraintViolationList
    public function addAll(ConstraintViolationList $otherList)
    {
        foreach ($otherList->violations as $violation) {
            $this->violations[] = $violation;
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Core request handler.
  *
  * @param GetResponseEvent $event The event
  *
  * @throws BadRequestHttpException
  * @throws UnsupportedMediaTypeHttpException
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $metadata = $this->getControllerActionMetadata($controller);
     if (null !== $metadata) {
         $violations = new ConstraintViolationList();
         if (0 < count($metadata->queryParams)) {
             // set defaults
             $this->setDefaultValues($metadata->queryParams, $request->query);
             $queryViolations = $this->validateParams($this->container->get('validator'), $metadata->queryParams, $request->query);
             $violations->addAll($queryViolations);
         }
         if (0 < count($metadata->requestParams)) {
             // set defaults
             $this->setDefaultValues($metadata->requestParams, $request->request);
             $requestViolations = $this->validateParams($this->container->get('validator'), $metadata->requestParams, $request->request);
             $violations->addAll($requestViolations);
         }
         $violationParam = $this->getViolationsParameterName($metadata);
         if (null !== $violationParam) {
             // if action has an argument for violations, pass it
             $request->attributes->set($violationParam, $violations);
         } elseif (0 < count($violations)) {
             // if action has no arg for violations and there is at least one, throw an exception
             throw new ValidationException($violations);
         }
     }
 }
All Usage Examples Of Symfony\Component\Validator\ConstraintViolationList::addAll