MaxDepth.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Annotation;
  11. use Symfony\Component\Serializer\Exception\InvalidArgumentException;
  12. /**
  13. * Annotation class for @MaxDepth().
  14. *
  15. * @Annotation
  16. * @Target({"PROPERTY", "METHOD"})
  17. *
  18. * @author Kévin Dunglas <dunglas@gmail.com>
  19. */
  20. class MaxDepth
  21. {
  22. /**
  23. * @var int
  24. */
  25. private $maxDepth;
  26. public function __construct(array $data)
  27. {
  28. if (!isset($data['value'])) {
  29. throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', get_class($this)));
  30. }
  31. if (!is_int($data['value']) || $data['value'] <= 0) {
  32. throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a positive integer.', get_class($this)));
  33. }
  34. $this->maxDepth = $data['value'];
  35. }
  36. public function getMaxDepth()
  37. {
  38. return $this->maxDepth;
  39. }
  40. }