Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Company_Application_Bootstrap extends Zend_Application_Bootstrap_Bootstrap
- {
- public function __construct($application)
- {
- $this->setOptions(array(
- 'pluginPaths' => array('Company_Application_Resource' => 'Company/Application/Resource')
- ));
- parent::__construct($application);
- }
- /**
- * This loads the modules directory under the application
- * If adding a module, you should not need to edit this
- */
- protected function _initApplicationModules()
- {
- $frontController = Zend_Controller_Front::getInstance();
- $frontController->addModuleDirectory(APPLICATION_PATH . '/modules');
- }
- /**
- * This loads modules from the Company library
- */
- protected function _initLibraryModules()
- {
- $frontController = Zend_Controller_Front::getInstance();
- $frontController->addModuleDirectory(APPLICATION_PATH . '/../library/Company/modules');
- }
- /**
- * This loads the Company namespace
- */
- protected function _initNamespace()
- {
- $loader = Zend_Loader_Autoloader::getInstance();
- $loader->registerNamespace('Company\\');
- }
- /**
- * This loads library level resources that should run at all times
- */
- protected function _initResources()
- {
- //Build the array of resources to load
- //If the options are present in the application.ini, they will overwrite these defaults
- $resources = array();
- if(APPLICATION_ENV != 'testing')
- {
- $resources['ErrorLogger'] = array(
- 'stream' => array(
- 'writerName' => 'Db',
- 'writerParams' => array(
- 'db' => array(
- 'dbname' => APPLICATION_PATH . '/logs/errorLog.sqlite'
- )
- )
- )
- );
- }
- $resources['frontController'] = array(
- 'actionHelperPaths' => array(
- 'Helper' => APPLICATION_PATH . '/helpers'
- ),
- 'params' => array(
- 'displayExceptions' => 0
- )
- );
- $resources['layout'] = array(
- 'layoutPath' => APPLICATION_PATH . '/layouts/scripts'
- );
- //This simply forces the Zend view and module resources to be loaded
- $resources['view'] = array();
- $resources['modules'] = array();
- $app = $this->getApplication();
- $resourceConfigs = $app->getOption('resources');
- //Register and bootstrap each resource
- foreach(array('register', 'bootstrap') as $action)
- {
- foreach($resources as $resourceName => $resourceOptions)
- {
- if($action == 'register')
- {
- if(isset($resourceConfigs[$resourceName]))
- {
- $resourceOptions = $this->mergeResourceOptions($resourceConfigs[$resourceName], $resourceOptions);
- }
- if($this->hasPluginResource($resourceName))
- {
- $this->getPluginResource($resourceName)->setOptions($resourceOptions);
- }
- else
- {
- $this->registerPluginResource($resourceName, $resourceOptions);
- }
- }
- elseif($action == 'bootstrap')
- {
- $app->bootstrap($resourceName);
- }
- }
- }
- }
- public function mergeResourceOptions($a, $b)
- {
- foreach($a as $optionName => $optionValue)
- {
- if(is_int($optionName))
- {
- $b[] = $optionValue;
- }
- else
- {
- if(is_array($optionValue) && isset($b[$optionName]))
- {
- $b[$optionName] = $this->mergeResourceOptions($optionValue, $b[$optionName]);
- }
- else
- {
- $b[$optionName] = $optionValue;
- }
- }
- }
- return $b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement