PHP code example of onmoon / openapi-server-bundle
1. Go to this page and download the library: Download onmoon/openapi-server-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/ */
declare (strict_types=1);
namespace App\Generated\Apis\PetStore\ShowPetById;
use OnMoon\OpenApiServerBundle\Interfaces\RequestHandler;
use App\Generated\Apis\PetStore\ShowPetById\Dto\Request\ShowPetByIdRequestDto;
use App\Generated\Apis\PetStore\ShowPetById\Dto\Response\ShowPetByIdResponse;
/**
* This interface was automatically generated
* You should not change it manually as it will be overwritten
*/
interface ShowPetById extends RequestHandler
{
/** Info for a specific pet */
public function showPetById(ShowPetByIdRequestDto $request) : ShowPetByIdResponse;
}
namespace App\Api;
use App\Repository\PetRepository;
use App\Generated\Apis\PetStore\ShowPetById\Dto\Request\ShowPetByIdRequestDto;
use App\Generated\Apis\PetStore\ShowPetById\Dto\Response\OK\ShowPetByIdResponseDto;
use App\Generated\Apis\PetStore\ShowPetById\Dto\Response\ShowPetByIdResponse;
use App\Generated\Apis\PetStore\ShowPetById\ShowPetById;
class ShowPetByIdHandler implements ShowPetById
{
private PetRepository $pets;
public function __construct(PetRepository $pets)
{
$this->pets = $pets;
}
public function showPetById(ShowPetByIdRequestDto $request) : ShowPetByIdResponse
{
$petId = $request->getPathParameters()->getPetId();
$pet = $this->pets->getById($petId);
return new ShowPetByIdResponseDto($pet->id(), $pet->name());
}
}