You are here

public function StaticMethodLoader::loadClassMetadata in Plug 7

Loads validation metadata into a {@link ClassMetadata} instance.

Parameters

ClassMetadata $metadata The metadata to load:

Return value

bool Whether the loader succeeded

Overrides LoaderInterface::loadClassMetadata

File

lib/Symfony/validator/Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php, line 44

Class

StaticMethodLoader
Loads validation metadata by calling a static method on the loaded class.

Namespace

Symfony\Component\Validator\Mapping\Loader

Code

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;
}