Get injector associated with given class.

@param \ReflectionClass $reflection
@return InjectorInterface
543885
private function getInjector(\ReflectionClass $reflection): InjectorInterface
    {
        if (isset($this->injectors[$reflection->getName()])) {
            //Stated directly
            $injector = $this->get($this->injectors[$reflection->getName()]);
        } else {
            //Auto-injection!
            $injector = $this->get($reflection->getConstant('INJECTOR'));
        }

        if (!$injector instanceof InjectorInterface) {
            throw new InjectionException(sprintf(
                "Class '%s' must be an instance of InjectorInterface for '%s'",
                get_class($injector),
                $reflection->getName()
            ));
        }

        return $injector;
    }
1141870
public static function get($class)
    {
        $key = strtolower($class);

        if (isset(static::$instances[$key])) {
            return static::$instances[$key];
        }

        static::override($class);

        if (!class_exists($class)) {
            throw new ReflectionException("Class $class does not exist");
        }

        $instance = static::getInstance($class);
        static::register($class, $instance);
        return $instance;
    }
326921
protected function generateImplements(\ReflectionClass $reflectionClass)
    {

        // load the class interfaces
        $interfaces = $reflectionClass->getInterfaces();

        // initialize the array for the
        $generateInterfaces = array();

        // iterate over the specified interfaces
        foreach ($interfaces as $interfaceName => $interface) {
            // clean them up to avoid doubles
            foreach ($generateInterfaces as $obj) {
                if ($obj->isSubclassOf($interface)) {
                    continue 2;
                }
            }

            // traversable interface can not be implemented directly, so ignore it
            if ($interface->getName() === 'Traversable') {
                continue;
            }

            // append the interface
            $generateInterfaces[sprintf('\\%s', $interfaceName)] = $interface;
        }

        // implode the interfaces and return them as string
        return implode(', ', array_keys($generateInterfaces));
    }
1107940
public function injectorForClosure(callable $closure)
    {
        $reflection = new \ReflectionFunction($closure);
        $parameters = $reflection->getParameters();
        $params = [];

        foreach ($parameters as $parameter) {
            $type = $parameter->getType();

            if (is_null($type)) {
                continue;
            }

            $class = trim($type->getName());

            if (! class_exists($class, true)) {
                continue;
            }

            if (!in_array(strtolower($class), $this->getInjectorExceptedType())) {
                if (method_exists($class, 'getInstance')) {
                    $params[] = $class::getInstance();
                } else {
                    $params[] = new $class();
                }
            }
        }

        return $params;
    }
709887
public static function beansOfType(ApplicationInterface $applicationContext, $class)
    {
        /**
         * @var $objectManager ObjectManagerInterface
         */
        $objectManager = $applicationContext->search("ObjectManagerInterface");
        $initialContext = new InitialContext();
        $initialContext->injectApplication($applicationContext);
        $beans = array();
        foreach ($objectManager->getObjectDescriptors() as $descriptor) {
            if ($descriptor instanceof ComponentDescriptorInterface) {
                if (is_subclass_of($descriptor->getClassName(), $class)) {
                    $beans[$descriptor->getName()] = $initialContext->lookup($descriptor->getName());
                }
            }
        }
        return $beans;
    }
413979
public static function createResourceForClass(\ReflectionClass $reflectionClass)
    {
        $metadata = array();

        if ($constructor = $reflectionClass->getConstructor()) {
            $metadata['__construct'] = self::getResourceMetadataForMethod($constructor);
        }

        foreach (self::getSetters($reflectionClass) as $reflectionMethod) {
            $metadata[$reflectionMethod->name] = self::getResourceMetadataForMethod($reflectionMethod);
        }

        return new AutowireServiceResource($reflectionClass->name, $reflectionClass->getFileName(), $metadata);
    }
11661
private function make(string $class)
    {
        if (! array_key_exists($class, $this->instances)) {

            try {

                return $this->instances[$class] = ($this->factory)($class)->value($this);

            }

            catch (ResolvingExceptionInterface $e) {

                throw new ReflectionContainerException($class, $e);

            }

        }

        return $this->instances[$class];
    }
1044048
public function loadMetadataForClass(\ReflectionClass $class)
    {
        $classMetadata = new ClassMetadata($class->getName());

        // should class be exposed?
        $annotation = $this->reader->getClassAnnotation(
            $class,
            Entity\Expose::class
        );

        $classMetadata->setExposed($annotation !== null);

        // not exposed so just return here
        if (!$classMetadata->isExposed()) {
            return $classMetadata;
        }

        if ($annotation->name) {
            $classMetadata->setExposedName($annotation->name);
        }

        $this->parseProperties($class, $classMetadata);

        while ($class = $class->getParentClass()) {
            $this->parseProperties($class, $classMetadata);
        }

        return $classMetadata;
    }
