proklung / request-validator-bundle
Symfony bundle for validate Request via annotations.
Installs: 25
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Type:symfony-bundle
Requires
- php: >=7.3 || ^8.0
- doctrine/annotations: ^1.10
- symfony/config: ^4.4 || ^5.0
- symfony/dependency-injection: ^4.4 || ^5.0
- symfony/expression-language: ^4.4 || ^5.0
- symfony/http-kernel: ^4.4 || ^5.0
- symfony/validator: ^4.4 || ^5.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-12-09 02:27:06 UTC
README
Форк пакета, доработано под личные нужды.
Установка
composer require proklung/request-validator-bundle
Использование
<?php use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Validator\Constraints as Assert; use Prokl\RequestValidatorBundle\Validator\RequestValidator; use Prokl\RequestValidatorBundle\Annotation\Validator; class AcmeController extends AbstractController { /** * @Validator(name="page", default="1", constraints={@Assert\Type(type="numeric"), @Assert\Range(min=1)}) * @Validator(name="limit", default="25", constraints={@Assert\Type(type="numeric"), @Assert\Range(min=10, max=100)}) * @Validator(name="order", default="desc", constraints={@Assert\Choice(choices={"asc", "desc"}, message="error.wrong_order_choice")}) * @Validator(name="name", constraints={@Assert\NotBlank()}) * @Validator(name="email", required=true, constraints={@Assert\Email()}) * * @param RequestValidator $requestValidator */ public function someAction(RequestValidator $requestValidator) { // You can get errors if there is any /** @var \Symfony\Component\Validator\ConstraintViolationList $errors */ $errors = $requestValidator->getErrors(); // You can get the request value with `get($path)` method $email = $requestValidator->get('email'); // ... } }