Clone an instance of one of the loaded classes.
It clones the class. It does NOT re-create it.

@param string $className The name of the loaded class, WITHOUT the namespace
@return Factory Instance
331343
public function cloneInstance($className): self
	{
		// Determine the class to load
		$instanceName = strtolower($className);

		if (!isset($this->{$instanceName}))
		{
			throw new FactoryException("Could not clone instance of '".$instanceName."'. Instance was not found.", 1);
		}

		// Clone the instance
		$this->{$instanceName} = clone $this->{$instanceName};

		// Return itself
		return $this;
	}
530108
public function create(string $className)
    {
        if (!class_exists($className)) {
            $classFileName = $this->fileNameforClass($className);
            $this->createFile($classFileName, $className, 'class.tmpl');
            $this->console->writeLine(
                    'Class ' . $className . ' created at ' . $classFileName
            );
        } else {
            $this->console->writeLine(
                    'Class ' . $className
                    . ' already exists, skipped creating the class'
            );
        }
    }
735016
public static function createObject( $className, $arguments = array() )
	{
		if( !class_exists( $className ) )
			throw new RuntimeException( 'Class "'.$className.'" has not been loaded' );
		$class	= new ReflectionClass( $className );
		if( $arguments )
			$object	= $class->newInstanceArgs( $arguments );
		else
			$object	= $class->newInstance();
		return $object;
	}
558754
public function create(string $className)
    {
        $this->console->writeLine('Please enter the script name for the console app: ');
        $stubFileName = $this->rootpath->to('bin',  $this->console->readLine());
        if (!file_exists($stubFileName)) {
            $this->createFile($stubFileName, $className, 'script.tmpl');
            $this->console->writeLine(
                    'Script for ' . $className . ' created at ' . $stubFileName
            );
        } else {
            $this->console->writeLine(
                    'Script for ' . $className
                    . ' already exists, skipped creating the script'
            );
        }
    }
651629
public function newInstance($className)
    {

        // lock the method
        \Mutex::lock($this->mutex);

        // we're not dispatched
        $this->dispatched = false;

        // initialize the data
        $this->className = $className;

        // notify the thread
        $this->notify();

        // wait till we've dispatched the request
        while ($this->dispatched === false) {
            usleep(100);
        }

        // try to load the last created instance
        if (isset($this->instances[$last = sizeof($this->instances) - 1])) {
            $instance = $this->instances[$last];
        } else {
            throw new \Exception('Requested instance can\'t be created');
        }

        // unlock the method
        \Mutex::unlock($this->mutex);

        // return the created instance
        return $instance;
    }
194593
public function getReflectionClass($className)
    {

        // check if we've already initialized the reflection class
        if (isset($this->reflectionClasses[$className]) === false) {
            $this->reflectionClasses[$className] = $this->newReflectionClass($className);
        }

        // return the reflection class instance
        return $this->reflectionClasses[$className];
    }
968797
public function setClassName(string $className): ClassPaser
    {
        $this->className = $className;
        $this->reflect_object = (new \ReflectionClass($this->className));

        return $this;
    }
818412
public function generateAndLoadClass($className)
    {
        if (class_exists($className, false)) {
            throw new \RuntimeException("Unable to generate and load already existing class '$className'");
        }

        $filename = $this->findFile($className);

        if (!$filename || !file_exists($filename)) {
            $classFileGenerator = $this->_builder->build($className);

            if ($filename) {
                file_put_contents($filename, $classFileGenerator->generate());
            } else {
                $this->evalContent($classFileGenerator);
            }
        }
        if ($filename && file_exists($filename)) {
            include $filename;
        }
    }
240042
protected function _createShell($className, $shortName)
    {
        list($plugin) = pluginSplit($shortName);
        $instance = new $className();
        $instance->plugin = trim($plugin, '.');

        return $instance;
    }
202142
public static function factory($className)
    {
        if (!$className || !is_string($className)) {
            exit('类名参数不正确');
        }

        $className = __NAMESPACE__ . '\\API\\' . $className . 'Api';

        if (!array_key_exists($className, self::$selfInstanceMap)) {
            $api = new $className();
            if (!$api instanceof BaseApi) {
                exit($className . ' 必须继承 BaseApi');
            }
            self::$selfInstanceMap[$className] = $api;
        }
        self::$instantiation = true;
        Api::$instantiation  = false;

        return self::$selfInstanceMap[$className];
    }
86902
public function isInstanceOf($className)
    {
        $this->doCheck(function ($value) use ($className) {
            $this->throwExceptionIfFalse(
                $value instanceof $className,
                'Failed assertion that %s is an instance of %s', $value, $className
            );
        });

        return $this;
    }
520006
public static function createNewObject($className, $args = null)
    {
        $mock = self::getMock(self::$injectedObjects, 'object', $className);
        if ($mock !== null)
        {
            return $mock;
        }

        if ($args === null)
        {
            return new $className();
        }

        // we need to pass arguments which requires reflection
        $reflection = new ReflectionClass($className);
        return $reflection->newInstanceArgs($args);
    }
99453
public function addClass($classname)
    {
        $classArr = $this->getClassArray();
        $classArr[] = $classname;
        return $this->setClassArray($classArr);
    }
981333
protected function getInstance($classname, $params)
    {
        $components = UIComponentsRegistry::get('ui-components');
        if (is_null($components)) {
            return false;
        }
        $object = $components->first(function ($value, $key) use($classname) {
            return $value instanceof $classname;
        });
        if (!$object) {
            return false;
        }

        $attributes       = array_only(array_get($params, 'data'), ['x', 'y', 'width', 'height', 'disabled', 'id']);
        $attributes['id'] = isset($params['id']) ? $params['id'] : null;

        $object->setAttributes($attributes);
        return $object;
    }
264754
public function build($className)
    {
        $footprint = $this->_footprintRegistry->get($className);

        $parentClass = $footprint->getParent();
        if (!$parentClass) {
            $parentClass = $this->_baseClassRegistry->find($className);
        }


        if ($footprint->isInterface()) {
            $generator = new InterfaceGenerator();
        } else {
            $traits = $this->_traitRegistry->findByClass($className);

            $generator = new ClassGenerator();
            $generator->useTraits($traits);
        }

        $generator->setName($className);
        $generator->setExtendedClass($parentClass);
        $generator->setImplementedInterfaces($footprint->getInterfaces());

        foreach ($footprint->getConstants() as $name => $value) {
            $generator->addConstant($name, $value);
        }

        $file = new FileGenerator();
        $file->setClass($generator);

        return $file;
    }
415946
public static function getInstance(
        $classname, $input = "", $userDefFunction = null
    ) {
        $fullname = "soloproyectos\\css\\parser\\filter\\"
            . $classname;
        return new $fullname($input, $userDefFunction);
    }
246125
protected function createType($typeName)
    {
        if (isset($this->typeCache[$typeName])) {
            return clone $this->typeCache[$typeName];
        }


        if (!$this->hasExtension($typeName)) {
            $class = $this->typeToClassName($typeName);
            $this->typeCache[$typeName] = new $class();
            return clone $this->typeCache[$typeName];
        }

        $this->typeCache[$typeName] = $this->callExtension($typeName, [$typeName, $this]);

        return clone $this->typeCache[$typeName]->setName($typeName);
    }