create new instance of given class

@param string $namespace
@param array $args
@return mixed
@throws \InvalidArgumentException
@throws RegisterException
961987
public function factory($namespace, array $args = [])
    {
        $namespace = $this->checkOverrider($namespace);

        $this->classExists($namespace)
            ->callEvent('register_before_create', [$namespace, $args]);

        try {
            $object = new $namespace(...$args);
        } catch (\Exception $exception) {
            throw new RegisterException($exception);
        }

        $this->callEvent('register_after_create', [$object]);

        $this->setClassCounter($namespace);
        $this->registeredObjects[$namespace] = get_class($object);

        $this->makeLog([
            'Object created: ' . $namespace . '. With args:',
            $args
        ]);

        return $object;
    }
415312
public static function create($namespace = null, $name = null)
    {
        if (null === $namespace) {
            return self::createNamespacelessUuid();
        }

        return self::createNamespacedUuid($namespace, $name);
    }
473255
public function setNamespace($namespace)
    {
        if (is_string($namespace) === false) {
            $msg = "The namespace argument must be a string.";
            throw new InvalidArgumentException($msg);
        } elseif ($namespace === '') {
            $msg = "The namespace argument must be a non-empty string.";
            throw new InvalidArgumentException($msg);
        } else {
            $this->namespace = $namespace;
        }
    }
835015
public function singletonFactory($namespace, array $args = [], $name = null)
    {
        if (is_null($name)) {
            $name = $namespace;
        }

        if (!isset($this->singletons[$name])) {
            $this->singletons[$name] = $this->factory($namespace, $args);
        }

        $this->callEvent(
            'register_before_return_singleton',
            [$this->singletons[$name], $args, $name]
        );

        return $this->singletons[$name];
    }
779288
public static function object($alias,$namespace=null,$args=[]) {
        if (isset(self::$pool[$alias])) {
            return self::$pool[$alias];
        }

        //object('dao','\app\Name',[]);3
        //object('dao','\app\Name');2

        //object('\app\Name',[]); 2
        //object('\app\Name');  1

        if($namespace == null) {
            $namespace = $alias;
        }
        elseif(is_array($namespace)) {
            $args = $namespace;
            $namespace = $alias;
        }

        $constructor = static::make($namespace,$args);
        /*
        $reflect = new \ReflectionClass($namespace);
        $constructor = $reflect->getConstructor();
        if (!$constructor || $constructor->getNumberOfParameters() == 0) {
            $constructor = $reflect->newInstance();
        }
        else {
            $constructor = $reflect->newInstanceArgs($args);
        }
        */
        //固化
        if(in_array($alias,Config::$o->pool)) {
            self::$solidify[$alias] = $constructor;
        }
        return self::$pool[$alias] = $constructor;
    }
589666
protected function initService(array $args = null) {
		if (is_object($this->prototype)) {
			return clone $this->prototype;
		}
		
		$copy = $this->prototype;
		return $copy;
	}
1037272
protected static function createObject($class, ...$args)
    {
        if (!is_subclass_of($class, DataMapper::class) && !is_subclass_of($class, AbstractDatabaseMapperProxy::class)) {
            throw new \InvalidArgumentException(sprintf('Class: %s is not sub class of ' . DataMapper::class, $class));
        }

        return new $class(...$args);
    }
1307789
public function create($class, $args = [])
    {
        $class = (string) $class;

        if (empty($class)) {
            throw new InvalidArgumentException(
                'Cannot create a migration from an empty class name!'
            );
        }

        if (!is_array($args)) {
            throw new InvalidArgumentException(
                'Argument "params" must be an array of parameters.'
            );
        }

        if (!empty($args)) {
            $class = new \ReflectionClass($class);
            $instance = $class->newInstanceArgs($args);
        } else {
            $instance = new $class();
        }

        return $instance;
    }
1005001
public function newInstance($className, array $args = array())
    {
        return $this->getApplication()->search(ProviderInterface::IDENTIFIER)->newInstance($className, $args);
    }
424630
public static function create(...$args) {
        $alias = get_called_class();

        $config = end($args)?:[];
        $class = self::parse($alias,$config);

        return Pool::make($class,$args);
    }
