10000 Recursive denormalize with property info by mihai-stancu · Pull Request #17193 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Recursive denormalize with property info #17193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Next Next commit
[Serializer] Add a MaxDepth option
  • Loading branch information
dunglas committed Dec 22, 2015
commit 3a32b03f27c77efbaba830f85f4ce282956e06f2
48 changes: 48 additions & 0 deletions src/Symfony/Component/Serializer/Annotation/MaxDepth.php
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Serializer\Annotation;

use Symfony\Component\Serializer\Exception\InvalidArgumentException;

/**
* Annotation class for @MaxDepth().
*
* @Annotation
* @Target({"PROPERTY", "METHOD"})
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class MaxDepth
{
/**
* @var int
*/
private $maxDepth;

public function __construct(array $data)
{
if (!isset($data['value']) || !$data['value']) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', get_class($this)));
}

if (!is_int($data['value'])) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an int.', get_class($this)));
}

$this->maxDepth = $data['value'];
}

public function getMaxDepth()
{
return $this->maxDepth;
}
}
32 changes: 31 additions & 1 deletion src/Symfony/Component/Serializer/Mapping/AttributeMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class AttributeMetadata implements AttributeMetadataInterface
*/
public $groups = array();

/**
* @var int|null
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getMaxDepth()} instead.
*/
public $maxDepth;

/**
* Constructs a metadata for the given attribute.
*
Expand Down Expand Up @@ -72,6 +81,22 @@ public function getGroups()
return $this->groups;
}

/**
* {@inheritdoc}
*/
public function setMaxDepth($maxDepth)
{
$this->maxDepth = $maxDepth;
}

/**
* {@inheritdoc}
*/
public function getMaxDepth()
{
return $this->maxDepth;
}

/**
* {@inheritdoc}
*/
Expand All @@ -80,6 +105,11 @@ public function merge(AttributeMetadataInterface $attributeMetadata)
foreach ($attributeMetadata->getGroups() as $group) {
$this->addGroup($group);
}

// Overwrite only if not defined
if (null === $this->maxDepth) {
$this->maxDepth = $attributeMetadata->getMaxDepth();
}
}

/**
Expand All @@ -89,6 +119,6 @@ public function merge(AttributeMetadataInterface $attributeMetadata)
*/
public function __sleep()
{
return array('name', 'groups');
return array('name', 'groups', 'maxDepth');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ public function addGroup($group);
*/
public function getGroups();

/**
* Sets the serialization max depth for this attribute.
*
* @param int|null $maxDepth
*/
public function setMaxDepth($maxDepth);

/**
* Gets the serialization max depth for this attribute.
*
* @return int|null
*/
public function getMaxDepth();

/**
* Merges an {@see AttributeMetadataInterface} with in the current one.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/Mapping/ClassMetadata.php