PHP code example of netmex / request-bundle

1. Go to this page and download the library: Download netmex/request-bundle 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/ */

    

netmex / request-bundle example snippets




namespace App\Request;

use Netmex\RequestBundle\Request\AbstractRequest;
use Symfony\Component\Validator\Constraints as Assert;

class CustomRequest extends AbstractRequest
{
    #[Assert\NotBlank()]
    public string $exampleField;
}




namespace App\Controller;

use App\DTO\CustomRequest;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ExampleController
{
    #[Route('/example', name: 'app_example')]
    public function index(CustomRequest $request): Response
    {
        // Validated and sanitized content
        $results = $request->content();

        return new Response($results);
    }
}

$request->content();

// Raw value (with optional fallback)
$request->get('fieldName', 'default');

try {
    $data = $request->getContent()->validate();
} catch (ValidationFailedException $e) {
    return new JsonResponse(['errors' => (string) $e->getViolations()], 400);
}
text
src/
├── Request/
│   └── YourDTO.php
└── Controller/
    └── YourController.php