Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StaticMethodLoader.php

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\Loader
View 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.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal