Get singleton of a class.

@param string $class
@param string $method Optional
@return object|array
505906
protected function getSingleton($class) {
		if (isset($this->singletons[$class])) {
			return $this->singletons[$class];
		}

		$instance = $this->getNewInstance($class);
		$this->singletons[$class] = $instance;
		return $instance;
	}
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);
    }
1194860
public function singleton($className) {
        $closure = function(ContainerInterface $container) use($className) {
            static $instance;
            
            if (is_null($instance)) {
                $instance = $container->make($className);
            }

            return $instance;
        };

        $this->bind($className, $closure);
    }
796819
public function singleton(string $name, string $class, string $alisa = '')
        {
                $this->singleton[$name] = $this->build($class);
                $this->singleton[$class] = $this->singleton[$name];
                if(!empty($alisa)) {
                        $this->aliases[$name] = $this->singleton[$name];
                        $this->aliases[$alisa] = $this->singleton[$name];
                        $this->aliases[$name] = $this->singleton[$name];
                }
                return $this;
        }
1158492
public static function getInstance($className)
    {
        if (!isset(self::$instances[$className])) {
            self::$instances[$className] = new self($className);
        }

        return self::$instances[$className];
    }
1084969
public function get($class = null)
        {
            $class = $this->getClass($class);

            if (Arrays::exists($class, $this->reflections)) {
                return $this->reflections[$class];
            }

            throw new Exception("Class not found: $class");
        }
29716
static function getMethodAnnotation($method, $annotationName, $class = NULL)
	{
		$method instanceof ReflectionMethod or $method = new ReflectionMethod($class, $method);

		return static::instance()->getMethodAnnotation($method, $annotationName);
	}
955548
protected static function getReflection($class)
    {
        if (!isset(self::$reflections[$class])) {
            self::$reflections[$class] = new ReflectionClass($class);
        }
        $result = self::$reflections[$class];

        return $result;
    }
13650
protected static function _GetInstance ($class_name) {
		return (isset(static::$_instanceList[$class_name])) ? static::$_instanceList[$class_name] : static::$_instanceList[$class_name] = new static($class_name);
	}
315899
public function injector($classname, $method = null)
    {
        $params = [];
        $reflection = new \ReflectionClass($classname);

        if (is_null($method)) {
            $method = "__invoke";
        }

        $parameters = $reflection->getMethod($method)->getParameters();

        foreach ($parameters as $parameter) {
            $class = $parameter->getClass();

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

            $constructor = $class->getName();

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

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

        return $params;
    }
892926
public static function getMethodAnnotations($class, $method)
    {
        $annotationBag = Bridge\Loader::getInstance()->getMethodAnnotations($class, $method);
        $annotationBag = self::explodeNamespaces($annotationBag);

        return new ConfigObject($annotationBag);
    }
356029
public static function singleton()
    {
        $returnValue = null;

        
        
        if(is_null(self::$instance)){
        	$class = __CLASS__;				//used in case of subclassing
        	self::$instance = new $class();
        }
        $returnValue = self::$instance;
        
        

        return $returnValue;
    }
1329908
public function create($class) {
        $reflectionClass = new ReflectionClass($class);
        $reflectionMethod = $reflectionClass->getConstructor();
        if (!$reflectionMethod) {
            return new $class;
        }
        $params = &$this->fetchDepsFromSignature($reflectionMethod);
        return $reflectionClass->newInstanceArgs($params);
    }
780347
protected function createQueuedHandlerCallable($class, $method)
    {
        return function () use ($class, $method) {
            $arguments = array_map(function ($a) {
                return is_object($a) ? clone $a : $a;
            }, func_get_args());

            if (method_exists($class, 'queue')) {
                $this->callQueueMethodOnHandler($class, $method, $arguments);
            } else {
                $this->queueHandler($class, $method, $arguments);
            }
        };
    }
549543
public function getObjectInstance($class)
  {
    // Eventbasierte Objekt-Erzeugung
    $event = new ClassBuilderEvent($class);

    // $class enthält bereits ein Objekt
    if ($event->isObject() === true)
    {
      // Vor der Rückgabe an die EventListener/EventSubscriber geben...
      $this->dispatcher->dispatch(TransformerEvents::OBJECT_RETURN_INSTANCE, $event);

      return $event->getObject();
    }

    // $class enthält noch kein Objekt
    if (class_exists($event->getObject()))
    {
      $this->dispatcher->dispatch(TransformerEvents::OBJECT_CREATE_INSTANCE, $event);

      // Wenn in keinem EventListener/EventSubscriber die Instanz erzeugt wurde...
      if ($event->isObject() === false)
      {
        $reflection = new \ReflectionClass($class);

        return $reflection->newInstanceWithoutConstructor();
      }

      // Wenn in einem EventListener/EventSubscriber die Instanz erzeugt wurde...
      return $event->getObject();
    }
    throw new TransformerException(sprintf('Class %s does not exist.', $class));
  }
948273
public static function instance($instance = null)
	{
		$class = get_called_class();

		if (static::exists($instance))
		{
			$instance = static::$_instances[$class][$instance];
		}
		else
		{
			$instance = false;
		}

		return $instance;
	}
1187599
public static function instance($className = __CLASS__)
    {
        if (!isset(self::$instances[$className])) {
            self::$instances[$className] = new $className;
        }

        return self::$instances[$className];
    }