/** * @return void * @uses \Event * @uses \EventHandler * @uses \DI * @uses \DataFilter * @todo get teacher for mysql in GlobalEvents for Crontab */ public static function startup() { $cronevent = new \Event('cron.run'); $cronevent->call(function () { // do something }); \EventHandler::attach($cronevent); $cronevent = new \Event('crontab.run.untis'); $cronevent->call(function () { //do something }); \EventHandler::attach($cronevent); }
/** * get started with all this * @return void * @todo template-map */ public static function startup() { $activeTemplate = new Template(app::get('template')); $gettext = new Gettext(HOME_DIR . '/locale/' . app::get('language') . '.mo'); if ($activeTemplate->translated) { Gettext::addTranslation(HOME_DIR . '/templates/' . app::get('template') . '/locale/' . app::get('language') . '.mo'); } require_once HOME_DIR . '/translate_functions.php'; if (isset($activeTemplate->map)) { foreach ($activeTemplate->map as $map) { Route::get("/{$map}/[fn:filename]", "AssetsController.everything")->name($map); } } // add your routes here! Route::get('/^\\s*$/', 'IndexController.get', true); Route::get('/test/stack', 'TestController.stack'); Route::get('/css/[fn:filename]', 'AssetsController.css'); Route::get('/js/[fn:filename]', 'AssetsController.js'); Modules::loadModuleList(); Modules::loadModules(); //$msqlo = new MySQLi(app::get('mysql')->host, app::get('mysql')->user, app::get('mysql')->password, app::get('mysql')->database); //\DI::addInstance($msqlo); $modelob = new \Observer\ModelObserver(); \DI::addInstance($modelob); $etagevent = new \Event('etag.change'); $etagevent->call(function ($newval) { \Kernel::$response->etag = md5(\Kernel::$response->etag . '|' . $newval); }); \EventHandler::attach($etagevent); Route::registerNotFoundAction('/', function () { \Kernel::$response->errorCode(404); (new \Controller())->view('error', ['error' => ['code' => '404', 'text' => 'Not found!']]); }); Route::registerNotFoundAction('/api/', function () { throw new \HTTPException\ObjectNotFoundException(404, "Requested resource not found!"); }); }
public function init() { if (!$this->enabled) { return; } if ($this->fixScriptName) { $scriptName = php_sapi_name() === 'cli' ? implode(' ', $_SERVER['argv']) : '/' . \Yii::app()->urlManager->parseUrl(\Yii::app()->request); $this->setScriptName($scriptName); } $eventHandler = new EventHandler(); $eventHandler->attach(\Yii::app(), 'request', 'onBeginRequest', 'onEndRequest'); foreach ($this->profileEvents as $event) { if (is_string($event[0])) { $event[0] = \Yii::app()->getComponent($event[0]); } if (!$event[0] instanceof \CComponent) { throw new \InvalidArgumentException(var_export($event[0], true) . ' is not string or instance of CComponent'); } call_user_func_array([$eventHandler, 'attach'], $event); } \Yii::app()->attachEventHandler('onEndRequest', function () { Timer::stopAll(); }); }