Retrieves and caches the constructor (ReflectionMethod) for the specified class.

@since 0.3.0

@param string $class Class name to retrieve the constructor from.

@return ReflectionMethod ReflectionMethod for the constructor of the specified class.
777376
public function getConstructor($class)
    {
        $cacheKey = self::CACHE_KEY_CTORS . strtolower($class);

        $reflectedConstructor = $this->cache->fetch($cacheKey);

        if ($reflectedConstructor === false) {
            $reflectionClass      = $this->getClass($class);
            $reflectedConstructor = $reflectionClass->getConstructor();
            $this->cache->store($cacheKey, $reflectedConstructor);
        }

        return $reflectedConstructor;
    }
194663
public function createCache($class, $args)
    {
        /** @var CacheInterface $cache */
        $reflection = new ReflectionClass($class);
        $cache = $reflection->newInstanceArgs($args);

        // Assign cache logger
        if ($this->logger && $cache instanceof LoggerAwareInterface) {
            $cache->setLogger($this->logger);
        }

        return $cache;
    }
240548
private static function initPropertyCache($class) {
        $loops = $class instanceof Object ? $class->getLoops() : Loops::getCurrentLoops();
        $classname = get_class($class);
        $key = "Loops-Misc-AccessTrait-$classname";

        static $cache;

        if(!$cache) {
            $cache = new ChainCache([new ArrayCache, $loops->getService("cache")]);
        }

        if($cache->contains($key)) {
            return $cache->fetch($key);
        }

        $annotations = $loops->getService("annotations");

        // build
        $result["getter"]    = [];
        $result["setter"]    = [];
        $result["exposed"]   = [];
        $result["protected"] = [];
        $result["sleep"]     = [];

        $ro = $annotations->get($classname)->properties->findFirst("Access\ReadOnly");
        $rw = $annotations->get($classname)->properties->findFirst("Access\ReadWrite");

        //make getter
        foreach(array_merge($ro, $rw) as $name => $annotation) {
            if($annotation->getter && !method_exists($class, $annotation->getter)) {
                throw new Exception("Passed getter '{$annotation->getter}' is not a method of class '$classname'.");
            }
            $result["getter"][$name] = $annotation->getter ? [ $annotation->getter, $annotation->arguments ] : $name;
        }

        //make setter
        foreach($rw as $name => $annotation) {
            if($annotation->setter && !method_exists($class, $annotation->setter)) {
                throw new Exception("Passed getter '{$annotation->setter}' is not a method of class '$classname'.");
            }
            $result["setter"][$name] = $annotation->setter ? [ $annotation->setter ] : $name;
        }

        //expose public properties
        foreach((new ReflectionClass($classname))->getProperties() as $property) {
            if($property->isStatic()) {
                continue;
            }

            if($property->isPublic()) {
                $name = $property->getName();
                $result["getter"][$name]  = $name;
                $result["setter"][$name]  = $name;
                $result["exposed"][$name] = $name;
            }

            if($property->isProtected()) {
                $name = $property->getName();
                $result["protected"][$name] = $name;
            }
        }

        //expose properties that have the Exposed annotation - prefer getter of property if exists
        foreach($annotations->get($classname)->properties->findLast("Access\Expose") as $name => $annotation) {
            $result["exposed"][$annotation->name ?: $name] = array_key_exists($name, $result["getter"]) ? $result["getter"][$name] : $name;
        }

        //expose methods that have the Exposed annotation
        foreach($annotations->get($classname)->methods->findLast("Access\Expose") as $name => $annotation) {
            $result["exposed"][$annotation->name ?: $name] = [ $name, $annotation->arguments ];
        }

        //check, which keys must be imported when sleeping
        $current = $classname;
        do {
            $set = $annotations->getStrict($current);

            $properties = array_keys(iterator_to_array($set->properties));

            $properties = array_filter($properties, function($name) use ($current) {
                $property = new ReflectionProperty($current, $name);
                if($property->isStatic()) return FALSE;
                if($property->isPrivate()) return FALSE;
                return TRUE;
            });

            foreach($set->find("Access\Sleep") as $sleep) {
                if($sleep->forbid) {
                    $result["sleep"] = FALSE;
                    break 2;
                }

                if($sleep->include) {
                    $properties = array_intersect($properties, $sleep->include);
                }

                if($sleep->exclude) {
                    $properties = array_diff($properties, $sleep->exclude);
                }
            }

            $result["sleep"] = array_merge($result["sleep"], $properties);
        } while($current = get_parent_class($current));

        $cache->save($key, $result);

        return $result;
    }
