Skip to content

Commit

Permalink
Improve object type context
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Jul 3, 2024
1 parent a3c0853 commit d798960
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Context/LocalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public function getPath(): PathInterface
return $this->path;
}

public function contains(mixed $value): bool
{
return $this->path->contains($value);
}

/**
* @return $this
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace TypeLang\Mapper\Type;

use TypeLang\Mapper\Context\LocalContext;
use TypeLang\Mapper\Context\Path\ObjectEntry;
use TypeLang\Mapper\Context\Path\ObjectPropertyEntry;
use TypeLang\Mapper\Exception\Mapping\InvalidValueException;
use TypeLang\Mapper\Exception\Mapping\MissingRequiredFieldException;
Expand Down Expand Up @@ -70,6 +71,8 @@ private function normalizeObject(object $object, RegistryInterface $types, Local
$result = [];
$reflection = $this->metadata->getReflection();

$context->enter(new ObjectEntry($this->metadata->getName()));

foreach ($this->metadata->getProperties() as $meta) {
$context->enter(new ObjectPropertyEntry($meta->getName()));

Expand All @@ -93,6 +96,8 @@ class: $this->metadata->getName(),
$context->leave();
}

$context->leave();

if ($context->isObjectsAsArrays()) {
return $result;
}
Expand Down Expand Up @@ -147,6 +152,8 @@ private function denormalizeObject(array $value, RegistryInterface $types, Local
$object = $this->newInstance();
$reflection = $this->metadata->getReflection();

$context->enter(new ObjectEntry($this->metadata->getName()));

foreach ($this->metadata->getProperties() as $meta) {
$context->enter(new ObjectPropertyEntry($meta->getExportName()));

Expand Down Expand Up @@ -184,6 +191,8 @@ class: $this->metadata->getName(),
);
}

$context->leave();

return $object;
}

Expand Down

0 comments on commit d798960

Please sign in to comment.