src/Base.php
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();
        }
    }
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();
        }
    }
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 ( ) ; } }
Returns an instance considering routes. With
this method we can instantiate while passing
construct arguments as arrays

@param *string $class name of the class

@return object
Returns an instance considering routes . With this method we can instantiate while passing construct arguments as arrays