vendor/pimcore/pimcore/lib/Loader/ImplementationLoader/AbstractClassNameLoader.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types 1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Loader\ImplementationLoader;
  16. use Pimcore\Loader\ImplementationLoader\Exception\UnsupportedException;
  17. /**
  18.  * @internal
  19.  */
  20. abstract class AbstractClassNameLoader implements LoaderInterfaceClassNameLoaderInterface
  21. {
  22.     /**
  23.      * @param string $name
  24.      *
  25.      * @return string
  26.      */
  27.     abstract protected function getClassName(string $name);
  28.     /**
  29.      * {@inheritdoc}
  30.      */
  31.     public function build(string $name, array $params = [])
  32.     {
  33.         if (!$this->supports($name)) {
  34.             throw new UnsupportedException(sprintf('"%s" is not supported'$name));
  35.         }
  36.         $params array_values($params);
  37.         $className $this->getClassName($name);
  38.         $instance = new $className(...$params);
  39.         return $instance;
  40.     }
  41.     /**
  42.      * {@inheritdoc}
  43.      */
  44.     public function supportsClassName(string $name): bool
  45.     {
  46.         return $this->supports($name);
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function getClassNameFor(string $name): string
  52.     {
  53.         if (!$this->supports($name)) {
  54.             throw new UnsupportedException(sprintf('"%s" is not supported'$name));
  55.         }
  56.         return $this->getClassName($name);
  57.     }
  58. }