Esempio n. 1
0
 /**
  * Invalid link handler. Descendant can override this method to change default behaviour.
  * @param  InvalidLinkException
  * @return string
  * @throws InvalidLinkException
  */
 protected function handleInvalidLink($e)
 {
     if (self::$invalidLinkMode === NULL) {
         self::$invalidLinkMode = Environment::isProduction() ? self::INVALID_LINK_SILENT : self::INVALID_LINK_WARNING;
     }
     if (self::$invalidLinkMode === self::INVALID_LINK_SILENT) {
         return '#';
     } elseif (self::$invalidLinkMode === self::INVALID_LINK_WARNING) {
         return 'error: ' . htmlSpecialChars($e->getMessage());
     } else {
         // self::INVALID_LINK_EXCEPTION
         throw $e;
     }
 }
Esempio n. 2
0
$loader->register();
/** 2e) load extension methods */
if (is_file(APP_DIR . '/extensions.php')) {
    include_once APP_DIR . '/extensions.php';
}
/** 2f) enable DebugBar */
if ($mode == Debug::DEVELOPMENT) {
    Debug::$showBar = TRUE;
}
/** 2g) Session setup [optional] */
if (Environment::getVariable('sessionDir') !== NULL && !is_writable(Environment::getVariable('sessionDir'))) {
    die("Make directory '" . realpath(Environment::getVariable('sessionDir')) . "' writable!");
}
$session = Environment::getSession();
$session->setSavePath(Environment::getVariable('sessionDir'));
// Step 3: Configure application
/** 3a) Setup Application, ErrorPresenter & exceptions catching */
$application = Environment::getApplication();
Presenter::$invalidLinkMode = Environment::isProduction() ? Presenter::INVALID_LINK_SILENT : Presenter::INVALID_LINK_EXCEPTION;
Environment::setVariable('host', Environment::getHttpRequest()->getUri()->host);
/** 3b) establish database connection and initialize services */
$application->onStartup[] = 'Services::initialize';
$application->onStartup[] = 'BaseModel::initialize';
$application->onShutdown[] = 'BaseModel::disconnect';
// Step 4: Setup application router
$router = $application->getRouter();
$router[] = new Route('index.php', array('presenter' => 'Example', 'action' => 'default'), Route::ONE_WAY);
$router[] = new Route('<presenter>/<action>/', array('presenter' => 'Example', 'action' => 'default'));
$router[] = new SimpleRouter('Example:default');
// Step 5: Run the application!
$application->run();