111392
public function newInstance(string $class, array $args, BindInterface $bind)
    {
        $compiledClass = $this->compile($class, $bind);
        $instance = (new ReflectionClass($compiledClass))->newInstanceArgs($args);
        $instance->bindings = $bind->getBindings();

        return $instance;
    }
900272
static function getClass($namespace = '',$config = [],$new = false){
	
		if($namespace == ''){
			return self::$instance;
		}
		
		if($new === false && isset(self::$instance[$namespace])){
			return self::$instance[$namespace];
		}
		
		$ns = self::getName($namespace);
		
		self::$instance[$namespace] = new $ns->namespace($config);
		
		return self::$instance[$namespace] ;
	}
460820
public function createInstance(array $args = array())
    {
        $generatedClass = $this->getClassName($this->class);

        if (!class_exists($generatedClass, false)) {
            eval($this->generateClass());
        }

        $ref = new \ReflectionClass($generatedClass);

        return $ref->newInstanceArgs($args);
    }
875005
private function _createInstance($namespace, $class, $params, $method_name, $data)
    {
        $ns_class = $namespace . $class;

        //create a reflection class so that we can pass parameters to the constructor

        $ref_class = new \ReflectionClass($ns_class);

        if (is_array($params) && sizeof($params) > 0) {

            $instance = $ref_class->newInstanceArgs($params);

        } else {

            $instance = new $ns_class();
        }
        
        $this->logger->info("$namespace object created for $class class");
   
        //call the method along with parameters, if they exist !
        if (method_exists($instance, $method_name))
        {
            if(is_callable(array($instance, $method_name)))
            {
                $last_hook = $this->loading[count($this->loading) - 1];
                $this->loaderHooks($instance,"pre_$last_hook",$class,$method_name,$data);
                call_user_func_array(array($instance, $method_name), $data);
                $this->loaderHooks($instance,"post_$last_hook",$class,$method_name,$data);
            }
        }elseif(is_object($instance)) 
        {
            $last_hook = $this->loading[count($this->loading) - 1];
            $this->loaderHooks($instance,"pre_$last_hook",$class,$method_name,$data);
        }
        else if(strpos($namespace,'controller') > 0)
        {
            header("HTTP/1.0 404 Not Found");
            Base::getInstance()->hook('404',array(
                'file' => $ref_class,
                'controller' => $class,
                'method' => $method_name,
                'message' => '404'
            ));
            die();
        }

        $this->clearCurrentLoader();

        return $instance;
    }
749863
public function register_namespace( $namespace, $paths )
    {
        if ( isset( $this->namespaces[ $namespace ] ) )
        {
            $this->namespaces[ $namespace ] = array_merge(
                $this->namespaces[ $namespace ],
                (array) $paths
            );
        } 
        else 
        {
            $this->namespaces[ $namespace ] = (array) $paths;
            
            // Register PSR_0 as the first autoload filter for every namespace
            $this->register_autoload_filter( $namespace, array( $this, "PSR_0" ) );
        }
    }
1057989
public static function instantiateClassByConstructor($class, $args)
    {
        switch (count($args)) {
            case 0:
                return new $class();
            case 1:
                return new $class($args[0]);
            case 2:
                return new $class($args[0], $args[1]);
            case 3:
                return new $class($args[0], $args[1], $args[2]);
            case 4:
                return new $class($args[0], $args[1], $args[2], $args[3]);
            default:
                $rClass = new \ReflectionClass($class);
                return $rClass->newInstanceArgs($args);
        }
    }
1120635
protected static function createObject($class, ...$args)
    {
        if (!is_subclass_of($class, Record::class)) {
            throw new \InvalidArgumentException(sprintf('Class: %s is not sub class of ' . Record::class, $class));
        }

        // TODO: Make Record support set DB after construct.
        try {
            return new $class(...$args);
        } catch (\Exception $e) {
            if ($e instanceof \InvalidArgumentException || $e->getPrevious() instanceof \PDOException) {
                return new NullRecord();
            }

            throw $e;
        }
    }