/** * Invokes the startup methods just for framework extensions so other parties can take over execution. */ public static function run() { Request::init(); // determine active application $tSelectedApplication = null; foreach (self::$applications as $tApplication) { if (count($tApplication['endpoints']) > 0) { foreach ($tApplication['endpoints'] as $tEndpoint) { foreach ((array) $tEndpoint['address'] as $tEndpointAddress) { if (Request::matchesHostname($tEndpointAddress)) { $tSelectedApplication = $tApplication; break 3; } } } } else { $tSelectedApplication = $tApplication; break; } } // construct application object if ($tSelectedApplication !== null) { self::$application = new Application($tSelectedApplication['namespace'], $tSelectedApplication['directory']); } // load configuration w/ extensions Config::$default = Config::load(); // include files foreach (Config::get('includeList', array()) as $tInclude) { $tIncludePath = pathinfo(Io::translatePath($tInclude)); $tFiles = Io::glob($tIncludePath['dirname'] . '/', $tIncludePath['basename'], Io::GLOB_FILES); if ($tFiles !== false) { foreach ($tFiles as $tFilename) { //! todo require_once? include $tFilename; } } } // loadClass classes foreach (Config::get('loadClassList', array()) as $tClass) { class_exists($tClass, true); } // events foreach (Config::get('eventList', array()) as $tLoad) { if ($tLoad['name'] === 'load') { Events::invokeSingle(array($tLoad['type'], $tLoad['value'])); continue; } Events::register($tLoad['name'], $tLoad['type'], $tLoad['value']); } Request::setRoutes(); // output handling ob_start('Scabbia\\Framework::output'); ob_implicit_flush(false); try { // run extensions $tParms = array(); Events::invoke('pre-run', $tParms); // ignite application if ($tSelectedApplication !== null) { self::$application->before->invoke(); $tReturn = self::$application->callbacks->invoke(); self::$application->after->invoke(); if (self::$application->otherwise !== null && $tReturn !== false) { call_user_func(self::$application->otherwise); return false; } } } catch (CustomException $ex) { if ($tSelectedApplication !== null) { call_user_func(self::$application->onError, $ex->type, $ex->title, $ex->getMessage()); } return false; } return true; }