1. Go to this page and download the library: Download rollun-com/rollun-openapi 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/ */
namespace HelloUser\OpenAPI\V1\Server\Rest;
use Articus\DataTransfer\Service as DataTransferService;
use OpenAPI\Server\Rest\Base7Abstract;
use Psr\Log\LoggerInterface;
use rollun\dic\InsideConstruct;
/**
* Class User
*/
class User extends Base7Abstract
{
public const CONTROLLER_OBJECT = 'User1Controller';
/** @var object */
protected $controllerObject;
/** @var LoggerInterface */
protected $logger;
/** @var DataTransferService */
protected $dataTransfer;
/**
* User constructor.
*
* @param mixed $controllerObject
* @param LoggerInterface|null logger
* @param DataTransferService|null dataTransfer
*
* @throws \ReflectionException
*/
public function __construct($controllerObject = null, $logger = null, $dataTransfer = null)
{
InsideConstruct::init([
'controllerObject' => static::CONTROLLER_OBJECT,
'logger' => LoggerInterface::class,
'dataTransfer' => DataTransferService::class
]);
}
/**
* @inheritDoc
*
* @param \HelloUser\OpenAPI\V1\DTO\User $bodyData
*/
public function post($bodyData = null)
{
if (method_exists($this->controllerObject, 'post')) {
$bodyDataArray =$this->dataTransfer->extractFromTypedData($bodyData);
return $this->controllerObject->post($bodyDataArray);
}
throw new \Exception('Not implemented method');
}
/**
* @inheritDoc
*/
public function getById($id)
{
if (method_exists($this->controllerObject, 'getById')) {
return $this->controllerObject->getById($id);
}
throw new \Exception('Not implemented method');
}
}
namespace OpenAPI;
use HelloUser\OpenAPI\V1\Client\Rest\Hello;
use OpenAPI\Client\Rest\ClientInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use rollun\dic\InsideConstruct;use Zend\Diactoros\Response;
class TestHandler implements RequestHandlerInterface
{
/**
* @var ClientInterface|null
*/
private $rest;
public function __construct(ClientInterface $rest = null)
{
InsideConstruct::init(['rest' => Hello::class]);
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->rest->setHostIndex(1);
$result = $this->rest->getById('10');
return new Response\JsonResponse($result);
}
}
public function orderIdUserPost(string $id, User $bodyData)
{
// code
}
public function setOrderUser(string $id, User $bodyData)
{
// code
}