<?php
define( 'ROOT', dirname( dirname( __FILE__ ) ) );
set_include_path(
'.'
. PATH_SEPARATOR . ROOT
. PATH_SEPARATOR . ROOT . '/application/default'
. PATH_SEPARATOR . ROOT . '/library'
. PATH_SEPARATOR . ROOT . '/models'
. PATH_SEPARATOR . ROOT . '/models/handlers'
. PATH_SEPARATOR . '/usr/share/php/Zend/library'
. PATH_SEPARATOR . '/usr/share/php/Doctrine/lib'
);
require_once 'Zend/Controller/Plugin/Abstract.php';
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Controller/Request/Abstract.php';
require_once 'Zend/Controller/Action/HelperBroker.php';
class Initializer extends Zend_Controller_Plugin_Abstract
{
protected static $_config;
protected $_env;
protected $_front;
protected $_root;
public function __construct($env, $root = null)
{
$this->_setEnv($env);
if (null === $root) {
$root = realpath(dirname(__FILE__) . '/../');
}
$this->_root = $root;
$this->initPhpConfig();
$this->_front = Zend_Controller_Front::getInstance();
date_default_timezone_set( 'UTC' );
if ( $env == 'test') {
error_reporting(E_ALL | E_STRICT);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
$this->_front->throwExceptions(true);
}
$configFile = dirname( __FILE__ ) . '/config.xml';
require_once 'Zend/Config/Xml.php';
self::$_config = new Zend_Config_Xml( $configFile, $this->_env );
require_once 'Zend/Registry.php';
Zend_Registry::set( 'Config', self::$_config );
}
protected function _setEnv($env)
{
$this->_env = $env;
}
public function initPhpConfig()
{
}
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$this->initApp();
$this->initDb();
$this->initHelpers();
$this->initView();
$this->initPlugins();
$this->initRoutes();
$this->initControllers();
}
public function initApp()
{
}
public function initDb()
{
require_once 'Doctrine.php';
spl_autoload_register( array( 'Doctrine', 'autoload' ) );
Doctrine_Manager::connection( self::$_config->db->dsn );
foreach( self::$_config->db->attributes as $key => $value ) {
Doctrine_Manager::getInstance()->setAttribute( $key, $value );
}
Doctrine::loadModels( array(
dirname( dirname( __FILE__ ) ) .'/models'
) );
}
public function initHelpers()
{
Zend_Controller_Action_HelperBroker::addPath(
'../application/default/helpers',
'Zend_Controller_Action_Helper'
);
}
public function initView()
{
$layout = Zend_Layout::startMvc(array(
'layoutPath' => $this->_root . '/application/default/layouts',
'layout' => 'main'
));
$view = $layout->getView()
->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
Zend_Dojo::enableView( $view );
}
public function initPlugins()
{
$this->_front->setDefaultModule( 'default' );
}
public function initRoutes()
{
}
public function initControllers()
{
$this->_front->addControllerDirectory($this->_root . '/application/default/controllers', 'default');
}
}