Created
November 20, 2012 21:36
-
-
Save baldurrensch/4121342 to your computer and use it in GitHub Desktop.
JMS Serializer Exclusion Strategy to limit level of serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Hautelook\ApiBundle\Serializer\Handler; | |
use JMS\SerializerBundle\Serializer\Exclusion\ExclusionStrategyInterface; | |
use JMS\SerializerBundle\Metadata\ClassMetadata; | |
use JMS\SerializerBundle\Metadata\PropertyMetadata; | |
class HautelookDoctrineExclusionStrategy implements ExclusionStrategyInterface | |
{ | |
static private $level = 0; | |
/** | |
* Whether the class should be skipped. | |
* | |
* @param ClassMetadata $metadata | |
* @param object $object instance, provided during serialization but not deserialization | |
* | |
* @return boolean | |
*/ | |
function shouldSkipClass(ClassMetadata $metadata, $object = null) | |
{ | |
self::$level++; | |
return self::$level > 1; | |
} | |
/** | |
* Whether the property should be skipped. | |
* | |
* @param PropertyMetadata $property | |
* @param object $object instance, provided during serialization but not deserialization | |
* | |
* @return boolean | |
*/ | |
function shouldSkipProperty(PropertyMetadata $property, $object = null) | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment