class StaticMethodLoader
Loads validation metadata by calling a static method on the loaded class.
@author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader implements \Symfony\Component\Validator\Mapping\Loader\LoaderInterface
Expanded class hierarchy of StaticMethodLoader
1 file declares its use of StaticMethodLoader
- ValidatorBuilder.php in vendor/
symfony/ validator/ ValidatorBuilder.php
File
-
vendor/
symfony/ validator/ Mapping/ Loader/ StaticMethodLoader.php, line 22
Namespace
Symfony\Component\Validator\Mapping\LoaderView source
class StaticMethodLoader implements LoaderInterface {
/**
* Creates a new loader.
*
* @param string $methodName The name of the static method to call
*/
public function __construct(string $methodName = 'loadValidatorMetadata') {
}
public function loadClassMetadata(ClassMetadata $metadata) : bool {
/** @var \ReflectionClass $reflClass */
$reflClass = $metadata->getReflectionClass();
if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
$reflMethod = $reflClass->getMethod($this->methodName);
if ($reflMethod->isAbstract()) {
return false;
}
if (!$reflMethod->isStatic()) {
throw new MappingException(\sprintf('The method "%s::%s()" should be static.', $reflClass->name, $this->methodName));
}
if ($reflMethod->getDeclaringClass()->name != $reflClass->name) {
return false;
}
$reflMethod->invoke(null, $metadata);
return true;
}
return false;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
StaticMethodLoader::loadClassMetadata | public | function | Loads validation metadata into a {@link ClassMetadata} instance. | Overrides LoaderInterface::loadClassMetadata |
StaticMethodLoader::__construct | public | function | Creates a new loader. |