You are here

public function StaticMethodLoader::loadClassMetadata in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Mapping/Loader/StaticMethodLoader.php \Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader::loadClassMetadata()

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

vendor/symfony/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;
}