equal
deleted
inserted
replaced
|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony package. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.com> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace Symfony\Component\Validator\Mapping; |
|
13 |
|
14 use Symfony\Component\Validator\Exception\ValidatorException; |
|
15 |
|
16 class PropertyMetadata extends MemberMetadata |
|
17 { |
|
18 /** |
|
19 * Constructor. |
|
20 * |
|
21 * @param string $class The class this property is defined on |
|
22 * @param string $name The name of this property |
|
23 */ |
|
24 public function __construct($class, $name) |
|
25 { |
|
26 if (!property_exists($class, $name)) { |
|
27 throw new ValidatorException(sprintf('Property %s does not exists in class %s', $name, $class)); |
|
28 } |
|
29 |
|
30 parent::__construct($class, $name, $name); |
|
31 } |
|
32 |
|
33 /** |
|
34 * {@inheritDoc} |
|
35 */ |
|
36 public function getValue($object) |
|
37 { |
|
38 return $this->getReflectionMember()->getValue($object); |
|
39 } |
|
40 |
|
41 /** |
|
42 * {@inheritDoc} |
|
43 */ |
|
44 protected function newReflectionMember() |
|
45 { |
|
46 $member = new \ReflectionProperty($this->getClassName(), $this->getName()); |
|
47 $member->setAccessible(true); |
|
48 |
|
49 return $member; |
|
50 } |
|
51 } |