/** * Dispatches a request to the action of a controller * @param Request $request The request to dispatch * @param Response $response The response to dispatch the request to * @return mixed The return value of the action * @throws zibo\ZiboException when the action is not invokable */ public function dispatch(Request $request, Response $response) { $controller = $this->getController($request); $actionName = $request->getActionName(); $parameters = $request->getParameters(); $callback = $this->processAction($controller, $actionName, $parameters); $this->prepareController($controller, $request, $response, $actionName, $parameters); $this->zibo->triggerEvent(self::EVENT_PRE_DISPATCH, $controller, $actionName, $parameters); $controller->preAction(); $returnValue = $callback->invokeWithArrayArguments($parameters); $controller->postAction(); $this->zibo->triggerEvent(self::EVENT_POST_DISPATCH, $controller, $actionName, $parameters); return $returnValue; }
$zibo = new Zibo($fileBrowser, $configIO); $zibo->setEnvironment($environment); $zibo->setDefaultTimeZone('Europe/Brussels'); $zibo->setDefaultLocale(array('en_IE.utf8', 'en_IE', 'en')); // run Zibo $zibo->bootModules(); $zibo->main(); } catch (Exception $exception) { // uncaught exception $class = get_class($exception); $message = $exception->getMessage(); $trace = $exception->getTraceAsString(); // try to log the exception try { if (isset($zibo)) { $zibo->triggerEvent(Zibo::EVENT_LOG, $class . ($message ? ': ' . $message : ''), $trace); } } catch (Exception $e) { } $title = 'Uncaught exception (' . $class . ')' . ($message ? ': ' . $message : ''); if (php_sapi_name() == 'cli') { echo "\n" . $title . "\n\n" . $trace; exit; } $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; header($protocol . ' 500'); echo '<div style="background-color: #fdf5d9; padding: 14px; border: 1px solid #fceec1; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; color: #404040; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);">'; echo '<strong>' . $title . '</strong>'; echo '<pre>' . $trace . '</pre>'; echo '</div>'; }
/** * @expectedException zibo\ZiboException */ public function testTriggerEventThrowsExceptionWhenSystemEventNameIsPassed() { $zibo = new Zibo($this->getBrowserMock(), $this->getConfigIOMock()); $zibo->triggerEvent(Zibo::EVENT_PRE_ROUTE); }
/** * Loads the database connections from the Zibo configuration * @param zibo\core\Zibo $zibo Instance of Zibo * @return null * @throws zibo\library\database\exception\DatabaseException when the configuration contains an invalid connection * @throws zibo\library\database\exception\DatabaseException when the default connection does not exist */ private function loadConnectionsFromConfig(Zibo $zibo) { $zibo->triggerEvent(Zibo::EVENT_LOG, 'Loading database connections', '', 0, self::LOG_NAME); $connections = $zibo->getConfigValue(self::CONFIG_CONNECTION, array()); if (!is_array($connections)) { $connections = array(self::NAME_DEFAULT => $connections); } $defaultConnectionName = null; foreach ($connections as $name => $dsn) { if ($name == self::NAME_DEFAULT) { $defaultConnectionName = $name; } try { $dsn = new Dsn($dsn); $this->registerConnection($name, $dsn); } catch (DatabaseException $e) { if ($name == self::NAME_DEFAULT) { $defaultConnectionName = $dsn; } else { throw $e; } } } if ($defaultConnectionName != null) { $this->setDefaultConnectionName($defaultConnectionName); } }