/protected/extensions/doctrine/vendors/Symfony/Component/Validator/Mapping/GetterMetadata.php

https://bitbucket.org/NordLabs/yiidoctrine · PHP · 55 lines · 27 code · 8 blank · 20 comment · 2 complexity · ce388335f4e57e72de617746f3626368 MD5 · raw file

  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\Validator\Mapping;
  11. use Symfony\Component\Validator\Exception\ValidatorException;
  12. class GetterMetadata extends MemberMetadata
  13. {
  14. /**
  15. * Constructor.
  16. *
  17. * @param string $class The class the getter is defined on
  18. * @param string $property The property which the getter returns
  19. */
  20. public function __construct($class, $property)
  21. {
  22. $getMethod = 'get'.ucfirst($property);
  23. $isMethod = 'is'.ucfirst($property);
  24. if (method_exists($class, $getMethod)) {
  25. $method = $getMethod;
  26. } elseif (method_exists($class, $isMethod)) {
  27. $method = $isMethod;
  28. } else {
  29. throw new ValidatorException(sprintf('Neither method %s nor %s exists in class %s', $getMethod, $isMethod, $class));
  30. }
  31. parent::__construct($class, $method, $property);
  32. }
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public function getValue($object)
  37. {
  38. return $this->getReflectionMember()->invoke($object);
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. protected function newReflectionMember()
  44. {
  45. return new \ReflectionMethod($this->getClassName(), $this->getName());
  46. }
  47. }