cron/controllers/CronRouter.php
public function index()
    {
        //  Command line only
        $oInput = Factory::service('Input');
        if (Environment::is(Environment::ENV_PROD) && !$oInput::isCli()) {
            header($oInput->server('SERVER_PROTOCOL') . ' 401 Unauthorized');
            echo '<h1>' . lang('unauthorised') . '</h1>';
            exit(401);
        }

        // --------------------------------------------------------------------------

        /**
         * Look for a controller, app version first then the module's cron controllers directory
         */
        $aControllerPaths = [
            NAILS_APP_PATH . 'application/modules/cron/controllers/',
        ];

        $nailsModules = Components::modules();

        foreach ($nailsModules as $oModule) {

            if ($oModule->moduleName === $this->sModuleName) {
                $aControllerPaths[] = $oModule->path . 'cron/controllers/';
                break;
            }
        }

        //  Look for a valid controller
        $sControllerName    = ucfirst($this->sClassName) . '.php';
        $bDidfindController = false;

        foreach ($aControllerPaths as $sPath) {

            $sControllerPath = $sPath . $sControllerName;

            if (is_file($sControllerPath)) {
                $bDidfindController = true;
                break;
            }
        }

        if (!empty($bDidfindController)) {

            //  Load the file and try and execute the method
            require_once $sControllerPath;

            $this->sModuleName = 'Nails\\Cron\\' . ucfirst($this->sModuleName) . '\\' . ucfirst($this->sClassName);

            if (class_exists($this->sModuleName)) {

                //  New instance of the controller
                $oInstance = new $this->sModuleName($this);

                if (is_callable([$oInstance, $this->sMethod])) {

                    //  Begin timing
                    $this->writeLog('Starting job');

                    if (!empty($this->aParams)) {

                        $this->writeLog('Passed parameters');
                        $this->writeLog(print_r($this->aParams, true));
                    }

                    $iStart = microtime(true) * 10000;

                    call_user_func_array([$oInstance, $this->sMethod], $this->aParams);

                    $iEnd      = microtime(true) * 10000;
                    $iDuration = ($iEnd - $iStart) / 10000;
                    $this->writeLog('Finished job');
                    $this->writeLog('Job took ' . number_format($iDuration, 5) . ' seconds');

                } else {

                    $this->writeLog('Cannot call method "' . $this->sMethod . '"');
                }

            } else {

                $this->writeLog(
                    '"' . $this->sModuleName . '" is incorrectly configured; could not find class ' . $this->sModuleName . '  at path ' . $sControllerPath
                );
            }

        } else {

            $this->writeLog(
                '"' . $this->sModuleName . '/' . $this->sClassName . '/' . $this->sMethod . '" is not a valid route.'
            );
        }
    }
public function index()
    {
        //  Command line only
        $oInput = Factory::service('Input');
        if (Environment::is(Environment::ENV_PROD) && !$oInput::isCli()) {
            header($oInput->server('SERVER_PROTOCOL') . ' 401 Unauthorized');
            echo '<h1>' . lang('unauthorised') . '</h1>';
            exit(401);
        }

        // --------------------------------------------------------------------------

        /**
         * Look for a controller, app version first then the module's cron controllers directory
         */
        $aControllerPaths = [
            NAILS_APP_PATH . 'application/modules/cron/controllers/',
        ];

        $nailsModules = Components::modules();

        foreach ($nailsModules as $oModule) {

            if ($oModule->moduleName === $this->sModuleName) {
                $aControllerPaths[] = $oModule->path . 'cron/controllers/';
                break;
            }
        }

        //  Look for a valid controller
        $sControllerName    = ucfirst($this->sClassName) . '.php';
        $bDidfindController = false;

        foreach ($aControllerPaths as $sPath) {

            $sControllerPath = $sPath . $sControllerName;

            if (is_file($sControllerPath)) {
                $bDidfindController = true;
                break;
            }
        }

        if (!empty($bDidfindController)) {

            //  Load the file and try and execute the method
            require_once $sControllerPath;

            $this->sModuleName = 'Nails\\Cron\\' . ucfirst($this->sModuleName) . '\\' . ucfirst($this->sClassName);

            if (class_exists($this->sModuleName)) {

                //  New instance of the controller
                $oInstance = new $this->sModuleName($this);

                if (is_callable([$oInstance, $this->sMethod])) {

                    //  Begin timing
                    $this->writeLog('Starting job');

                    if (!empty($this->aParams)) {

                        $this->writeLog('Passed parameters');
                        $this->writeLog(print_r($this->aParams, true));
                    }

                    $iStart = microtime(true) * 10000;

                    call_user_func_array([$oInstance, $this->sMethod], $this->aParams);

                    $iEnd      = microtime(true) * 10000;
                    $iDuration = ($iEnd - $iStart) / 10000;
                    $this->writeLog('Finished job');
                    $this->writeLog('Job took ' . number_format($iDuration, 5) . ' seconds');

                } else {

                    $this->writeLog('Cannot call method "' . $this->sMethod . '"');
                }

            } else {

                $this->writeLog(
                    '"' . $this->sModuleName . '" is incorrectly configured; could not find class ' . $this->sModuleName . '  at path ' . $sControllerPath
                );
            }

        } else {

            $this->writeLog(
                '"' . $this->sModuleName . '/' . $this->sClassName . '/' . $this->sMethod . '" is not a valid route.'
            );
        }
    }
