2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2010-10-02 11:42:31 +01:00
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-10-02 11:42:31 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-10-02 11:42:31 +01:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-10-02 11:42:31 +01:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Validator\Mapping;
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
class GetterMetadata extends MemberMetadata
|
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
2010-10-15 22:49:09 +01:00
|
|
|
* @param string $class The class the getter is defined on
|
|
|
|
* @param string $property The property which the getter returns
|
2010-06-24 10:24:08 +01:00
|
|
|
*/
|
|
|
|
public function __construct($class, $property)
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
$getMethod = 'get'.ucfirst($property);
|
|
|
|
$isMethod = 'is'.ucfirst($property);
|
|
|
|
|
|
|
|
if (method_exists($class, $getMethod)) {
|
|
|
|
$method = $getMethod;
|
2011-12-18 13:42:59 +00:00
|
|
|
} elseif (method_exists($class, $isMethod)) {
|
2010-06-24 10:24:08 +01:00
|
|
|
$method = $isMethod;
|
|
|
|
} else {
|
|
|
|
throw new ValidatorException(sprintf('Neither method %s nor %s exists in class %s', $getMethod, $isMethod, $class));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($class, $method, $property);
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|
2010-06-24 10:24:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2012-11-22 14:58:46 +00:00
|
|
|
public function getPropertyValue($object)
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
return $this->getReflectionMember()->invoke($object);
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|
2010-06-24 10:24:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected function newReflectionMember()
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
return new \ReflectionMethod($this->getClassName(), $this->getName());
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|
2011-06-08 11:16:48 +01:00
|
|
|
}
|