diff --git a/bundle/DependencyInjection/Compiler/VarDumperPass.php b/bundle/DependencyInjection/Compiler/VarDumperPass.php new file mode 100644 index 00000000..0e05b77f --- /dev/null +++ b/bundle/DependencyInjection/Compiler/VarDumperPass.php @@ -0,0 +1,55 @@ +hasDefinition(self::ClonerId)) { + return; + } + + $clonerDefinition = $container->findDefinition(self::ClonerId); + + $clonerDefinition->addMethodCall( + 'addCasters', + [ + '$casters' => [ + DebugInfo::class => [self::class, 'cast'], + ], + ], + ); + } + + public static function cast(DebugInfo $object, array $array): array + { + $debugInfo = $object->getDebugInfo(); + $debugData = []; + + foreach ($debugInfo as $key => $value) { + if (!isset($key[0]) || $key[0] !== "\0") { + if (array_key_exists(Caster::PREFIX_DYNAMIC . $key, $array)) { + continue; + } + + $key = Caster::PREFIX_VIRTUAL . $key; + } + + unset($array[$key]); + + $debugData[$key] = $value; + } + + return array_merge($debugData, $array); + } +} diff --git a/bundle/NetgenIbexaSiteApiBundle.php b/bundle/NetgenIbexaSiteApiBundle.php index ee38f8a5..c59001be 100644 --- a/bundle/NetgenIbexaSiteApiBundle.php +++ b/bundle/NetgenIbexaSiteApiBundle.php @@ -12,6 +12,7 @@ use Netgen\Bundle\IbexaSiteApiBundle\DependencyInjection\Compiler\RelationResolverRegistrationPass; use Netgen\Bundle\IbexaSiteApiBundle\DependencyInjection\Compiler\UrlAliasGeneratorOverridePass; use Netgen\Bundle\IbexaSiteApiBundle\DependencyInjection\Compiler\UrlAliasRouterOverridePass; +use Netgen\Bundle\IbexaSiteApiBundle\DependencyInjection\Compiler\VarDumperPass; use Netgen\Bundle\IbexaSiteApiBundle\DependencyInjection\Compiler\ViewBuilderRegistrationPass; use Netgen\Bundle\IbexaSiteApiBundle\DependencyInjection\Configuration\Parser\ContentView; use Netgen\Bundle\IbexaSiteApiBundle\DependencyInjection\Configuration\Parser\SiteApi; @@ -32,6 +33,7 @@ public function build(ContainerBuilder $container): void $container->addCompilerPass(new QueryTypeExpressionFunctionProviderPass()); $container->addCompilerPass(new RedirectExpressionFunctionProviderPass()); $container->addCompilerPass(new RelationResolverRegistrationPass()); + $container->addCompilerPass(new VarDumperPass()); $container->addCompilerPass(new ViewBuilderRegistrationPass()); /** @var \Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension $coreExtension */ diff --git a/lib/API/Values/Content.php b/lib/API/Values/Content.php index 4e1e2241..193d8f52 100644 --- a/lib/API/Values/Content.php +++ b/lib/API/Values/Content.php @@ -34,7 +34,7 @@ * @property-read \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $innerVersionInfo * @property-read \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo */ -abstract class Content extends ValueObject +abstract class Content extends ValueObject implements DebugInfo { /** * Returns if Content has the field with the given field definition $identifier. diff --git a/lib/API/Values/ContentInfo.php b/lib/API/Values/ContentInfo.php index b54ea238..93b0b8bf 100644 --- a/lib/API/Values/ContentInfo.php +++ b/lib/API/Values/ContentInfo.php @@ -36,4 +36,4 @@ * @property-read \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType $innerContentType * @property-read ?\Netgen\IbexaSiteApi\API\Values\Location $mainLocation */ -abstract class ContentInfo extends ValueObject {} +abstract class ContentInfo extends ValueObject implements DebugInfo {} diff --git a/lib/API/Values/DebugInfo.php b/lib/API/Values/DebugInfo.php new file mode 100644 index 00000000..e7212d7a --- /dev/null +++ b/lib/API/Values/DebugInfo.php @@ -0,0 +1,16 @@ + + */ + public function getDebugInfo(): array; +} diff --git a/lib/API/Values/Field.php b/lib/API/Values/Field.php index 4eb0de46..8d4e3bd2 100644 --- a/lib/API/Values/Field.php +++ b/lib/API/Values/Field.php @@ -24,7 +24,7 @@ * @property-read \Ibexa\Contracts\Core\Repository\Values\Content\Field $innerField * @property-read \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $innerFieldDefinition */ -abstract class Field extends ValueObject +abstract class Field extends ValueObject implements DebugInfo { abstract public function isEmpty(): bool; diff --git a/lib/API/Values/Fields.php b/lib/API/Values/Fields.php index db28bb0f..2b338d43 100644 --- a/lib/API/Values/Fields.php +++ b/lib/API/Values/Fields.php @@ -13,7 +13,7 @@ * * @see \Netgen\IbexaSiteApi\API\Values\Field */ -abstract class Fields implements IteratorAggregate, ArrayAccess, Countable +abstract class Fields implements IteratorAggregate, ArrayAccess, Countable, DebugInfo { /** * Return whether the collection contains a field with the given $identifier. diff --git a/lib/API/Values/Location.php b/lib/API/Values/Location.php index 091886e2..c422ec45 100644 --- a/lib/API/Values/Location.php +++ b/lib/API/Values/Location.php @@ -36,7 +36,7 @@ * @property-read ?\Netgen\IbexaSiteApi\API\Values\Location $parent * @property-read \Ibexa\Contracts\Core\Repository\Values\Content\Location $innerLocation */ -abstract class Location extends ValueObject +abstract class Location extends ValueObject implements DebugInfo { /** * Return an array of children Locations, limited by optional $limit. diff --git a/lib/Core/Site/Values/Content.php b/lib/Core/Site/Values/Content.php index d01a298a..1fd3ba85 100644 --- a/lib/Core/Site/Values/Content.php +++ b/lib/Core/Site/Values/Content.php @@ -498,4 +498,23 @@ private function internalGetUrl(): Url return $this->url; } + + public function getDebugInfo(): array + { + return [ + 'id' => $this->id, + 'mainLocationId' => $this->mainLocationId, + 'name' => $this->name, + 'languageCode' => $this->languageCode, + 'isVisible' => $this->getContentInfo()->isVisible, + 'url' => $this->getUrl(), + 'path' => $this->getPath(), + 'owner' => $this->getOwner(), + 'modifier' => $this->getModifier(), + 'mainLocation' => $this->getMainLocation(), + 'locations' => $this->getLocations(), + 'contentInfo' => $this->getContentInfo(), + 'fields' => $this->fields, + ]; + } } diff --git a/lib/Core/Site/Values/ContentInfo.php b/lib/Core/Site/Values/ContentInfo.php index 4a5e68ef..ab1a027f 100644 --- a/lib/Core/Site/Values/ContentInfo.php +++ b/lib/Core/Site/Values/ContentInfo.php @@ -90,4 +90,27 @@ private function getMainLocation(): ?APILocation return $this->internalMainLocation; } + + public function getDebugInfo(): array + { + return [ + 'id' => $this->innerContentInfo->id, + 'mainLocationId' => $this->innerContentInfo->mainLocationId, + 'remoteId' => $this->innerContentInfo->remoteId, + 'name' => $this->name, + 'published' => $this->innerContentInfo->published, + 'currentVersionNo' => $this->innerContentInfo->currentVersionNo, + 'publishedDate' => $this->innerContentInfo->publishedDate, + 'modificationDate' => $this->innerContentInfo->modificationDate, + 'languageCode' => $this->languageCode, + 'mainLanguageCode' => $this->innerContentInfo->mainLanguageCode, + 'alwaysAvailable' => $this->innerContentInfo->alwaysAvailable, + 'isVisible' => !$this->innerContentInfo->isHidden, + 'isHidden' => $this->innerContentInfo->isHidden, + 'sectionId' => $this->innerContentInfo->sectionId, + 'ownerId' => $this->innerContentInfo->ownerId, + 'innerContentType' => $this->innerContentType, + 'mainLocation' => $this->getMainLocation(), + ]; + } } diff --git a/lib/Core/Site/Values/Field.php b/lib/Core/Site/Values/Field.php index 308e6386..3de986fe 100644 --- a/lib/Core/Site/Values/Field.php +++ b/lib/Core/Site/Values/Field.php @@ -44,4 +44,22 @@ public function isSurrogate(): bool { return $this->isSurrogate; } + + public function getDebugInfo(): array + { + return [ + 'id' => $this->id, + 'contentId' => $this->content->id, + 'fieldDefIdentifier' => $this->fieldDefIdentifier, + 'fieldTypeIdentifier' => $this->fieldTypeIdentifier, + 'languageCode' => $this->languageCode, + 'name' => $this->name, + 'description' => $this->description, + 'isEmpty' => $this->isEmpty, + 'isSurrogate' => $this->isSurrogate, + 'content' => $this->content, + 'innerFieldDefinition' => $this->innerFieldDefinition, + 'value' => $this->value, + ]; + } } diff --git a/lib/Core/Site/Values/Fields.php b/lib/Core/Site/Values/Fields.php index 1008bf4b..6fe4d3b7 100644 --- a/lib/Core/Site/Values/Fields.php +++ b/lib/Core/Site/Values/Fields.php @@ -245,4 +245,11 @@ private function getSurrogateField(string $identifier, SiteContent $content): Fi 'isSurrogate' => true, ]); } + + public function getDebugInfo(): array + { + $this->initialize(); + + return $this->fieldsByIdentifier; + } } diff --git a/lib/Core/Site/Values/Location.php b/lib/Core/Site/Values/Location.php index 77160eca..02023af4 100644 --- a/lib/Core/Site/Values/Location.php +++ b/lib/Core/Site/Values/Location.php @@ -312,4 +312,29 @@ private function internalGetUrl(): Url return $this->url; } + + public function getDebugInfo(): array + { + return [ + 'id' => $this->innerLocation->id, + 'contentId' => $this->innerLocation->contentId, + 'remoteId' => $this->innerLocation->remoteId, + 'status' => $this->innerLocation->status, + 'priority' => $this->innerLocation->priority, + 'hidden' => $this->innerLocation->hidden, + 'invisible' => $this->innerLocation->invisible, + 'explicitlyHidden' => $this->innerLocation->explicitlyHidden, + 'isVisible' => !$this->innerLocation->hidden && !$this->innerLocation->invisible, + 'pathString' => $this->innerLocation->pathString, + 'pathArray' => $this->innerLocation->path, + 'depth' => $this->innerLocation->depth, + 'sortField' => $this->innerLocation->sortField, + 'sortOrder' => $this->innerLocation->sortOrder, + 'path' => $this->getPath(), + 'url' => $this->getUrl(), + 'content' => $this->getContent(), + 'contentInfo' => $this->getContentInfo(), + 'parent' => $this->getParent(), + ]; + } }