public function index ( ) { //  Command line only $ oInput = Factory :: service ( 'Input' ) ; if ( Environment :: is ( Environment :: ENV_PROD ) && ! $ oInput :: isCli ( ) ) { header ( $ oInput -> server ( 'SERVER_PROTOCOL' ) . ' 401 Unauthorized' ) ; echo '<h1>' . lang ( 'unauthorised' ) . '</h1>' ; exit ( 401 ) ; } // -------------------------------------------------------------------------- /**
         * Look for a controller, app version first then the module's cron controllers directory
         */ $ aControllerPaths = [ NAILS_APP_PATH . 'application/modules/cron/controllers/' , ] ; $ nailsModules = Components :: modules ( ) ; foreach ( $ nailsModules as $ oModule ) { if ( $ oModule -> moduleName === $ this -> sModuleName ) { $ aControllerPaths [ ] = $ oModule -> path . 'cron/controllers/' ; break ; } } //  Look for a valid controller $ sControllerName = ucfirst ( $ this -> sClassName ) . '.php' ; $ bDidfindController = false ; foreach ( $ aControllerPaths as $ sPath ) { $ sControllerPath = $ sPath . $ sControllerName ; if ( is_file ( $ sControllerPath ) ) { $ bDidfindController = true ; break ; } } if ( ! empty ( $ bDidfindController ) ) { //  Load the file and try and execute the method require_once $ sControllerPath ; $ this -> sModuleName = 'Nails\\Cron\\' . ucfirst ( $ this -> sModuleName ) . '\\' . ucfirst ( $ this -> sClassName ) ; if ( class_exists ( $ this -> sModuleName ) ) { //  New instance of the controller $ oInstance = new $ this -> sModuleName ( $ this ) ; if ( is_callable ( [ $ oInstance , $ this -> sMethod ] ) ) { //  Begin timing $ this -> writeLog ( 'Starting job' ) ; if ( ! empty ( $ this -> aParams ) ) { $ this -> writeLog ( 'Passed parameters' ) ; $ this -> writeLog ( print_r ( $ this -> aParams , true ) ) ; } $ iStart = microtime ( true ) * 10000 ; call_user_func_array ( [ $ oInstance , $ this -> sMethod ] , $ this -> aParams ) ; $ iEnd = microtime ( true ) * 10000 ; $ iDuration = ( $ iEnd - $ iStart ) / 10000 ; $ this -> writeLog ( 'Finished job' ) ; $ this -> writeLog ( 'Job took ' . number_format ( $ iDuration , 5 ) . ' seconds' ) ; } else { $ this -> writeLog ( 'Cannot call method "' . $ this -> sMethod . '"' ) ; } } else { $ this -> writeLog ( '"' . $ this -> sModuleName . '" is incorrectly configured; could not find class ' . $ this -> sModuleName . '  at path ' . $ sControllerPath ) ; } } else { $ this -> writeLog ( '"' . $ this -> sModuleName . '/' . $ this -> sClassName . '/' . $ this -> sMethod . '" is not a valid route.' ) ; } }
Route the call to the correct place

@return Void
Route the call to the correct place