* @package MCMS\System */ abstract class RunnerBase extends \Mammut\StrictObject implements \MCMS\Interfaces\iRunner { protected $weaving; public function setWeaving($data) { $this->weaving = $data; } public function getWeaving() { return $this->weaving; } public function run($callorder = false) { if (empty($callorder)) { if(defined('_CLI_')) { $callorder = [ 'doLoadConfig', 'doInit', 'doRunCLI', 'doCleanup' ]; } else { $callorder = [ 'doLoadConfig', 'doInit', 'doRoute', 'doBeforeRun', !defined('_ADMIN_') ? 'doRun' : 'doRunAdmin', 'doAfterRun', 'doOutput', 'doCleanup' ]; } } if (!defined('PROFILE')) { foreach ($callorder as $call) $this->{$call}(); } else { $profilerClass = defined('PROFILE'); if (!class_exists($profilerClass)) $profilerClass = \Mammut\Profiler\Profiler::clazz(); foreach ($callorder as $call) { call_user_func([$profilerClass,'start'],'runner::'.$call); $this->{$call}(); call_user_func([$profilerClass,'stop'],'runner::'.$call); } } } protected function _loadConfigFromDir(File $directory, $varname = 'cfg') { Logger::getInstance(__CLASS__)->traceStart(); if(!$directory->isDir()) throw new IOException('file is not an directory or does not exist', IOException::IO_NOT_FOUND, $directory); $system = System::getInstance(); ob_start(); foreach($directory->getFiles() as $file) { if(preg_match('#\\.php[0-9]*$#i', $file->getFilename())) { include ($file->getPath()); // echo 'loading config '.$file->getPath(); // check if config variable is set if(isset($$varname) && is_array($$varname)) { foreach($$varname as $key=>$value) $system->setConfig($key, $value); } } } ob_end_clean(); } public function doCleanup() { Logger::getInstance(__CLASS__)->traceStart(); $system = System::getInstance(); $cfg = $system->getConfig('cron'); if(defined('_CRON_') && $cfg['mode'] == 'emulate') { ignore_user_abort(true); set_time_limit(0); $this->runCronJobs(); } else if(!defined('_CRON_') && !empty($cfg['mode']) && $cfg['mode'] == 'emulate') { $time = time(); $lastrun = (int) $system->getSiteParam(0, 'cron', 'lastrun', -1); if($lastrun <= 0 || $time - $lastrun >= 58) { if(function_exists('apache_lookup_uri')) { apache_lookup_uri(_BASEURL_ . '/cron.' . _PHPEXT_); } elseif(extension_loaded('curl')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://" . $_SERVER['HTTP_HOST'] . '/' . _BASEURL_ . '/cron.' . _PHPEXT_); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, true); defined('DEBUG') or ob_start(); curl_exec($ch); defined('DEBUG') or ob_end_clean(); curl_close($ch); } } } Logger::getInstance(__CLASS__)->traceEnd(); } public function doRunCLI() { Logger::getInstance(__CLASS__)->traceStart(); // do noting by default Logger::getInstance(__CLASS__)->traceEnd(); } public function onException(\Exception $e) { Logger::getInstance(__CLASS__)->traceStart(); System::getInstance()->onException($e); // throw to the base system Logger::getInstance(__CLASS__)->traceEnd(); } }