AccessType.php 885 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace JMS\SerializerBundle\Annotation;
  3. /**
  4. * @Annotation
  5. * @Target({"CLASS", "PROPERTY"})
  6. *
  7. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  8. */
  9. final class AccessType
  10. {
  11. /**
  12. * @Required
  13. * @var string
  14. */
  15. public $type;
  16. public function __construct()
  17. {
  18. if (0 === func_num_args()) {
  19. return;
  20. }
  21. $values = func_get_arg(0);
  22. if (isset($values['value'])) {
  23. $values['type'] = $values['value'];
  24. }
  25. if (!isset($values['type'])) {
  26. throw new \InvalidArgumentException(sprintf('@AccessType requires the AccessType.'));
  27. }
  28. if (!is_string($values['type'])) {
  29. throw new \InvalidArgumentException(sprintf('@AccessType expects a string type, but got %s.', json_encode($values['type'])));
  30. }
  31. $this->type = $values['type'];
  32. }
  33. }