Last active
December 20, 2015 03:49
-
-
Save naeluh/6066572 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
set_include_path('.' . PATH_SEPARATOR . | |
'WEB-INF/library' . PATH_SEPARATOR . | |
'WEB-INF/cms/portal/models/' . PATH_SEPARATOR . | |
get_include_path() | |
); | |
require_once 'Initializer.php'; | |
// Prepare the front controller. | |
$frontController = Zend_Controller_Front::getInstance(); | |
// Change to 'production' parameter under production environemtn | |
$frontController->registerPlugin(new Initializer('dev')); | |
$frontController->throwExceptions(false); | |
// Dispatch the request using the front controller. | |
$frontController->dispatch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'WEB-INF/cms/bootstrap.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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'; | |
require_once "Zend/Loader/Autoloader.php"; | |
require_once "Zend/Config.php"; | |
require_once "Zend/Db.php"; | |
require_once 'functions.php'; | |
require_once 'CMS.php'; | |
/** | |
* | |
* Initializes configuration depndeing on the type of environment | |
* (test, development, production, etc.) | |
* | |
* This can be used to configure environment variables, databases, | |
* layouts, routers, helpers and more | |
* | |
*/ | |
class Initializer extends Zend_Controller_Plugin_Abstract | |
{ | |
/** | |
* @var Zend_Config | |
*/ | |
protected static $_config; | |
/** | |
* @var string Current environment | |
*/ | |
protected $_env; | |
/** | |
* @var Zend_Controller_Front | |
*/ | |
protected $_front; | |
/** | |
* @var string Path to application root | |
*/ | |
protected $_root; | |
/** | |
* Constructor | |
* | |
* Initialize environment, root path, and configuration. | |
* | |
* @param string $env | |
* @param string|null $root | |
* @return void | |
*/ | |
public function __construct($env, $root = null) | |
{ | |
$this->_setEnv($env); | |
if (null === $root) { | |
$root = realpath(dirname(__FILE__) . '/../..'); | |
} | |
$this->_root = $root; | |
$this->initConfig(); | |
$this->_front = Zend_Controller_Front::getInstance(); | |
// set the test environment parameters | |
if ($env == 'dev') { | |
// Enable all errors so we'll know when something goes wrong. | |
error_reporting(E_ALL | E_STRICT); | |
ini_set('display_startup_errors', 1); | |
ini_set('display_errors', 1); | |
$this->_front->throwExceptions(true); | |
} | |
// Set up autoload. | |
Zend_Loader_Autoloader::getInstance() | |
->registerNamespace('CMS') | |
->setFallbackAutoloader(true); | |
} | |
/** | |
* Initialize environment | |
* | |
* @param string $env | |
* @return void | |
*/ | |
protected function _setEnv($env) | |
{ | |
$this->_env = $env; | |
} | |
/** | |
* Initialize Config | |
* | |
* @return void | |
*/ | |
public function initConfig() | |
{ | |
//todo: cache config in APC if necessary | |
self::$_config = include 'WEB-INF/config/config.php'; | |
CMS::init($this->_root, self::$_config); | |
} | |
/** | |
* Route startup | |
* | |
* @return void | |
*/ | |
public function routeStartup(Zend_Controller_Request_Abstract $request) | |
{ | |
$this->initDb(); | |
$this->initHelpers(); | |
$this->initView(); | |
$this->initPlugins(); | |
$this->initRoutes(); | |
$this->initControllers(); | |
} | |
/** | |
* Initialize data bases | |
* | |
* @return void | |
*/ | |
public function initDb() | |
{ | |
CMS::initDb(); | |
} | |
/** | |
* Initialize action helpers | |
* | |
* @return void | |
*/ | |
public function initHelpers() | |
{ | |
// register the default action helpers | |
Zend_Controller_Action_HelperBroker::addPath('../cms/portal/helpers', 'Zend_Controller_Action_Helper'); | |
Zend_Controller_Action_HelperBroker::addHelper(new CMS_Helper_ViewRenderer()); | |
} | |
/** | |
* Initialize view | |
* | |
* @return void | |
*/ | |
public function initView() | |
{ | |
// Bootstrap layouts | |
$options = self::$_config->layouts->options->toArray(); | |
Zend_Layout::startMvc($options); | |
} | |
/** | |
* Initialize plugins | |
* | |
* @return void | |
*/ | |
public function initPlugins() | |
{ | |
} | |
/** | |
* Initialize routes | |
* | |
* @return void | |
*/ | |
public function initRoutes() | |
{ | |
$this->_front->getRouter()->addConfig(self::$_config, 'routes'); | |
} | |
/** | |
* Initialize Controller paths | |
* | |
* @return void | |
*/ | |
public function initControllers() | |
{ | |
$this->_front->setControllerDirectory(self::$_config->controllers->toArray()); | |
$this->_front->setDefaultModule(self::$_config->default_module); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment