Allow get just one instance new/exiting saved on the pool.

@param string $class_name Name of the class to get the instance

@throws InvalidClassException If the constructor is not protected

@return mixed
544382
final public static function getInstance($class_name = null)
    {
        if (is_null($class_name)) {
            $class_name = get_called_class();
        }

        $reflection = new \ReflectionClass($class_name);
        if (!$reflection->isInstantiable()) {
            throw new \Exception("The constructor of the class '$class_name' must be protected", 1);
        }

        if (empty(self::$pool[$class_name])) {
            self::$pool[$class_name] = new $class_name();
        }

        return self::$pool[$class_name];
    }
116546
public static function singleton()
    {
        $returnValue = null;

        
        $cacheName = get_called_class();
        if (!isset(self::$instances[$cacheName])) {
        	self::$instances[$cacheName] = new $cacheName();
        }
        
        $returnValue = self::$instances[$cacheName];
        

        return $returnValue;
    }
615279
private function get_model_instance($model_classname)
	{
	    if(!isset($this->controller->{$model_classname}))
		{
			/*
			 * Do not use $this->controller->loadModel, as calling it from a plugin may prevent correct loading of behaviors
			 */
			$model_instance = ClassRegistry :: init($model_classname);
		}
		else
		{
			$model_instance = $this->controller->{$model_classname};
		}
		
		return $model_instance;
	}
1328490
protected function findOrCreateMethod(Class_ $class, $name)
    {
        $foundMethods = array_filter(
            $class->getMethods(),
            function (ClassMethod $method) use ($name) {
                return $name === $method->name;
            }
        );

        $method = reset($foundMethods);

        if (!$method) {
            $class->stmts[] = $method = new ClassMethod($name);
        }

        return $method;
    }
100086
public function getFirstDescendant($class_name)
    {
        if (!class_exists($class_name) && !interface_exists($class_name)) {
            return null;
        }

        $out = null;

        foreach ($this->action_items as $action_item) {
            if ($action_item instanceof $class_name) {
                $out = $action_item;
                break;
            }

            if ($action_item instanceof SwatUIParent) {
                $out = $action_item->getFirstDescendant($class_name);
                if ($out !== null) {
                    break;
                }
            }
        }

        return $out;
    }
502646
public function get_prefix($class_name){
        /** @var RestBase $class_name */
        if( !empty($class_name::$prefix) ){
            return $class_name::$prefix;
        }else{
            $seg = explode('\\', $class_name);
            $base = $seg[count($seg) - 1];
            return $this->str->camel_to_hyphen($base);
        }
    }
442227
public function fetchObject($class_name = 'stdClass', array $ctor_args = array()) {
		$obj = $this->fetch(PDO::FETCH_OBJ);
		if($class_name == 'stdClass') {
			$res = $obj;
		}
		else {
			$res = $this->populateObject($obj, $class_name, $ctor_args);
		}

		return $res;
	}
937545
public function getLastNameSpace($class_name)
    {
        $class          = new \ReflectionClass($class_name);
        //获取命名空间
        $namespace      = $class->getNamespaceName();
        //分割获取命名空间
        $arr_namespace  = $namespace ? explode('\\', $namespace):array("");
        //获取最后一个命名空间
        $end_namespace  = array_pop($arr_namespace);
        return $end_namespace;
    }
138249
public static function getInstance()
    {
        if (self::$instance == null)
        {
            $c = __CLASS__;
            self::$instance = new $c;
        }

        return self::$instance;
    }
811311
protected function _fetch_object($class_name = 'stdClass')
	{
		// No native support for fetching rows as objects
		if (($row = $this->result_id->fetchArray(SQLITE3_ASSOC)) === FALSE)
		{
			return FALSE;
		}
		elseif ($class_name === 'stdClass')
		{
			return (object) $row;
		}

		$class_name = new $class_name();
		foreach (array_keys($row) as $key)
		{
			$class_name->$key = $row[$key];
		}

		return $class_name;
	}
518330
protected function serviceProviderIsRegistered($class_name)
    {
        if (\method_exists($this->app, 'getLoadedProviders')) {
            $loaded = \array_keys($this->app->getLoadedProviders());

            return \in_array($class_name, $loaded, true);
        }

        return false;
    }
931679
public function getFirstDescendant($class_name)
    {
        if (!class_exists($class_name) && !interface_exists($class_name)) {
            return null;
        }

        $out = null;

        if ($this->widget instanceof $class_name) {
            $out = $this->widget;
        }

        if ($out === null && $this->widget instanceof SwatUIParent) {
            $out = $this->widget->getFirstDescendant($class_name);
        }

        return $out;
    }
484054
public static function instance($config_name)
    {
        if (empty(self::$instance[$config_name])) {
            $config = self::$config[$config_name];
            self::$instance[$config_name] = new \Beanbun\Lib\DbConnection($config);
        }
        return self::$instance[$config_name];
    }
824840
public static function instance($model_class)
	{
		$observer = get_called_class();
		if (empty(static::$_instances[$observer][$model_class]))
		{
			static::$_instances[$observer][$model_class] = new static($model_class);
		}

		return static::$_instances[$observer][$model_class];
	}
891798
public static function isClass($class_name) {
    $class_names = func_get_args();

    return function ($node) use ($class_names) {
      if ($node instanceof ClassNode) {
        return in_array($node->getName()->getText(), $class_names, TRUE);
      }
      return FALSE;
    };
  }
1187599
public static function instance($className = __CLASS__)
    {
        if (!isset(self::$instances[$className])) {
            self::$instances[$className] = new $className;
        }

        return self::$instances[$className];
    }
317648
protected function getClosure(string $class_name, string $class_key): callable
    {
        $parent_class_names = class_parents($class_name);
        $all_class_names    = $parent_class_names;
        $all_class_names[]  = $class_name;

        $class                      = new \ReflectionClass($class_name);
        $constructor                = $class->getConstructor(); // Null if no constructor.
        $class_rule                 = $this->getRule($class_name, $class_key, $parent_class_names);
        $constructor_params_closure = $constructor ? $this->getParamsClosure($constructor, $class_rule) : null;

        if (!$this->rules['*']['new_instances'] || !array_intersect($all_class_names, $this->rules['*']['new_instances'])) {
            return function (array $args) use ($class, $class_key, $constructor, $constructor_params_closure) {
                if ($constructor && $constructor_params_closure) {
                    return $this->instances[$class_key] = $class->newInstanceArgs($constructor_params_closure($args));
                } else {
                    return $this->instances[$class_key] = $class->newInstanceWithoutConstructor();
                }
            };
        } elseif ($constructor && $constructor_params_closure) {
            return function (array $args) use ($class, $constructor_params_closure) {
                return $class->newInstanceArgs($constructor_params_closure($args));
            };
        } else {
            return function (array $args) use ($class) {
                return $class->newInstanceWithoutConstructor();
            };
        }
    }