Get object from shared instances by class name.

@param string $class
@return mixed
962888
public function get($class)
    {
        $class = ltrim($class, '\\');

        if (!isset($this->sharedInstances[$class])) {
            $this->sharedInstances[$class] = $this->create($class);
        }
        return $this->sharedInstances[$class];
    }
1124919
public static function getAllChildClasses($class): array
    {
        $type = gettype($class);
        $className = '';

        /* If input an object */
        if ($type == 'object') {
            $className = get_class($class);
        }

        /* If input a string */
        elseif ($type == 'string') {
            $className = $class;
        }

        $classes = [];

        /* Go through all classes */
        foreach (get_declared_classes() as $class) {
            if (is_subclass_of($class, $className)) {
                $classes[] = $class;
            }
        }

        return $classes;
    }
899563
public function loadObject($class = 'stdClass')
	{
		// Initialise variables
		$return = null;

		// Execute the query
		if (!$this->execute())
		{
			return null;
		}

		// Get the first row from the result set as an object of type $class
		if ($row = $this->fetchObject($class))
		{
			$return = $row;
		}

		// Free up system resources and return
		$this->freeResult();

		return $return;
	}
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();
        }
    }
604418
public static function getModel($class)
    {
        if ($class instanceof \rhoone\extension\Extension) {
            $class = $class->className();
        }
        if (is_string($class)) {
            return \rhoone\models\Extension::find()->where(['classname' => static::normalizeClass($class)])->one();
        }
        if ($class instanceof \rhoone\models\Extension) {
            return \rhoone\models\Extension::find()->guid($class->guid)->one();
        }
        return null;
    }
147595
protected function instance($class)
    {
        $reflection = new \ReflectionClass($class);

        $arguments = array();

        $constructor = $reflection->getConstructor();

        if ($this->container->has($class))
        {
            return $this->container->get($class);
        }

        if ($constructor !== null)
        {
            $arguments = $this->arguments($constructor);
        }

        return $reflection->newInstanceArgs($arguments);
    }
541286
protected static function getObject($className)
    {
        if (!isset(self::$instances[$className])) {
            self::$instances[$className] = self::createObject($className);
        }

        return self::$instances[$className];
    }
634220
public function loadClass($class)
    {
        $result = $this->loadCachedClass($class);

        if ($result === false) {
            $result = parent::loadClass($class);
        }

        if ($this->verbose) {
            return $result !== false;
        }
    }
135148
public function get($class, ...$args)
    {
        $poolName = trim($class, '\\');

        if (!$poolName) {
            return null;
        }

        $pool     = $this->map[$poolName] ?? null;
        if ($pool == null) {
            $pool = $this->applyNewPool($poolName);
        }

        if ($pool->count()) {
            $obj = $pool->shift();
            $obj->__isConstruct = false;
            return $obj;
        } else {
            $reflector         = new \ReflectionClass($poolName);
            $obj               = $reflector->newInstanceWithoutConstructor();
            $obj->__useCount   = 0;
            $obj->__genTime    = time();
            $obj->__isConstruct = false;
            $obj->__DSLevel    = Macro::DS_PUBLIC;
            unset($reflector);
            return $obj;
        }
    }
497103
private function getModel($class)
    {
        $reflectionClass = new \ReflectionClass($class);
        $instance = $reflectionClass->newInstance();
        if (!($instance instanceof ModelInterface)) {
            throw new \Exception('This class is not supported');
        }

        return $instance;
    }
949825
public function resolveClass(string $class)
    {
        $object = $this->getClass($class);

        $definitions = $this->container->isDefined($object->getName())
            ? $this->container->getDefiniition($object->getName()) : null;

        $constructor_parameters = $object->getConstructor() !== null ? $object->getConstructor()->getParameters() : null;
        $parameters = $this->resolveParameters($constructor_parameters ?? [], $definitions);

        return $object->newInstanceArgs($parameters);
    }
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();
    }
1158492
public static function getInstance($className)
    {
        if (!isset(self::$instances[$className])) {
            self::$instances[$className] = new self($className);
        }

        return self::$instances[$className];
    }
536027
public function getObjects($class = null)
    {
        if ($class === null) {
            return $this->objects;
        }

        $objects = [];

        foreach ($this->objects as $object) {
            if ($object instanceof $class) {
                $objects[] = $object;
            }
        }

        return $objects;
    }
310856
public function find($class)
    {
        $reflectionClass = new \ReflectionClass($class);

        do {
            $classNamespace = $reflectionClass->getNamespaceName();
            foreach ($this->bundles as $bundleName => $bundleClass) {
                $bundleNamespace = \substr($bundleClass, 0, \strrpos($bundleClass, '\\'));
                if (0 === \strpos($classNamespace, $bundleNamespace)) {
                    return $bundleName;
                }
            }
            $reflectionClass = $reflectionClass->getParentClass();
        } while ($reflectionClass);

        return null;
    }
860407
protected function getBinding($class)
    {
        if ($this->isCollection($class) && ! $class->isEmpty()) {
            return $this->getBindingFromCollection($class);
        }

        $class = is_object($class) ? get_class($class) : $class;

        if (! $this->hasBinding($class)) {
            throw new RuntimeException('Unable to find bound transformer for "'.$class.'" class.');
        }

        return $this->bindings[$class];
    }
904158
public function getClass(string $class){
        if(!class_exists($class)){
            throw new \InvalidArgumentException();
        }

        if(!array_key_exists($class, $this->classes)){
            $this->classes[$class]  = new \ReflectionClass($class);
        }

        return $this->classes[$class];
    }