Обновил библиотеку

Проинтегрировал теги
master v0.0.3
Rinsvent 3 years ago
parent 7d38924dbd
commit e3a2e933f1
  1. 16
      composer.lock
  2. 30
      src/EventListener/RequestListener.php

16
composer.lock generated

@ -346,16 +346,16 @@
},
{
"name": "rinsvent/data2dto",
"version": "v0.0.2",
"version": "v0.0.4",
"source": {
"type": "git",
"url": "https://github.com/Rinsvent/data2dto.git",
"reference": "5ece49e3308b7a93147814ab865fe33bdf751798"
"reference": "10f1937434ff8e38b21ad54963488e40a4ad2a7d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Rinsvent/data2dto/zipball/5ece49e3308b7a93147814ab865fe33bdf751798",
"reference": "5ece49e3308b7a93147814ab865fe33bdf751798",
"url": "https://api.github.com/repos/Rinsvent/data2dto/zipball/10f1937434ff8e38b21ad54963488e40a4ad2a7d",
"reference": "10f1937434ff8e38b21ad54963488e40a4ad2a7d",
"shasum": ""
},
"require": {
@ -371,7 +371,7 @@
"codeception/module-asserts": "^1.0.0",
"codeception/module-phpbrowser": "^1.0.0"
},
"type": "project",
"type": "library",
"autoload": {
"psr-4": {
"tests\\": "tests/",
@ -380,14 +380,14 @@
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"proprietary"
"MIT"
],
"description": "Convert data to dto object",
"support": {
"issues": "https://github.com/Rinsvent/data2dto/issues",
"source": "https://github.com/Rinsvent/data2dto/tree/v0.0.2"
"source": "https://github.com/Rinsvent/data2dto/tree/v0.0.4"
},
"time": "2021-08-10T05:59:27+00:00"
"time": "2021-08-15T08:40:09+00:00"
},
{
"name": "symfony/cache",

@ -3,12 +3,10 @@
namespace Rinsvent\RequestBundle\EventListener;
use Rinsvent\Data2DTO\Data2DtoConverter;
use Rinsvent\Data2DTO\Resolver\TransformerResolverStorage;
use Rinsvent\RequestBundle\Annotation\RequestDTO;
use Rinsvent\RequestBundle\DTO\Error;
use Rinsvent\RequestBundle\DTO\ErrorCollection;
use Rinsvent\AttributeExtractor\MethodExtractor;
use Rinsvent\RequestBundle\Service\Transformer\ServiceResolver;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
@ -36,7 +34,15 @@ class RequestListener
/** @var RequestDTO $requestDTO */
while ($requestDTO = $methodExtractor->fetch(RequestDTO::class)) {
$requestDTOInstance = $this->grabRequestDTO($requestDTO, $request->getContent(), $request->query->all(), $request->request->all(), $request->headers->all());
$requestDTOInstance = $this->grabRequestDTO(
$requestDTO,
$request->get('_route'),
$request->getContent(),
$request->query->all(),
$request->request->all(),
$request->headers->all(),
$request->server->all(),
);
$errorCollection = $this->validate($requestDTOInstance);
if ($errorCollection->hasErrors()) {
@ -76,8 +82,15 @@ class RequestListener
return $errorCollection;
}
protected function grabRequestDTO(RequestDTO $requestDTO, string $content, array $queryParameters = [], array $parameters = [], array $headers = [])
{
protected function grabRequestDTO(
RequestDTO $requestDTO,
string $routeName,
string $content,
array $queryParameters = [],
array $parameters = [],
array $headers = [],
array $server = [],
) {
$data = [];
try {
$contentData = json_decode($content, true);
@ -88,10 +101,13 @@ class RequestListener
$data += $queryParameters;
$data += $parameters;
$data = $this->grabDataByJsonPath($data, $requestDTO->jsonPath);
$data += $headers;
$data2dtoConverter = new Data2DtoConverter();
return $data2dtoConverter->convert($data, $requestDTO->className);
$result = $data2dtoConverter->convert($data, $requestDTO->className, ['default', 'request', 'source_body', 'route_' . $routeName]);
$result = $data2dtoConverter->convert($headers, $requestDTO->className, ['default', 'request', 'source_headers', 'route_' . $routeName], $result);
$result = $data2dtoConverter->convert($server, $requestDTO->className, ['default', 'request', 'source_server', 'route_' . $routeName], $result);
return $result;
}
private function grabDataByJsonPath(array $data, string $jsonPath): array

Loading…
Cancel
Save