setViolations example

class ValidationException extends Enlight_Exception implements ApiException
{
    /** * @deprecated - Will be native type hinted in Shopware 5.8 and not nullable anymore * * @var ConstraintViolationListInterface|null */
    protected $violations;

    public function __construct(ConstraintViolationListInterface $violations)
    {
        $this->setViolations($violations);

        parent::__construct((string) $this, Response::HTTP_BAD_REQUEST);
    }

    /** * @return string */
    public function __toString()
    {
        $output = '';

        
array_diff(array_keys($entity->getFieldDefinitions())$field_names)
      );
    }

    if (count($violations) > 0) {
      // Instead of returning a generic 400 response we use the more specific       // 422 Unprocessable Entity code from RFC 4918. That way clients can       // distinguish between general syntax errors in bad serializations (code       // 400) and semantic errors in well-formed requests (code 422).       // @see \Drupal\jsonapi\Normalizer\UnprocessableHttpEntityExceptionNormalizer       $exception = new UnprocessableHttpEntityException();
      $exception->setViolations($violations);
      throw $exception;
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.