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

Проинтегрировал библиотеку
Поправил описание библиотеки
master v0.0.1
Rinsvent 3 years ago
parent eaded296aa
commit d8fd256977
  1. 6
      composer.json
  2. 5658
      composer.lock
  3. 19
      src/EventListener/ResponseListener.php
  4. 20
      src/Response/JsonResponse.php

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

5658
composer.lock generated

File diff suppressed because it is too large Load Diff

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

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

Loading…
Cancel
Save