1. Go to this page and download the library: Download dimkinthepro/http-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/ */
# src/App/DTO/RequestDTO.php
namespace App\DTO;
use Dimkinthepro\Http\Domain\DTO\ValidatedDTOInterface;
class RequestDTO implements ValidatedDTOInterface
{
public string $method;
public int $parameter;
public \DateTimeImmutable $date;
public App\Enum\FooEnum $enum;
}
# src/App/Controller/Controller.php
namespace App\Controller;
use App\DTO\RequestDTO;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
class Controller extends AbstractController
{
public function __invoke(RequestDTO $DTO): JsonResponse
{
return new JsonResponse([
'method' => $DTO->method,
'parameter' => $DTO->parameter,
'date' => $DTO->date,
'enum' => $DTO->enum->value,
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.