702602
private function getEntityAnnotation(\ReflectionClass $class)
    {
        if (!$this->annotationReader) {
            $this->annotationReader = new AnnotationReader();
        }

        return $this->annotationReader->getClassAnnotation($class, new Entity());
    }
752
protected function _getConfig($class)
    {
        $rClass = new \ReflectionClass($class);

        // Delegate actually loading the config for the class to the ClassAnnotationDriver
        $classDriver = new ClassAnnotationDriver($rClass, $this->annotationReaderFactory, $this->annotationNamespace);

        return $classDriver->getConfig();

    }
69753
public function get(string $class)
    {
        if (isset($this->instantiated[$class]) && $this->shared[$class]) {
            return $this->instantiated[$class];
        }

        $args = $this->services[$class];

        switch (count($args)) {
            case 0:
                $object = new $class();
                break;
            case 1:
                $object = new $class($args[0]);
                break;
            case 2:
                $object = new $class($args[0], $args[1]);
                break;
            case 3:
                $object = new $class($args[0], $args[1], $args[2]);
                break;
            default:
                throw new \OutOfRangeException('Too many arguments given');
        }

        if ($this->shared[$class]) {
            $this->instantiated[$class] = $object;
        }

        return $object;
    }
150250
private static function reflect($class): \ReflectionClass
    {
        if (is_string($class) && (class_exists($class) || interface_exists($class) || trait_exists($class))) {
            return new \ReflectionClass($class);
        } elseif (is_object($class)) {
            return new \ReflectionObject($class);
        }

        throw new \InvalidArgumentException(
                'Given class must either be an existing class, interface or'
                . ' trait name or class instance, ' . \gettype($class)
                . ' with value "' . $class . '" given'
        );
    }
570548
public function getRepository($class)
    {
        $classMetadata = $this->getClassMetadataFor($class);
        if (!array_key_exists($class, $this->repositories)) {
            $repositoryClassName = $classMetadata->hasCustomRepository() ? $classMetadata->getRepositoryClass() : BaseRepository::class;
            $this->repositories[$class] = new $repositoryClassName($classMetadata, $this, $class);
        }

        return $this->repositories[$class];
    }
1060789
public static function getParentClassName($class)
    {
        $className = self::getClassName($class);
        $reflection = new \ReflectionClass($className);
        $parentClass = $reflection->getParentClass();

        if (null === $parentClass || false === $parentClass) {
            return null;
        }

        return $parentClass->getName();
    }
955548
protected static function getReflection($class)
    {
        if (!isset(self::$reflections[$class])) {
            self::$reflections[$class] = new ReflectionClass($class);
        }
        $result = self::$reflections[$class];

        return $result;
    }
199331
public function getNewInstance(\ReflectionClass $class) : NewInstance
    {
        $setterMethods = new SetterMethods([]);
        $methods = $class->getMethods();
        foreach ($methods as $method) {
            if ($method->name === '__construct') {
                continue;
            }
            $setterMethods->add($this->injectionMethod->getSetterMethod($method));
        }
        $name = $this->injectionMethod->getConstructorName($class);

        return new NewInstance($class, $setterMethods, $name);
    }
755978
public function loadMetadataForClass(\ReflectionClass $class)
    {
        $classMetadata = new MergeableClassMetadata($class->getName());

        foreach ($class->getProperties() as $reflectionProperty) {
            $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName());

            /** @var $annotation \Zicht\Bundle\FileManagerBundle\Annotation\File */
            $annotation = $this->reader->getPropertyAnnotation(
                $reflectionProperty,
                'Zicht\Bundle\FileManagerBundle\Annotation\File'
            );
            if (null !== $annotation) {
                // a "@DefaultValue" annotation was found
                $propertyMetadata->fileManager = $annotation->settings;
            }

            $classMetadata->addPropertyMetadata($propertyMetadata);
        }

        return $classMetadata;
    }
