vendor/jackalope/jackalope/src/Jackalope/Factory.php line 62

Open in your IDE?
  1. <?php
  2. namespace Jackalope;
  3. use InvalidArgumentException;
  4. use ReflectionClass;
  5. /**
  6.  * Jackalope implementation factory.
  7.  *
  8.  * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
  9.  * @license http://opensource.org/licenses/MIT MIT License
  10.  */
  11. class Factory implements FactoryInterface
  12. {
  13.     /**
  14.      * @var array
  15.      */
  16.     protected $classCache = [];
  17.     
  18.     /**
  19.      * @var array
  20.      */
  21.     protected $reflectionCache = [];
  22.     /**
  23.      * {@inheritDoc}
  24.      *
  25.      * @throws InvalidArgumentException
  26.      */
  27.     public function get($name, array $params = [])
  28.     {
  29.         if (isset($this->classCache[$name])) {
  30.             $name $this->classCache[$name];
  31.         } else {
  32.             $originalName $name;
  33.             if (class_exists('Jackalope\\' $name)) {
  34.                 $name 'Jackalope\\' $name;
  35.             } elseif (! class_exists($name)) {
  36.                 throw new InvalidArgumentException("Neither class Jackalope\\$name nor class $name found. Please check your autoloader and the spelling of $name");
  37.             }
  38.             
  39.             $this->classCache[$originalName] = $name;
  40.         }
  41.         if (=== strpos($name'Jackalope\\')) {
  42.             array_unshift($params$this);
  43.         }
  44.         if (! count($params)) {
  45.             return new $name;
  46.         }
  47.         if (isset($this->reflectionCache[$name])) {
  48.             $class $this->reflectionCache[$name];
  49.         } else {
  50.             $class = new ReflectionClass($name);
  51.             $this->reflectionCache[$name] = $class;
  52.         }
  53.         return $class->newInstanceArgs($params);
  54.     }
  55. }