Доработал обработчик
Проинтегрировал библиотеку Поправил описание библиотеки
This commit is contained in:
parent
eaded296aa
commit
d8fd256977
@ -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
5658
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,16 @@ namespace Rinsvent\ResponseBundle\Response;
|
||||
|
||||
class JsonResponse extends \Symfony\Component\HttpFoundation\JsonResponse
|
||||
{
|
||||
protected $rawData;
|
||||
|
||||
public function __construct($data = null, int $status = 200, array $headers = [], bool $json = false)
|
||||
{
|
||||
parent::__construct(null, $status, $headers, $json);
|
||||
$this->data = $data;
|
||||
$this->rawData = $data;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
public function getRawData()
|
||||
{
|
||||
return $this->data;
|
||||
return $this->rawData;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user