970106
private static function getInstance($class)
    {
        //get the backtrace
        $trace = debug_backtrace();
        $args = array();
        
        //the 2nd line is the caller method
        if (isset($trace[1]['args']) && count($trace[1]['args']) > 1) {
            //get the args
            $args = $trace[1]['args'];
            //shift out the class name
            array_shift($args);
            //then maybe it's the 3rd line?
        } else if (isset($trace[2]['args']) && count($trace[2]['args']) > 0) {
            //get the args
            $args = $trace[2]['args'];
        }
        
        //if there's no args or there's no construct to accept the args
        if (count($args) === 0 || !method_exists($class, '__construct')) {
            //just return the instantiation
            return new $class;
        }
        
        //at this point, we need to vitually call the class
        $reflect = new \ReflectionClass($class);
        
        try { //to return the instantiation
            return $reflect->newInstanceArgs($args);
        } catch (\ReflectionException $e) {
            //trigger error
            Exception::i()
                ->setMessage(self::ERROR_REFLECTION)
                ->addVariable($class)
                ->addVariable('new')
                ->trigger();
        }
    }
1153892
public function createInstance(string $class)
    {
        $refClass = new \ReflectionClass($class);
        $args = [];
        if ($refClass->getConstructor()) {
            foreach ($refClass->getConstructor()->getParameters() as $parameter) {
                $name = Inflector::tableize(str_replace('_', '.', $parameter->getName()));
                $dependency = null;
                if ($parameter->getClass()) {
                    if ($this->container->has($parameter->getClass()->getName())) {
                        $dependency = $this->container->get($parameter->getClass()->getName());
                    } elseif ($this->container->has($name)) {
                        $dependency = $this->container->get($name);
                    }
                } elseif ($this->container->hasParameter($name)) {
                    $dependency = $this->container->getParameter($name);
                }
                $args[] = $dependency;
            }
        }

        return $refClass->newInstanceArgs($args);
    }
23287
function classGetReflection($class) {
    if (array_key_exists($class, $this->classLikesByQcn)) {
      return $this->classLikesByQcn[$class];
    }
    if (class_exists($class, FALSE) || interface_exists($class, FALSE) || trait_exists($class, FALSE)) {
      $reflectionClass = new \ReflectionClass($class);
      $this->initKnownClass($class, $reflectionClass);
    }
    else {
      $this->triggerAutoload($class);
    }
    if (isset($this->classLikesByQcn[$class])) {
      return $this->classLikesByQcn[$class];
    }
    if (array_key_exists($class, $this->classLikesByQcn)) {
      return $this->classLikesByQcn[$class];
    }
    return NULL;
  }
1090301
public function loadMetadataForClass(\ReflectionClass $class)
    {
        $classMetadata                  = new MergeableClassMetadata($name = $class->name);
        $classMetadata->fileResources[] = $class->getFileName();

        foreach ($class->getProperties() as $property) {
            $propertyMetadata = new PropertyMetadata($name, $property->getName());
            $propertyAnnotations = $this->reader->getPropertyAnnotations($property);

            foreach ($propertyAnnotations as $annotation) {
                if ($annotation instanceof Fixture\Data) {
                    $propertyMetadata->staticData = $annotation->value;
                } elseif ($annotation instanceof Fixture\Faker) {
                    $propertyMetadata->fakerName = $annotation->name;
                    $propertyMetadata->fakerResolverType = $annotation->type;
                    $propertyMetadata->fakerResolverArgs = $annotation->arguments;
                } elseif ($annotation instanceof Fixture\Ignore) {
                    $propertyMetadata->ignore = true;
                }
            }

            $classMetadata->addPropertyMetadata($propertyMetadata);
        }

        return $classMetadata;
    }
444756
public static function loadClass($class)
    {
        if (isset(self::$_classMap[$class]))
            return (bool)require sprintf('%s/%s', self::ROOT_DIR, self::$_classMap[$class]);
        return null;
    }