PageRenderTime 303ms CodeModel.GetById 242ms app.highlight 2ms RepoModel.GetById 58ms app.codeStats 0ms

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