protected static function instantiate($className, $arguments = null, $constructor = null, $includeFilename = null)
    {
        // Include file given?
        if (null !== $includeFilename) {
            include_once $includeFilename;
        }

        // create reflection of class
        $reflectionOfClass = new ReflectionClass($className);

        // Check if class is instantiable
        if (false === $reflectionOfClass->isInstantiable()) {

            // if no constructor given for singleton instantiation try to detect
            if (null === $constructor) {
                $constructor = self::parseConstructor($reflectionOfClass);
            }

            // Instantiate ...
            if (null === $arguments) {
                // ... without any arguments
                return call_user_func($className.'::'.$constructor);
            } else {
                // ... with arguments passed by
                if (is_array($arguments)) {
                    return call_user_func_array($className.'::'.$constructor, $arguments);
                } else {
                    return call_user_func($className.'::'.$constructor, $arguments);
                }
            }
        } else {

            // Check for given arguments
            if ($arguments) {

                // check if parameter is already of type array
                if (!is_array($arguments)) {
                    // if not make array
                    $arguments = [$arguments];
                }

                // return instance with parameter}
                return $reflectionOfClass->newInstanceArgs($arguments);
            } else {
                // return instance without parameter
                return $reflectionOfClass->newInstance();
            }
        }
    }
protected static function instantiate($className, $arguments = null, $constructor = null, $includeFilename = null)
    {
        // Include file given?
        if (null !== $includeFilename) {
            include_once $includeFilename;
        }

        // create reflection of class
        $reflectionOfClass = new ReflectionClass($className);

        // Check if class is instantiable
        if (false === $reflectionOfClass->isInstantiable()) {

            // if no constructor given for singleton instantiation try to detect
            if (null === $constructor) {
                $constructor = self::parseConstructor($reflectionOfClass);
            }

            // Instantiate ...
            if (null === $arguments) {
                // ... without any arguments
                return call_user_func($className.'::'.$constructor);
            } else {
                // ... with arguments passed by
                if (is_array($arguments)) {
                    return call_user_func_array($className.'::'.$constructor, $arguments);
                } else {
                    return call_user_func($className.'::'.$constructor, $arguments);
                }
            }
        } else {

            // Check for given arguments
            if ($arguments) {

                // check if parameter is already of type array
                if (!is_array($arguments)) {
                    // if not make array
                    $arguments = [$arguments];
                }

                // return instance with parameter}
                return $reflectionOfClass->newInstanceArgs($arguments);
            } else {
                // return instance without parameter
                return $reflectionOfClass->newInstance();
            }
        }
    }
protected static function instantiate ( $ className , $ arguments = null , $ constructor = null , $ includeFilename = null ) { // Include file given? if ( null !== $ includeFilename ) { include_once $ includeFilename ; } // create reflection of class $ reflectionOfClass = new ReflectionClass ( $ className ) ; // Check if class is instantiable if ( false === $ reflectionOfClass -> isInstantiable ( ) ) { // if no constructor given for singleton instantiation try to detect if ( null === $ constructor ) { $ constructor = self :: parseConstructor ( $ reflectionOfClass ) ; } // Instantiate ... if ( null === $ arguments ) { // ... without any arguments return call_user_func ( $ className . '::' . $ constructor ) ; } else { // ... with arguments passed by if ( is_array ( $ arguments ) ) { return call_user_func_array ( $ className . '::' . $ constructor , $ arguments ) ; } else { return call_user_func ( $ className . '::' . $ constructor , $ arguments ) ; } } } else { // Check for given arguments if ( $ arguments ) { // check if parameter is already of type array if ( ! is_array ( $ arguments ) ) { // if not make array $ arguments = [ $ arguments ] ; } // return instance with parameter} return $ reflectionOfClass -> newInstanceArgs ( $ arguments ) ; } else { // return instance without parameter return $ reflectionOfClass -> newInstance ( ) ; } } }
Returns an instance fof class requested.

@param string $className       Name of the class to load
@param array  $arguments       Arguments to pass to loaded class
@param string $constructor     Constructor to use for instantiation
@param string $includeFilename Filename to include before instantiating the class

@author Benjamin Carl <opensource@clickalicious.de>

@return object Instance of the class ($className) requested
Returns an instance fof class requested .