Advertisement
tubaguy50035

Bootstrap.php

Oct 17th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. class Company_Application_Bootstrap extends Zend_Application_Bootstrap_Bootstrap
  2. {
  3.     public function __construct($application)
  4.     {
  5.         $this->setOptions(array(
  6.             'pluginPaths' => array('Company_Application_Resource' => 'Company/Application/Resource')
  7.         ));
  8.         parent::__construct($application);
  9.     }
  10.  
  11.     /**
  12.      * This loads the modules directory under the application
  13.      * If adding a module, you should not need to edit this
  14.      */
  15.     protected function _initApplicationModules()
  16.     {
  17.         $frontController = Zend_Controller_Front::getInstance();
  18.         $frontController->addModuleDirectory(APPLICATION_PATH . '/modules');
  19.     }
  20.  
  21.     /**
  22.      * This loads modules from the Company library
  23.      */
  24.     protected function _initLibraryModules()
  25.     {
  26.         $frontController = Zend_Controller_Front::getInstance();
  27.         $frontController->addModuleDirectory(APPLICATION_PATH . '/../library/Company/modules');
  28.     }
  29.  
  30.     /**
  31.      * This loads the Company namespace
  32.      */
  33.     protected function _initNamespace()
  34.     {
  35.         $loader = Zend_Loader_Autoloader::getInstance();
  36.         $loader->registerNamespace('Company\\');
  37.     }
  38.  
  39.     /**
  40.      * This loads library level resources that should run at all times
  41.      */
  42.     protected function _initResources()
  43.     {
  44.         //Build the array of resources to load
  45.         //If the options are present in the application.ini, they will overwrite these defaults
  46.         $resources = array();
  47.         if(APPLICATION_ENV != 'testing')
  48.         {
  49.             $resources['ErrorLogger'] = array(
  50.                 'stream' => array(
  51.                     'writerName' => 'Db',
  52.                     'writerParams' => array(
  53.                         'db' => array(
  54.                             'dbname' => APPLICATION_PATH . '/logs/errorLog.sqlite'
  55.                         )
  56.                     )
  57.                 )
  58.             );
  59.         }
  60.         $resources['frontController'] = array(
  61.             'actionHelperPaths' => array(
  62.                 'Helper' => APPLICATION_PATH . '/helpers'
  63.             ),
  64.             'params' => array(
  65.                 'displayExceptions' => 0
  66.             )
  67.         );
  68.         $resources['layout'] = array(
  69.             'layoutPath' => APPLICATION_PATH . '/layouts/scripts'
  70.         );
  71.         //This simply forces the Zend view and module resources to be loaded
  72.         $resources['view'] = array();
  73.         $resources['modules'] = array();
  74.  
  75.         $app = $this->getApplication();
  76.         $resourceConfigs = $app->getOption('resources');
  77.         //Register and bootstrap each resource
  78.         foreach(array('register', 'bootstrap') as $action)
  79.         {
  80.             foreach($resources as $resourceName => $resourceOptions)
  81.             {
  82.                 if($action == 'register')
  83.                 {
  84.                     if(isset($resourceConfigs[$resourceName]))
  85.                     {
  86.                         $resourceOptions = $this->mergeResourceOptions($resourceConfigs[$resourceName], $resourceOptions);
  87.                     }
  88.                     if($this->hasPluginResource($resourceName))
  89.                     {
  90.                         $this->getPluginResource($resourceName)->setOptions($resourceOptions);
  91.                     }
  92.                     else
  93.                     {
  94.                         $this->registerPluginResource($resourceName, $resourceOptions);
  95.                     }
  96.                 }
  97.                 elseif($action == 'bootstrap')
  98.                 {
  99.                     $app->bootstrap($resourceName);
  100.                 }
  101.             }
  102.         }
  103.     }
  104.  
  105.     public function mergeResourceOptions($a, $b)
  106.     {
  107.         foreach($a as $optionName => $optionValue)
  108.         {
  109.             if(is_int($optionName))
  110.             {
  111.                 $b[] = $optionValue;
  112.             }
  113.             else
  114.             {
  115.                 if(is_array($optionValue) && isset($b[$optionName]))
  116.                 {
  117.                     $b[$optionName] = $this->mergeResourceOptions($optionValue, $b[$optionName]);
  118.                 }
  119.                 else
  120.                 {
  121.                     $b[$optionName] = $optionValue;
  122.                 }
  123.             }
  124.         }
  125.         return $b;
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement