1. Go to this page and download the library: Download sfmok/request-input-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/ */
sfmok / request-input-bundle example snippets
use Sfmok\RequestInput\InputInterface;
class PostInput implements InputInterface
{
#[Assert\NotBlank]
private string $title;
#[Assert\NotBlank]
private string $content;
#[Assert\NotBlank]
private array $tags;
#[SerializedName('author')]
#[Assert\NotBlank]
private string $name;
# getters and setters or make properties public
}
class PostController
{
# Example with global config
#[Route(path: '/posts', name: 'create')]
public function create(PostInput $input): Response
{
dd($input);
}
# Example with specific config
#[Route(path: '/posts', name: 'create')]
#[Input(format: 'json', groups: ['create'], context: ['groups' => ['create']])]
public function create(PostInput $input): Response
{
dd($input);
}
}
declare(strict_types=1);
namespace App\Manager;
use App\Dto\PostInput;
use Sfmok\RequestInput\InputInterface;
use Symfony\Component\HttpFoundation\Request;
use Sfmok\RequestInput\Factory\InputFactoryInterface;
class PostManager
{
public function __construct(private InputFactoryInterface $inputFactory)
{
}
public function getInput(Request $request): InputInterface
{
return $this->inputFactory->createFromRequest($request, PostInput::class);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.