diff --git a/src/Context/LocalContext.php b/src/Context/LocalContext.php index 368fa35..ec73c33 100644 --- a/src/Context/LocalContext.php +++ b/src/Context/LocalContext.php @@ -103,6 +103,11 @@ public function getPath(): PathInterface return $this->path; } + public function contains(mixed $value): bool + { + return $this->path->contains($value); + } + /** * @return $this */ diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 613b77e..ca6c25a 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -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; @@ -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())); @@ -93,6 +96,8 @@ class: $this->metadata->getName(), $context->leave(); } + $context->leave(); + if ($context->isObjectsAsArrays()) { return $result; } @@ -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())); @@ -184,6 +191,8 @@ class: $this->metadata->getName(), ); } + $context->leave(); + return $object; }