src/Components.php
public static function getDriverInstance($oDriver): Base
    {
        //  Allow for driver requesting as a string
        if (is_string($oDriver)) {
            $oDriver = \Nails\Components::getBySlug($oDriver);
        }

        if (isset(static::$aCache['DRIVER_INSTANCE'][$oDriver->slug])) {
            return static::$aCache['DRIVER_INSTANCE'][$oDriver->slug];
        }

        //  Test driver
        if (!empty($oDriver->data->namespace)) {
            $sNamespace = $oDriver->data->namespace;
        } else {
            throw new NailsException('Driver Namespace missing from driver "' . $oDriver->slug . '"', 1);
        }

        if (!empty($oDriver->data->class)) {
            $sClassName = $oDriver->data->class;
        } else {
            throw new NailsException('Driver ClassName missing from driver "' . $oDriver->slug . '"', 2);
        }

        //  Load the driver file
        $sDriverPath = $oDriver->path . 'src/' . $oDriver->data->class . '.php';
        if (!file_exists($sDriverPath)) {
            throw new NailsException(
                'Driver file for "' . $oDriver->slug . '" does not exist at "' . $sDriverPath . '"',
                3
            );
        }

        require_once $sDriverPath;

        //  Check if the class exists
        $sDriverClass = $sNamespace . $sClassName;

        if (!class_exists($sDriverClass)) {
            throw new NailsException('Driver class does not exist "' . $sDriverClass . '"', 4);
        }

        //  Save for later
        static::$aCache['DRIVER_INSTANCE'][$oDriver->slug] = new $sDriverClass();

        return static::$aCache['DRIVER_INSTANCE'][$oDriver->slug];
    }
public static function getDriverInstance($oDriver): Base
    {
        //  Allow for driver requesting as a string
        if (is_string($oDriver)) {
            $oDriver = \Nails\Components::getBySlug($oDriver);
        }

        if (isset(static::$aCache['DRIVER_INSTANCE'][$oDriver->slug])) {
            return static::$aCache['DRIVER_INSTANCE'][$oDriver->slug];
        }

        //  Test driver
        if (!empty($oDriver->data->namespace)) {
            $sNamespace = $oDriver->data->namespace;
        } else {
            throw new NailsException('Driver Namespace missing from driver "' . $oDriver->slug . '"', 1);
        }

        if (!empty($oDriver->data->class)) {
            $sClassName = $oDriver->data->class;
        } else {
            throw new NailsException('Driver ClassName missing from driver "' . $oDriver->slug . '"', 2);
        }

        //  Load the driver file
        $sDriverPath = $oDriver->path . 'src/' . $oDriver->data->class . '.php';
        if (!file_exists($sDriverPath)) {
            throw new NailsException(
                'Driver file for "' . $oDriver->slug . '" does not exist at "' . $sDriverPath . '"',
                3
            );
        }

        require_once $sDriverPath;

        //  Check if the class exists
        $sDriverClass = $sNamespace . $sClassName;

        if (!class_exists($sDriverClass)) {
            throw new NailsException('Driver class does not exist "' . $sDriverClass . '"', 4);
        }

        //  Save for later
        static::$aCache['DRIVER_INSTANCE'][$oDriver->slug] = new $sDriverClass();

        return static::$aCache['DRIVER_INSTANCE'][$oDriver->slug];
    }
public static function getDriverInstance ( $ oDriver ) : Base { //  Allow for driver requesting as a string if ( is_string ( $ oDriver ) ) { $ oDriver = \ Nails \ Components :: getBySlug ( $ oDriver ) ; } if ( isset ( static :: $ aCache [ 'DRIVER_INSTANCE' ] [ $ oDriver -> slug ] ) ) { return static :: $ aCache [ 'DRIVER_INSTANCE' ] [ $ oDriver -> slug ] ; } //  Test driver if ( ! empty ( $ oDriver -> data -> namespace ) ) { $ sNamespace = $ oDriver -> data -> namespace ; } else { throw new NailsException ( 'Driver Namespace missing from driver "' . $ oDriver -> slug . '"' , 1 ) ; } if ( ! empty ( $ oDriver -> data -> class ) ) { $ sClassName = $ oDriver -> data -> class ; } else { throw new NailsException ( 'Driver ClassName missing from driver "' . $ oDriver -> slug . '"' , 2 ) ; } //  Load the driver file $ sDriverPath = $ oDriver -> path . 'src/' . $ oDriver -> data -> class . '.php' ; if ( ! file_exists ( $ sDriverPath ) ) { throw new NailsException ( 'Driver file for "' . $ oDriver -> slug . '" does not exist at "' . $ sDriverPath . '"' , 3 ) ; } require_once $ sDriverPath ; //  Check if the class exists $ sDriverClass = $ sNamespace . $ sClassName ; if ( ! class_exists ( $ sDriverClass ) ) { throw new NailsException ( 'Driver class does not exist "' . $ sDriverClass . '"' , 4 ) ; } //  Save for later static :: $ aCache [ 'DRIVER_INSTANCE' ] [ $ oDriver -> slug ] = new $ sDriverClass ( ) ; return static :: $ aCache [ 'DRIVER_INSTANCE' ] [ $ oDriver -> slug ] ; }
Returns an instance of a single driver

@param  object $oDriver The Driver definition

@throws NailsException
@return Base
Returns an instance of a single driver