class StaticMethodLoader

Hierarchy

Expanded class hierarchy of StaticMethodLoader

2 files declare their use of StaticMethodLoader
StaticMethodLoaderTest.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Mapping/Loader/StaticMethodLoaderTest.php
ValidatorBuilder.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/ValidatorBuilder.php

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php, line 17

Namespace

Symfony\Component\Validator\Mapping\Loader
View source
class StaticMethodLoader implements LoaderInterface {
  protected $methodName;
  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
        ->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