Удалил jms serializer
Настроил использование своей библиотеки Чистка
This commit is contained in:
parent
453b918a6b
commit
1b9586f2f0
@ -8,11 +8,12 @@
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"ext-json": "*",
|
||||
"jms/serializer": "^3.13",
|
||||
"symfony/validator": "^5.3",
|
||||
"symfony/cache": "^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": {
|
||||
"codeception/codeception": "^4.1",
|
||||
|
833
composer.lock
generated
833
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -2,10 +2,7 @@
|
||||
|
||||
namespace Rinsvent\RequestBundle\EventListener;
|
||||
|
||||
use JMS\Serializer\SerializerBuilder;
|
||||
use ReflectionObject;
|
||||
use Rinsvent\AttributeExtractor\PropertyExtractor;
|
||||
use Rinsvent\RequestBundle\Annotation\PropertyPath;
|
||||
use Rinsvent\Data2DTO\Data2DtoConverter;
|
||||
use Rinsvent\RequestBundle\Annotation\RequestDTO;
|
||||
use Rinsvent\RequestBundle\DTO\Error;
|
||||
use Rinsvent\RequestBundle\DTO\ErrorCollection;
|
||||
@ -65,42 +62,20 @@ class RequestListener
|
||||
return $errorCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* todo переделать на перебор филлеров
|
||||
* Сделать регистрацию филлеров
|
||||
* и выексти филеры заполнения entity и documents в отдельных бандлах
|
||||
*/
|
||||
protected function grabRequestDTO(string $requestClass, string $content, array $queryParameters = [], array $parameters = [], array $headers = [])
|
||||
{
|
||||
$serializer = SerializerBuilder::create()->build();
|
||||
if ($content) {
|
||||
$object = $serializer->deserialize($content, $requestClass, 'json');
|
||||
} else {
|
||||
$object = new $requestClass;
|
||||
}
|
||||
$this->fillFromData($object, $queryParameters);
|
||||
$this->fillFromData($object, $parameters);
|
||||
$this->fillFromData($object, $headers);
|
||||
return $object;
|
||||
}
|
||||
|
||||
protected function fillFromData(object $object, array $data): object
|
||||
{
|
||||
$reflectionObject = new ReflectionObject($object);
|
||||
$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);
|
||||
}
|
||||
$data = [];
|
||||
try {
|
||||
$contentData = json_decode($content, true);
|
||||
$data += $contentData;
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
return $object;
|
||||
$data += $queryParameters;
|
||||
$data += $parameters;
|
||||
$data += $headers;
|
||||
|
||||
$data2dtoConverter = new Data2DtoConverter();
|
||||
return $data2dtoConverter->convert($data, $requestClass);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user