321608
public function createInjection(\ReflectionClass $class, string $context = null)
    {
        if ($class->isSubclassOf(ClassesInterface::class)) {
            return $this->classLocator();
        } elseif ($class->isSubclassOf(InvocationsInterface::class)) {
            return $this->invocationLocator();
        }

        throw new InjectionException("Unable to create injection for {$class}");
    }
507417
private function resolverClass($dependency, $arguments)
    {
        list($resolveClass, $reflectionParam) = $this->injector->getReflectionParam($dependency);

        // Application and Container cannot be injected into controller currently
        // since Application constructor is protected
        if ($reflectionParam->IsInstantiable()) {
            return $this->makeInstance($resolveClass, $arguments);
        }

        return $this->injector->interfaceInjection($reflectionParam);
    }
824348
private function keyPerEntityRequired(\ReflectionClass $reflectionClass)
    {
        $classMetadata = $this->getEncryptionMetadataFor($reflectionClass->getName());

        $keyPerEntityModes = array(
            EncryptionService::MODE_PER_USER_SHAREABLE,
            EncryptionService::MODE_SYSTEM_ENCRYPTION,
        );

        return $classMetadata->encryptionEnabled
            && in_array($classMetadata->encryptionMode, $keyPerEntityModes);
    }
169618
private function getAnalyzers(\ReflectionClass $reflectionClass)
    {
        $analyzers = [];

        foreach ($this->getDocumentPropertiesReflection($reflectionClass) as $name => $property) {
            $directory = $this->guessDirName($property->getDeclaringClass());

            $type = $this->getPropertyAnnotationData($property);
            $type = $type !== null ? $type : $this->getEmbeddedAnnotationData($property);

            if ($type instanceof Embedded) {
                $analyzers = array_merge(
                    $analyzers,
                    $this->getAnalyzers(new \ReflectionClass($this->finder->getNamespace($type->class, $directory)))
                );
            }

            if ($type instanceof Property) {
                if (isset($type->options['analyzer'])) {
                    $analyzers[] = $type->options['analyzer'];
                }
                if (isset($type->options['search_analyzer'])) {
                    $analyzers[] = $type->options['search_analyzer'];
                }

                if (isset($type->options['fields'])) {
                    foreach ($type->options['fields'] as $field) {
                        if (isset($field['analyzer'])) {
                            $analyzers[] = $field['analyzer'];
                        }
                        if (isset($field['search_analyzer'])) {
                            $analyzers[] = $field['search_analyzer'];
                        }
                    }
                }
            }
        }
        return array_unique($analyzers);
    }
1139859
protected function getDependentByParameter(ReflectionParameter $reflectionParameter)
    {
        $reflectionClass = $reflectionParameter->getClass();
        if (is_null($reflectionClass)) {
            throw new \BadMethodCallException('The method parameters not exists.');
        }
        $className = $reflectionClass->getName();

        if (array_key_exists($className, $this->container)) {
            return $this->container[$className];
        }
        return $this->newClass($className);
    }
405325
public function get(ContainerInterface $container = null)
    {
        if (empty($this->arguments)) {
            $instance = new $this->class();
        } else {
            $ref = new \ReflectionClass($this->class);
            $instance = $ref->newInstanceArgs($this->prepare($container, $this->arguments));
        }

        return $this->executeMethods($instance, $container);
    }
1026718
public function bindInjector(string $class, $injector): Container
    {
        if (!is_string($injector)) {
            throw new \InvalidArgumentException('Injector can only be set as string binding');
        }

        $this->injectors[$class] = $injector;

        return $this;
    }
805459
protected function resolveSetter(\ReflectionClass $reflection, string $name)
    {
        $setter = 'set' . ucfirst($name);

        if ($reflection->hasMethod($setter) && $reflection->getMethod($setter)->isPublic()) {
            return $setter;
        }
    }
126302
private function resolve($reflection, Type $type = null)
    {
        if ($type === null) {
            return null;
        }

        if (
            method_exists($reflection, 'getDeclaringClass') && (
                $type instanceof This ||
                $type instanceof Self_ ||
                $type instanceof Static_ ||
                $type instanceof Parent_
            )
        ) {
            $class = $reflection->getDeclaringClass()->getName();

            if ($type instanceof Parent_) {
                $class = get_parent_class($class) ?: $class;
            }

            return new Object_(new Fqsen('\\' . $class));
        }

        return $type;
    }