for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Ivory Serializer package.
*
* (c) Eric GELOEN <[email protected]>
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/
namespace Ivory\Serializer\Exclusion;
use Ivory\Serializer\Context\ContextInterface;
use Ivory\Serializer\Mapping\ClassMetadataInterface;
use Ivory\Serializer\Mapping\PropertyMetadataInterface;
use Ivory\Serializer\Mapping\TypeMetadataInterface;
/**
* @author GeLo <[email protected]>
class MaxDepthExclusionStrategy extends ExclusionStrategy
{
* {@inheritdoc}
public function skipClass(ClassMetadataInterface $class, ContextInterface $context)
return $this->skip($context);
}
public function skipType(TypeMetadataInterface $type, ContextInterface $context)
* @param ContextInterface $context
* @return bool
private function skip(ContextInterface $context)
$metadataStack = $context->getMetadataStack();
$stackDepth = count($context->getDataStack());
$depth = 0;
for ($i = $metadataStack->count() - 1; $i > 0; --$i) {
$metadata = $metadataStack[$i];
if ($metadata instanceof TypeMetadataInterface) {
++$depth;
if (!$metadata instanceof PropertyMetadataInterface) {
continue;
if (!$metadata->hasMaxDepth()) {
if ($stackDepth - $depth > $metadata->getMaxDepth()) {
return true;
return false;