Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / validator / Mapping / Loader / StaticMethodLoader.php
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\Loader;
13
14 use Symfony\Component\Validator\Exception\MappingException;
15 use Symfony\Component\Validator\Mapping\ClassMetadata;
16
17 /**
18  * Loads validation metadata by calling a static method on the loaded class.
19  *
20  * @author Bernhard Schussek <bschussek@gmail.com>
21  */
22 class StaticMethodLoader implements LoaderInterface
23 {
24     /**
25      * The name of the method to call.
26      *
27      * @var string
28      */
29     protected $methodName;
30
31     /**
32      * Creates a new loader.
33      *
34      * @param string $methodName The name of the static method to call
35      */
36     public function __construct($methodName = 'loadValidatorMetadata')
37     {
38         $this->methodName = $methodName;
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     public function loadClassMetadata(ClassMetadata $metadata)
45     {
46         /** @var \ReflectionClass $reflClass */
47         $reflClass = $metadata->getReflectionClass();
48
49         if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
50             $reflMethod = $reflClass->getMethod($this->methodName);
51
52             if ($reflMethod->isAbstract()) {
53                 return false;
54             }
55
56             if (!$reflMethod->isStatic()) {
57                 throw new MappingException(sprintf('The method %s::%s should be static', $reflClass->name, $this->methodName));
58             }
59
60             if ($reflMethod->getDeclaringClass()->name != $reflClass->name) {
61                 return false;
62             }
63
64             $reflMethod->invoke(null, $metadata);
65
66             return true;
67         }
68
69         return false;
70     }
71 }