Удалил jms serializer

Настроил использование своей библиотеки
Чистка
master
Sipachev Igor 3 years ago
parent 453b918a6b
commit 1b9586f2f0
  1. 5
      composer.json
  2. 829
      composer.lock
  3. 47
      src/EventListener/RequestListener.php

@ -8,11 +8,12 @@
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"ext-json": "*", "ext-json": "*",
"jms/serializer": "^3.13",
"symfony/validator": "^5.3", "symfony/validator": "^5.3",
"symfony/cache": "^5.3", "symfony/cache": "^5.3",
"symfony/string": "^5.3", "symfony/string": "^5.3",
"rinsvent/attribute-extractor": "^0.0.2" "rinsvent/attribute-extractor": "^0.0.3",
"rinsvent/data2dto": "^0.0.1",
"doctrine/annotations": "^1.13"
}, },
"require-dev": { "require-dev": {
"codeception/codeception": "^4.1", "codeception/codeception": "^4.1",

829
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -2,10 +2,7 @@
namespace Rinsvent\RequestBundle\EventListener; namespace Rinsvent\RequestBundle\EventListener;
use JMS\Serializer\SerializerBuilder; use Rinsvent\Data2DTO\Data2DtoConverter;
use ReflectionObject;
use Rinsvent\AttributeExtractor\PropertyExtractor;
use Rinsvent\RequestBundle\Annotation\PropertyPath;
use Rinsvent\RequestBundle\Annotation\RequestDTO; use Rinsvent\RequestBundle\Annotation\RequestDTO;
use Rinsvent\RequestBundle\DTO\Error; use Rinsvent\RequestBundle\DTO\Error;
use Rinsvent\RequestBundle\DTO\ErrorCollection; use Rinsvent\RequestBundle\DTO\ErrorCollection;
@ -65,42 +62,20 @@ class RequestListener
return $errorCollection; return $errorCollection;
} }
/**
* todo переделать на перебор филлеров
* Сделать регистрацию филлеров
* и выексти филеры заполнения entity и documents в отдельных бандлах
*/
protected function grabRequestDTO(string $requestClass, string $content, array $queryParameters = [], array $parameters = [], array $headers = []) protected function grabRequestDTO(string $requestClass, string $content, array $queryParameters = [], array $parameters = [], array $headers = [])
{ {
$serializer = SerializerBuilder::create()->build(); $data = [];
if ($content) { try {
$object = $serializer->deserialize($content, $requestClass, 'json'); $contentData = json_decode($content, true);
} else { $data += $contentData;
$object = new $requestClass; } catch (\Throwable $e) {
} }
$this->fillFromData($object, $queryParameters);
$this->fillFromData($object, $parameters);
$this->fillFromData($object, $headers);
return $object;
}
protected function fillFromData(object $object, array $data): object $data += $queryParameters;
{ $data += $parameters;
$reflectionObject = new ReflectionObject($object); $data += $headers;
$properties = $reflectionObject->getProperties();
foreach ($properties as $property) {
$propertyExtractor = new PropertyExtractor($object::class, $property->getName());
/** @var PropertyPath $propertyPath */
if ($propertyPath = $propertyExtractor->fetch(PropertyPath::class)) {
$value = $data[strtolower($propertyPath->path)][0] ?? null;
} else {
$value = $data[$property->getName()] ?? null;
}
if ($value) {
$property->setValue($object, $value);
}
}
return $object; $data2dtoConverter = new Data2DtoConverter();
return $data2dtoConverter->convert($data, $requestClass);
} }
} }

Loading…
Cancel
Save