Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/application/Bootstrap.php
2010-09-08 20:17:34 +02:00

245 lines
No EOL
6.3 KiB
PHP

<?php
/**
* Bootstrap this shit
*/
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
/**
* Setup navigaion
*
* @return Zend_Navigation $navigation
*/
protected function _initNav()
{
$this->bootstrap('translate');
$this->bootstrap('view');
$navConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'navigation');
$navigation = new Zend_Navigation($navConfig);
$view = $this->getResource('view');
$view->navigation()->setTranslator($this->getResource('translate'));
$view->navigation($navigation);
return $navigation;
}
/**
* Setup layout
*
* @return Zend_Layout $layout
*/
protected function _initLayout()
{
$layout = Zend_Layout::startMvc();
$layout->setLayoutPath(APPLICATION_PATH . '/modules/default/views/layout');
$layout->setLayout('default');
return $layout;
}
/**
* View and Layout configuration
*
* @return Zend_View $view
*/
protected function _initView()
{
$this->bootstrap('layout');
$view = $this->getResource('layout')->getView();
$view->setEncoding('UTF-8');
// Set site title from application.ini
$config = $this->getApplication()->getOptions();
$view->headTitle($config['app']['name']);
$view->headMeta()->appendHttpEquiv('Content-Type','text/html;charset=utf-8');
// Set helper path
$view->addHelperPath('Fiktiv/View/Helper/', 'Fiktiv_View_Helper');
$view->app = $this->getApplication()->getOption('app');
return $view;
}
/**
* Configure the front controller
*
* @return Zend_Controller_Front $frontController
*/
protected function _initFront()
{
$this->bootstrap('autoloader');
// Get front controller
$frontController = Zend_Controller_Front::getInstance();
// Set modules directory
$frontController->addModuleDirectory(APPLICATION_PATH . '/modules');
// Add plugins
$frontController->registerPlugin(new Fiktiv_Controller_Plugin_Language());
$frontController->registerPlugin(new Fiktiv_Controller_Plugin_Navigation());
return $frontController;
}
/**
* Configure routes for our application
*
* @return Zend_Controller_Router_Rewrite $router
*/
protected function _initRouter()
{
// Make sure the front controller is ready
$this->bootstrap('front');
$router = $this->getResource('front')->getRouter();
$route = new Zend_Controller_Router_Route(
':lang/:module/:controller/:action/*',
array(
'lang' => 'sv',
'module' => 'default',
'controller' => 'index',
'action' => 'index'
),
array(
'lang' => '[a-z]{2}'
)
);
$router->addRoute('default', $route);
return $router;
}
/**
* Configure global and local(modules) models
*/
protected function _initModels()
{
$this->bootstrap('autoloader');
// Include global model directory
set_include_path(implode(PATH_SEPARATOR, array(
APPLICATION_PATH . '/models',
get_include_path()
)));
// Let our model autoloader plugin handle local models
$front = $this->getResource('front');
$front->registerPlugin(new Fiktiv_Controller_Plugin_ModelAutoloader());
}
/**
* Configure autoloader
*
* @return Zend_Loader_Autoloader $autoloader
*/
protected function _initAutoloader()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Fiktiv_');
$autoloader->setFallbackAutoloader(true);
return $autoloader;
}
/**
* Configure multilanguage (translator)
*
* @return Zend_Translate $translate
*/
protected function _initTranslate()
{
$this->bootstrap('autoloader');
$translate = new Fiktiv_Translate(array(
'adapter' => 'Fiktiv_Translate_Adapter_Ini',
'locale' => 'sv',
'content' => APPLICATION_PATH . '/languages/se.ini'
));
$translate->addTranslation(APPLICATION_PATH . '/languages/en.ini', 'en');
Zend_Form::setDefaultTranslator($translate);
Zend_Registry::set('Zend_Translate', $translate);
return $translate;
}
/**
* Setup datastorage
*/
protected function _initDatastorage()
{
$this->bootstrap('autoloader');
// Include datapoints directory
set_include_path(implode(PATH_SEPARATOR, array(
APPLICATION_PATH . '/datastorage',
get_include_path()
)));
}
/**
* Setup a sweet and simple database
* connection.
*
* @return Zend_Db $database
*/
protected function _initDatabase()
{
// Access config for database user/pass ..
$config = $this->getApplication()->getOptions();
// Setup database adapter
$database = Zend_Db::factory('Pdo_Mysql', $config['db']);
// Use the adapter by default
Zend_Db_Table::setDefaultAdapter($database);
/*
* Fire up the data service
* This is not needed as the data service will be
* started when it is first accessed. Also, the
* data service will automaticly load datapoints
* on demand.
*/
$dbLayer = Fiktiv_Data_Service::getInstance();
return $database;
}
/**
* Setup session
*
* @return Zend_Session $session
*/
protected function _initSession()
{
Zend_Session::start();
// TODO: Better name for global session namespace (default namespace)
$defaultNamespace = new Zend_Session_Namespace('global');
return $defaultNamespace;
}
/**
* This is just a temporary.
*
*/
protected function _initOther()
{
// Add action helpers. Maybe should this should be in the frontController setup?
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/../library/Fiktiv/Controller/Action/Helper',
'Fiktiv_Controller_Action_Helper');
}
}