Доработал обработчик

Проинтегрировал библиотеку
Поправил описание библиотеки
This commit is contained in:
Rinsvent 2021-08-27 23:47:49 +07:00
parent eaded296aa
commit d8fd256977
4 changed files with 24 additions and 5681 deletions

View File

@ -1,6 +1,6 @@
{
"name": "rinsvent/request-bundle",
"description": "Request bundle",
"name": "rinsvent/response-bundle",
"description": "Response bundle",
"license": "proprietary",
"require": {
"php": "^8.0",
@ -11,7 +11,7 @@
"symfony/cache": "^5.3",
"symfony/string": "^5.3",
"rinsvent/attribute-extractor": "^0.0",
"rinsvent/data2dto": "^0.0",
"rinsvent/dto2data": "^0.0",
"doctrine/annotations": "^1.13"
},
"require-dev": {

5658
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,9 @@
namespace Rinsvent\ResponseBundle\EventListener;
use App\Response\JsonResponse;
use App\Serializer\EntitySchemaSerializer;
use Rinsvent\DTO2Data\Dto2DataConverter;
use Rinsvent\ResponseBundle\Response\JsonResponse;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class ResponseListener
{
@ -19,16 +19,15 @@ class ResponseListener
return;
}
$request = $event->getRequest();
$data = $response->getData();
if ($response->getSchema()) {
// $data = $this->entitySchemaSerializer->serializeBySchema($data, $response->getSchema());
}
if ($resultKey = $request->get('_result_key')) {
$data = [$resultKey => $data];
$data = $response->getRawData();
if (!is_object($data)) {
$response->setData($data);
return;
}
$dto2dataConverter = new Dto2DataConverter();
$data = $dto2dataConverter->convert($data);
$response->setData($data);
}
}

View File

@ -4,14 +4,16 @@ namespace Rinsvent\ResponseBundle\Response;
class JsonResponse extends \Symfony\Component\HttpFoundation\JsonResponse
{
public function __construct($data = null, int $status = 200, array $headers = [], bool $json = false)
{
parent::__construct(null, $status, $headers, $json);
$this->data = $data;
}
protected $rawData;
public function getData()
{
return $this->data;
}
public function __construct($data = null, int $status = 200, array $headers = [], bool $json = false)
{
parent::__construct(null, $status, $headers, $json);
$this->rawData = $data;
}
public function getRawData()
{
return $this->rawData;
}
}