for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Maba\Bundle\RestBundle\Annotation;
use Maba\Bundle\RestBundle\Entity\RestRequestOptions;
use Maba\Bundle\RestBundle\Entity\ValidationOptions;
use Maba\Bundle\RestBundle\Service\Annotation\ReflectionMethodWrapper;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
* @Target({"CLASS", "METHOD", "ANNOTATION"})
*/
class Validation implements RestAnnotationInterface
{
* @var array
private $groups;
private $violationPathMap;
* @var bool
private $enabled;
public function __construct(array $options)
$this->setGroups($options['groups'] ?? [Constraint::DEFAULT_GROUP]);
$this->setViolationPathMap($options['violationPathMap'] ?? []);
$this->setEnabled($options['enabled'] ?? true);
}
private function setGroups(array $groups): self
$this->groups = $groups;
return $this;
private function setViolationPathMap(array $violationPathMap): self
$this->violationPathMap = $violationPathMap;
private function setEnabled(bool $enabled): self
$this->enabled = $enabled;
public function isSeveralSupported(): bool
return true;
public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
if (!$this->enabled) {
$options->disableBodyValidation();
return;
$options->setBodyValidationOptions(
(new ValidationOptions())
->setValidationGroups($this->groups)
->setViolationPathMap($this->violationPathMap)
);