This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Validator/Mapping/GetterMetadata.php
Fabien Potencier df3d543349 Merge branch '2.4'
* 2.4:
  made types consistent with those defined in Hack
  made {@inheritdoc} annotations consistent across the board
  made {@inheritdoc} annotations consistent across the board
  fixed types in phpdocs
  [Debug] Fixed ClassNotFoundFatalErrorHandler on windows.
  made phpdoc types consistent with those defined in Hack
  Add support Thai translations
  [Validator] Add missing czech translations
  made types consistent with those defined in Hack
  removed extra/unsupported arguments
  [HttpKernel] fixed an error message
  [TwigBundle] removed undefined argument
  [Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM.

Conflicts:
	src/Symfony/Component/Console/Helper/TableHelper.php
	src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
	src/Symfony/Component/Form/FormError.php
	src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php
	src/Symfony/Component/Process/ProcessPipes.php
	src/Symfony/Component/PropertyAccess/PropertyAccessor.php
	src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php
	src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php
	src/Symfony/Component/Translation/Dumper/FileDumper.php
	src/Symfony/Component/Validator/ConstraintViolation.php
	src/Symfony/Component/Validator/Constraints/EmailValidator.php
	src/Symfony/Component/Validator/ExecutionContextInterface.php
	src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php
2014-04-16 10:08:40 +02:00

78 lines
2.1 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Mapping;
use Symfony\Component\Validator\Exception\ValidatorException;
/**
* Stores all metadata needed for validating a class property via its getter
* method.
*
* A property getter is any method that is equal to the property's name,
* prefixed with either "get" or "is". That method will be used to access the
* property's value.
*
* The getter will be invoked by reflection, so the access of private and
* protected getters is supported.
*
* This class supports serialization and cloning.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see PropertyMetadataInterface
*/
class GetterMetadata extends MemberMetadata
{
/**
* Constructor.
*
* @param string $class The class the getter is defined on
* @param string $property The property which the getter returns
*
* @throws ValidatorException
*/
public function __construct($class, $property)
{
$getMethod = 'get'.ucfirst($property);
$isMethod = 'is'.ucfirst($property);
$hasMethod = 'has'.ucfirst($property);
if (method_exists($class, $getMethod)) {
$method = $getMethod;
} elseif (method_exists($class, $isMethod)) {
$method = $isMethod;
} elseif (method_exists($class, $hasMethod)) {
$method = $hasMethod;
} else {
throw new ValidatorException(sprintf('Neither of these methods exist in class %s: %s, %s, %s', $class, $getMethod, $isMethod, $hasMethod));
}
parent::__construct($class, $method, $property);
}
/**
* {@inheritdoc}
*/
public function getPropertyValue($object)
{
return $this->newReflectionMember($object)->invoke($object);
}
/**
* {@inheritdoc}
*/
protected function newReflectionMember($objectOrClassName)
{
return new \ReflectionMethod($objectOrClassName, $this->getName());
}
}