Example #1
0
    $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
    $view->registerEngines(['.volt' => function () use($view, $config) {
        $volt = new Volt($view);
        $volt->setOptions(['compiledPath' => $config->application->view->compiledPath, 'compiledSeparator' => $config->application->view->compiledSeparator, 'compiledExtension' => $config->application->view->compiledExtension, 'compileAlways' => $config->application->debug]);
        $compiler = $volt->getCompiler();
        $compiler->addExtension(new \Phanbook\Tools\VoltFunctions());
        return $volt;
    }]);
    // Attach a listener for type 'view'
    $eventsManager->attach('view', function ($event, $view) {
        if ($event->getType() == 'notFoundView') {
            throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')');
        }
    });
    // Bind the eventsManager to the view component
    $view->setEventsManager($eventsManager);
    return $view;
});
// Register the flash service with custom CSS classes
$di->set('flashSession', function () {
    $flash = new Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning']);
    return $flash;
});
// Database connection is created based in the parameters defined in the configuration file
$di->set('db', function () use($di) {
    return new Mysql(['host' => $di->get('config')->database->mysql->host, 'username' => $di->get('config')->database->mysql->username, 'password' => $di->get('config')->database->mysql->password, 'dbname' => $di->get('config')->database->mysql->dbname, 'options' => [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $di->get('config')->database->mysql->charset]]);
}, true);
$di->set('cookies', function () {
    $cookies = new Cookies();
    $cookies->useEncryption(false);
    return $cookies;