class StaticMethodLoader in Plug 7
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 LoaderInterface
Expanded class hierarchy of StaticMethodLoader
2 files declare their use of StaticMethodLoader
- StaticMethodLoaderTest.php in lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Mapping/ Loader/ StaticMethodLoaderTest.php - ValidatorBuilder.php in lib/
Symfony/ validator/ Symfony/ Component/ Validator/ ValidatorBuilder.php
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Mapping/ Loader/ StaticMethodLoader.php, line 22
Namespace
Symfony\Component\Validator\Mapping\LoaderView source
class StaticMethodLoader implements LoaderInterface {
/**
* The name of the method to call.
*
* @var string
*/
protected $methodName;
/**
* Creates a new loader.
*
* @param string $methodName The name of the static method to call
*/
public function __construct($methodName = 'loadValidatorMetadata') {
$this->methodName = $methodName;
}
/**
* {@inheritdoc}
*/
public function loadClassMetadata(ClassMetadata $metadata) {
/** @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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StaticMethodLoader:: |
protected | property | The name of the method to call. | |
StaticMethodLoader:: |
public | function |
Loads validation metadata into a {@link ClassMetadata} instance. Overrides LoaderInterface:: |
|
StaticMethodLoader:: |
public | function | Creates a new loader. |