2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Component\Validator\Mapping;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-10-02 11:42:31 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony framework.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
class PropertyMetadata extends MemberMetadata
|
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param string $class The class this property is defined on
|
|
|
|
* @param string $name The name of this property
|
|
|
|
*/
|
|
|
|
public function __construct($class, $name)
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
if (!property_exists($class, $name)) {
|
|
|
|
throw new ValidatorException(sprintf('Property %s does not exists in class %s', $name, $class));
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
parent::__construct($class, $name, $name);
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getValue($object)
|
|
|
|
{
|
|
|
|
return $this->getReflectionMember()->getValue($object);
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected function newReflectionMember()
|
|
|
|
{
|
|
|
|
$member = new \ReflectionProperty($this->getClassName(), $this->getName());
|
|
|
|
$member->setAccessible(true);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
return $member;
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|