Accessor.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace JMS\SerializerBundle\Annotation;
  3. /**
  4. * @Annotation
  5. * @Target("PROPERTY")
  6. *
  7. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  8. */
  9. final class Accessor
  10. {
  11. /**
  12. * @var string
  13. */
  14. public $getter;
  15. /**
  16. * @var string
  17. */
  18. public $setter;
  19. public function __construct()
  20. {
  21. if (0 === func_num_args()) {
  22. return;
  23. }
  24. $values = func_get_arg(0);
  25. if (isset($values['value'])) {
  26. $values['getter'] = $values['value'];
  27. }
  28. if (isset($values['getter'])) {
  29. if (!is_string($values['getter'])) {
  30. throw new \InvalidArgumentException(sprintf('"getter" attribute of annotation @Accessor must be a string, but got %s.', json_encode($values['getter'])));
  31. }
  32. $this->getter = $values['getter'];
  33. }
  34. if (isset($values['setter'])) {
  35. if (!is_string($values['setter'])) {
  36. throw new \InvalidArgumentException(sprintf('"setter" attribute of annotation @Accessor must be a string, but got %s.', json_encode($values['setter'])));
  37. }
  38. $this->setter = $values['setter'];
  39. }
  40. }
  41. }