Переименовал TagsResolver
Починил тесты Вынес модификацию тегов из конвертера. В будущем можно добавить опционально
This commit is contained in:
parent
9e42589419
commit
dabeee4a72
@ -3,7 +3,7 @@
|
||||
namespace Rinsvent\Data2DTO\Attribute;
|
||||
|
||||
#[\Attribute]
|
||||
class TagsResolver
|
||||
class HandleTags
|
||||
{
|
||||
public function __construct(
|
||||
public string $method,
|
@ -7,7 +7,7 @@ use Rinsvent\AttributeExtractor\ClassExtractor;
|
||||
use Rinsvent\AttributeExtractor\PropertyExtractor;
|
||||
use Rinsvent\Data2DTO\Attribute\DTOMeta;
|
||||
use Rinsvent\Data2DTO\Attribute\PropertyPath;
|
||||
use Rinsvent\Data2DTO\Attribute\TagsResolver;
|
||||
use Rinsvent\Data2DTO\Attribute\HandleTags;
|
||||
use Rinsvent\Data2DTO\Attribute\VirtualProperty;
|
||||
use Rinsvent\Data2DTO\Resolver\TransformerResolverStorage;
|
||||
use Rinsvent\Data2DTO\Transformer\Meta;
|
||||
@ -16,13 +16,16 @@ use function Symfony\Component\String\u;
|
||||
|
||||
class Data2DtoConverter
|
||||
{
|
||||
public function getTags(array $data, object $object, array $tags = []): array
|
||||
{
|
||||
return $this->processTags($object, $data, $tags);
|
||||
}
|
||||
|
||||
public function convert(array $data, object $object, array $tags = []): object
|
||||
{
|
||||
$tags = empty($tags) ? ['default'] : $tags;
|
||||
$reflectionObject = new \ReflectionObject($object);
|
||||
|
||||
$tags = $this->processTags($object, $data, $tags);
|
||||
|
||||
$this->processClassTransformers($reflectionObject, $data, $tags);
|
||||
if (is_object($data)) {
|
||||
return $data;
|
||||
@ -189,8 +192,8 @@ class Data2DtoConverter
|
||||
protected function processTags(object $object, array $data, array $tags): array
|
||||
{
|
||||
$classExtractor = new ClassExtractor($object::class);
|
||||
/** @var TagsResolver $tagsMeta */
|
||||
if ($tagsMeta = $classExtractor->fetch(TagsResolver::class)) {
|
||||
/** @var HandleTags $tagsMeta */
|
||||
if ($tagsMeta = $classExtractor->fetch(HandleTags::class)) {
|
||||
if (method_exists($object, $tagsMeta->method)) {
|
||||
$reflectionMethod = new \ReflectionMethod($object, $tagsMeta->method);
|
||||
if (!$reflectionMethod->isPublic()) {
|
||||
|
@ -3,9 +3,6 @@
|
||||
namespace Rinsvent\Data2DTO\Tests\Converter;
|
||||
|
||||
use Rinsvent\Data2DTO\Data2DtoConverter;
|
||||
use Rinsvent\Data2DTO\Tests\unit\Converter\fixtures\FillTest\Bar;
|
||||
use Rinsvent\Data2DTO\Tests\unit\Converter\fixtures\FillTest\BuyRequest;
|
||||
use Rinsvent\Data2DTO\Tests\unit\Converter\fixtures\FillTest\HelloRequest;
|
||||
use Rinsvent\Data2DTO\Tests\unit\Converter\fixtures\FillTest\HelloTagsRequest;
|
||||
|
||||
class TagsTest extends \Codeception\Test\Unit
|
||||
@ -27,7 +24,8 @@ class TagsTest extends \Codeception\Test\Unit
|
||||
public function testSuccessFillRequestData()
|
||||
{
|
||||
$data2DtoConverter = new Data2DtoConverter();
|
||||
$dto = $data2DtoConverter->convert([
|
||||
|
||||
$data = [
|
||||
'surname' => 'Surname1234',
|
||||
'fake_age' => 3,
|
||||
'fake_age2' => 7,
|
||||
@ -36,7 +34,9 @@ class TagsTest extends \Codeception\Test\Unit
|
||||
'af234f',
|
||||
'asdf33333'
|
||||
],
|
||||
], new HelloTagsRequest);
|
||||
];
|
||||
$tags = $data2DtoConverter->getTags($data, new HelloTagsRequest);
|
||||
$dto = $data2DtoConverter->convert($data, new HelloTagsRequest, $tags);
|
||||
$this->assertInstanceOf(HelloTagsRequest::class, $dto);
|
||||
$this->assertEquals(7, $dto->age);
|
||||
|
||||
|
@ -3,9 +3,9 @@
|
||||
namespace Rinsvent\Data2DTO\Tests\unit\Converter\fixtures\FillTest;
|
||||
|
||||
use Rinsvent\Data2DTO\Attribute\PropertyPath;
|
||||
use Rinsvent\Data2DTO\Attribute\TagsResolver;
|
||||
use Rinsvent\Data2DTO\Attribute\HandleTags;
|
||||
|
||||
#[TagsResolver(method: 'getTags')]
|
||||
#[HandleTags(method: 'getTags')]
|
||||
class HelloTagsRequest extends HelloRequest
|
||||
{
|
||||
#[PropertyPath('fake_age2', tags: ['surname-group'])]
|
||||
|
Loading…
Reference in New Issue
Block a user