PHP code example of youniverse-center / request-validation-bundle

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

    

youniverse-center / request-validation-bundle example snippets


#[Route('/some/route', name: 'some_route')]
#[RequestValidator(Create::class)]
class CreateController extends AbstractController
{
  public function __invoke($data)
  {
    // in the data is your validated request content
  }
}

public function getData(Request $request): mixed
{
    return json_decode($request->getContent(), true);
}

public function transformData(mixed $data): array
{
    $id = ProjectId::fromString($data['id']);

    return [
        'project' => new Project($id, $data['name'])
    ];
}

public function __invoke(Project $project) {}