Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykbaszak committed Oct 19, 2023
1 parent 1667f93 commit c4049ac
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 239 deletions.
198 changes: 109 additions & 89 deletions output.yaml
Original file line number Diff line number Diff line change
@@ -1,92 +1,112 @@
main: PBaszak\DedicatedMapper\Tests\assets\Dummy
classes:
PBaszak\DedicatedMapper\Tests\assets\Dummy:
attributes: { }
className: PBaszak\DedicatedMapper\Tests\assets\Dummy
options: { }
properties:
id:
attributes:
-
class: Symfony\Component\Validator\Constraints\NotBlank
arguments: { }
instance: "\\Symfony\\Component\\Validator\\Constraints\\NotBlank::__set_state(array(\n 'payload' => NULL,\n 'message' => 'This value should not be blank.',\n 'allowNull' => false,\n 'normalizer' => NULL,\n))"
-
class: Symfony\Component\Serializer\Annotation\Groups
arguments:
- test
instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))"
name: id
options: { }
type:
types:
- string
innerType: null
nullable: false
union: false
intersection: false
class: false
collection: false
simpleObject: false
name:
attributes:
-
class: Symfony\Component\Validator\Constraints\Length
arguments:
min: 3
max: 255
instance: "\\Symfony\\Component\\Validator\\Constraints\\Length::__set_state(array(\n 'payload' => NULL,\n 'maxMessage' => 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.',\n 'minMessage' => 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.',\n 'exactMessage' => 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.',\n 'charsetMessage' => 'This value does not match the expected {{ charset }} charset.',\n 'max' => 255,\n 'min' => 3,\n 'charset' => 'UTF-8',\n 'normalizer' => NULL,\n 'countUnit' => 'codepoints',\n))"
-
class: Symfony\Component\Serializer\Annotation\Groups
arguments:
- test
instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))"
name: name
options: { }
type:
types:
- string
innerType: null
nullable: false
union: false
intersection: false
class: false
collection: false
simpleObject: false
description:
attributes: { }
name: description
options: { }
type:
types:
- string
innerType: null
nullable: false
union: false
intersection: false
class: false
collection: false
simpleObject: false
_embedded:
attributes:
-
class: Symfony\Component\Validator\Constraints\Valid
arguments: { }
instance: "\\Symfony\\Component\\Validator\\Constraints\\Valid::__set_state(array(\n 'payload' => NULL,\n 'traverse' => true,\n))"
-
class: Symfony\Component\Serializer\Annotation\Groups
arguments:
- test
instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))"
name: _embedded
options: { }
type:
types:
- PBaszak\DedicatedMapper\Tests\assets\EmbeddedDTO
innerType: null
nullable: false
union: false
intersection: false
class: true
collection: false
simpleObject: false
classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType
reflection:
attributes: { }
className: PBaszak\DedicatedMapper\Tests\assets\Dummy
file:
path: /app/tests/assets/Dummy.php
hash: 24ba2ede85a4491930ed05f368b3816c
options: { }
properties:
id:
attributes:
-
class: Symfony\Component\Validator\Constraints\NotBlank
arguments: { }
instance: "\\Symfony\\Component\\Validator\\Constraints\\NotBlank::__set_state(array(\n 'payload' => NULL,\n 'message' => 'This value should not be blank.',\n 'allowNull' => false,\n 'normalizer' => NULL,\n))"
-
class: Symfony\Component\Serializer\Annotation\Groups
arguments:
- test
instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))"
name: id
options: { }
type:
classType: PBaszak\DedicatedMapper\Reflection\Type\Type
types:
- string
innerType: null
nullable: false
union: false
intersection: false
class: false
collection: false
simpleObject: false
name:
attributes:
-
class: Symfony\Component\Validator\Constraints\Length
arguments:
min: 3
max: 255
instance: "\\Symfony\\Component\\Validator\\Constraints\\Length::__set_state(array(\n 'payload' => NULL,\n 'maxMessage' => 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.',\n 'minMessage' => 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.',\n 'exactMessage' => 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.',\n 'charsetMessage' => 'This value does not match the expected {{ charset }} charset.',\n 'max' => 255,\n 'min' => 3,\n 'charset' => 'UTF-8',\n 'normalizer' => NULL,\n 'countUnit' => 'codepoints',\n))"
-
class: Symfony\Component\Serializer\Annotation\Groups
arguments:
- test
instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))"
name: name
options: { }
type:
classType: PBaszak\DedicatedMapper\Reflection\Type\Type
types:
- string
innerType: null
nullable: false
union: false
intersection: false
class: false
collection: false
simpleObject: false
description:
attributes: { }
name: description
options: { }
type:
classType: PBaszak\DedicatedMapper\Reflection\Type\Type
types:
- string
innerType: null
nullable: false
union: false
intersection: false
class: false
collection: false
simpleObject: false
_embedded:
attributes:
-
class: Symfony\Component\Validator\Constraints\Valid
arguments: { }
instance: "\\Symfony\\Component\\Validator\\Constraints\\Valid::__set_state(array(\n 'payload' => NULL,\n 'traverse' => true,\n))"
-
class: Symfony\Component\Serializer\Annotation\Groups
arguments:
- test
instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))"
name: _embedded
options: { }
type:
classType: PBaszak\DedicatedMapper\Reflection\Type\Type
types:
- \PBaszak\DedicatedMapper\Tests\assets\EmbeddedDTO
innerType: null
nullable: false
union: false
intersection: false
class: true
collection: false
simpleObject: false
type:
classType: PBaszak\DedicatedMapper\Reflection\Type\Type
types:
- \PBaszak\DedicatedMapper\Tests\assets\Dummy
innerType: null
nullable: false
union: false
intersection: false
class: true
collection: false
simpleObject: false
7 changes: 3 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ public function __construct(protected string $className)
public function reflect(): self
{
ClassType::$classTypes = [];
(new TypeFactory(new ReflectionFactory()))->createClassType(
new \ReflectionClass($this->className),
null
$type = (new TypeFactory(new ReflectionFactory()))->createFromReflection(
new \ReflectionClass($this->className)
);

ClassType::create($type);
$this->classes = ClassType::$classTypes;

return $this;
Expand Down
18 changes: 8 additions & 10 deletions src/Reflection/AttributeReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace PBaszak\DedicatedMapper\Reflection;

use ArrayObject;
use PBaszak\DedicatedMapper\Reflection\Type\CollectionType;
use PBaszak\DedicatedMapper\Reflection\Type\SimpleObjectType;

class AttributeReflection
class AttributeReflection implements ReflectionInterface
{
public function toArray(): array
{
Expand All @@ -24,27 +22,27 @@ public function toArray(): array

public function __construct(
/**
* @var ClassReflection|CollectionType|PropertyReflection|SimpleObjectType $parent each attribute must have resource
* @var ClassReflection|PropertyReflection $parent each attribute must have resource
*/
protected ClassReflection|CollectionType|PropertyReflection|SimpleObjectType $parent,
protected ClassReflection|PropertyReflection $parent,

/**
* @var ArrayObject<object{"class": string, "arguments": mixed[]}> $attributes
* @var ArrayObject<object{"class": string, "arguments": mixed[], "instance": ?object}> $attributes
*/
protected ArrayObject $attributes,
) {
}

/**
* @return ClassReflection|CollectionType|PropertyReflection|SimpleObjectType
* @return ClassReflection|PropertyReflection
*/
public function getParent(): ClassReflection|CollectionType|PropertyReflection|SimpleObjectType
public function getParent(): ClassReflection|PropertyReflection
{
return $this->parent;
}

/**
* @return ArrayObject<object{"class": string, "arguments": mixed[]}>
* @return ArrayObject<object{"class": string, "arguments": mixed[], "instance": ?object}>
*/
public function getAttributes(): ArrayObject
{
Expand All @@ -54,7 +52,7 @@ public function getAttributes(): ArrayObject
/**
* @param class-string $class
*
* @return null|object{"class": string, "arguments": mixed[]}
* @return null|object{"class": string, "arguments": mixed[], "instance": ?object}
*/
public function getAttribute(string $class): ?object
{
Expand Down
8 changes: 5 additions & 3 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

use ArrayObject;
use PBaszak\DedicatedMapper\Reflection\Type\ClassType;
use PBaszak\DedicatedMapper\Utils\ToArrayTrait;
use ReflectionClass;
use Serializable;

class ClassReflection
class ClassReflection implements ReflectionInterface
{
public function toArray(): array
{
return [
'attributes' => $this->attributes->toArray(),
'className' => $this->reflection?->getName(),
'file' => [
'path' => $this->reflection?->getFileName(),
'hash' => $this->reflection?->getFileName() ? md5_file($this->reflection->getFileName()) : null,
],
'options' => $this->options->toArray(),
'properties' => array_map(fn (PropertyReflection $property) => $property->toArray(), $this->properties->getArrayCopy()),
];
Expand Down
3 changes: 1 addition & 2 deletions src/Reflection/PropertyReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
namespace PBaszak\DedicatedMapper\Reflection;

use PBaszak\DedicatedMapper\Reflection\Type\TypeInterface;
use PBaszak\DedicatedMapper\Utils\ToArrayTrait;

class PropertyReflection
class PropertyReflection implements ReflectionInterface
{
public function toArray(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/ReflectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function createPropertyReflection(\ReflectionProperty $reflection, ClassR
$attributes = new AttributeReflection($instance, $this->getAttributesFromReflection($reflection));
$ref->getProperty('attributes')->setValue($instance, $attributes);
$ref->getProperty('options')->setValue($instance, new Options());
$ref->getProperty('type')->setValue($instance, (new TypeFactory($this))->createType($instance));
$ref->getProperty('type')->setValue($instance, (new TypeFactory($this))->createFromReflection($reflection, $instance));

return $instance;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Reflection/ReflectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace PBaszak\DedicatedMapper\Reflection;

interface ReflectionInterface
{
public function toArray(): array;
}
Loading

0 comments on commit c4049ac

Please sign in to comment.