PHP code example of thvvger / symfony-request-validator

1. Go to this page and download the library: Download thvvger/symfony-request-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thvvger / symfony-request-validator example snippets


    return [
        Thvvger\RequestValidator\RequestValidatorBundle::class => ['all' => true],
    ];

    namespace App\Request;
    
    use Symfony\Component\Validator\Constraints\NotBlank;
    use Symfony\Component\Validator\Constraints\Type;
    use Thvvger\RequestValidator\BaseRequest;
    
    class TestRequest extends BaseRequest
    {
        #[NotBlank]
        #[Type('string')]
        public readonly string $name;
        
        // add other properties
    }

    #[Route('/test', methods: ['POST'])]
    public function test(TestRequest $request): JsonResponse
    {
        //...
        
        // Return a success message after the request is processed
        return new JsonResponse([
            'message' => 'Request exécuted succesfully',
        ]);
    }
shell
  php bin/console make:request TestRequest