CoreFiles by mySites.guru
StaticMethodLoader.php63 lines, 1,740 bytes, from Joomla_6.0.0-alpha1-Alpha-Full_Package.zip
Raw History Compare with 5.4.0-alpha3
md5
d3274056e077b94d69abd42b4dea3157
sha1
909ff345091d10dedc5edcaebd0caf92b349e913
sha256
9c2c62dae60d4e46b6d977ef310b84ce81bfb00c987c0cb9da26813d6cab469e
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Validator\Mapping\Loader;

use Symfony\Component\Validator\Exception\MappingException;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
 * Loads validation metadata by calling a static method on the loaded class.
 *
 * @author Bernhard Schussek <[email protected]>
 */
class StaticMethodLoader implements LoaderInterface
{
    protected $methodName;

    /**
     * Creates a new loader.
     *
     * @param string $methodName The name of the static method to call
     */
    public function __construct(string $methodName = 'loadValidatorMetadata')
    {
        $this->methodName = $methodName;
    }

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

The same content is in 63 releases, Joomla 5.1.0-beta1 to 6.0.0-alpha3. See them all, or every version of this file.