Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Serializer\Mapping; Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: * Chris@0: * @author Kévin Dunglas Chris@0: */ Chris@0: class AttributeMetadata implements AttributeMetadataInterface Chris@0: { Chris@0: /** Chris@0: * @internal This property is public in order to reduce the size of the Chris@0: * class' serialized representation. Do not access it. Use Chris@0: * {@link getName()} instead. Chris@0: */ Chris@0: public $name; Chris@0: Chris@0: /** Chris@0: * @internal This property is public in order to reduce the size of the Chris@0: * class' serialized representation. Do not access it. Use Chris@0: * {@link getGroups()} instead. Chris@0: */ Chris@17: public $groups = []; Chris@0: Chris@0: /** Chris@0: * @var int|null Chris@0: * Chris@0: * @internal This property is public in order to reduce the size of the Chris@0: * class' serialized representation. Do not access it. Use Chris@0: * {@link getMaxDepth()} instead. Chris@0: */ Chris@0: public $maxDepth; Chris@0: Chris@0: /** Chris@0: * Constructs a metadata for the given attribute. Chris@0: * Chris@0: * @param string $name Chris@0: */ Chris@0: public function __construct($name) Chris@0: { Chris@0: $this->name = $name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return $this->name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function addGroup($group) Chris@0: { Chris@14: if (!\in_array($group, $this->groups)) { Chris@0: $this->groups[] = $group; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getGroups() Chris@0: { Chris@0: return $this->groups; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setMaxDepth($maxDepth) Chris@0: { Chris@0: $this->maxDepth = $maxDepth; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getMaxDepth() Chris@0: { Chris@0: return $this->maxDepth; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function merge(AttributeMetadataInterface $attributeMetadata) Chris@0: { Chris@0: foreach ($attributeMetadata->getGroups() as $group) { Chris@0: $this->addGroup($group); Chris@0: } Chris@0: Chris@0: // Overwrite only if not defined Chris@0: if (null === $this->maxDepth) { Chris@0: $this->maxDepth = $attributeMetadata->getMaxDepth(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the names of the properties that should be serialized. Chris@0: * Chris@0: * @return string[] Chris@0: */ Chris@0: public function __sleep() Chris@0: { Chris@17: return ['name', 'groups', 'maxDepth']; Chris@0: } Chris@0: }