Guest User

Untitled

a guest
May 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.36 KB | None | 0 0
  1. <?php
  2. class Ez_Application_Module_Bootstrap extends Zend_Application_Module_Bootstrap
  3. {
  4.  
  5.     /**
  6.      *
  7.      * @var Zend_Acl
  8.      */
  9.     protected $_acl;
  10.  
  11.     /**
  12.      * Load configuration file of module
  13.      *
  14.      * @return Zend_Config_Ini
  15.      * @throws Zend_Config_Exception if file not found
  16.      */
  17.     protected function _initConfig()
  18.     {
  19.         $options = $this->getApplication()->getOptions();
  20.         $moduleDir = $options['resources']['frontController']['moduleDirectory'];
  21.         $pathToIni = $moduleDir . DIRECTORY_SEPARATOR . strtolower($this->_moduleName) . '/configs/module.ini';
  22.         $config = new Zend_Config_Ini($pathToIni, APPLICATION_ENV);
  23.         $this->_application->setOptions($config->toArray());
  24.         Zend_Registry::set('config', new Zend_Config($this->_application->getOptions()));
  25.         return $config;
  26.     }
  27.  
  28.     /**
  29.      *
  30.      * @return Zend_Acl
  31.      * @throws Zend_Application_Bootstrap_Exception
  32.      */
  33.     protected function _initAcl()
  34.     {
  35.         // Configuration automatique des acls via le fichier de config du module
  36.         $options = $this->getApplication()->getOptions();
  37.         $this->_acl = $this->_application->bootstrap('acl')->getResource('acl');
  38.  
  39.         $className = ($this->_moduleName != 'Default' ? $this->_moduleName . '_' : '') . 'Config_Acl';
  40.         $moduleName = strtolower($this->_moduleName);
  41.  
  42.         // La ressource existe-t-elle en acl?
  43.         if (!$this->_acl->has($moduleName)) {
  44.             //  Création de la ressource principale
  45.             $this->_acl->addResource($moduleName);
  46.  
  47.             // Recherche d'un fichier de config dans le module
  48.             if (method_exists($className, 'getResourcesDef')) {
  49.  
  50.                 $resourcesDef = call_user_func(array($className, 'getResourcesDef'));
  51.  
  52.                 if (!isset($resourcesDef['resources'])) {
  53.                     throw new Zend_Application_Bootstrap_Exception("Missing 'resources' parameter in {$className}::getResourcesDef()");
  54.                 }
  55.  
  56.                 if (!is_array($resourcesDef['resources'])) {
  57.                     throw new Zend_Application_Bootstrap_Exception("'resource' parameter has to be an array");
  58.                 }
  59.  
  60.                 // Ajout des ressources en acl
  61.                 foreach ($resourcesDef['resources'] as $mode => $resources) {
  62.                     foreach ($resources as $controllers => $actions) {
  63.  
  64.                         // Groupement de controllers
  65.                         $controllers = explode('+', $controllers);
  66.                         foreach ($controllers as $controller) {
  67.  
  68.                             $resource = $moduleName . '_' . $mode . '_' . $controller;
  69.                             if (!$this->_acl->has($resource)) {
  70.                                 $this->_acl->addResource($resource);
  71.                             }
  72.                            
  73.                             // On desactive les acls sur tout le controller
  74.                             if ($actions === 'disabled') {
  75.                                 $this->_acl->allow('user', $resource);
  76.                             } elseif (is_array($actions)) {
  77.                                 foreach ($actions as $action=>$description) {
  78.                                     // On desactive les acls sur une seule action du controller
  79.                                     if ($description === 'disabled') {
  80.                                         $this->_acl->allow('user', $resource, $action);
  81.                                     }
  82.                                 }
  83.                             }
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.     }
  90.  
  91.     /**
  92.      *
  93.      * @return array Menu for the current module
  94.      */
  95.     protected function _initMenu()
  96.     {
  97.         $this->_application->bootstrap('acl');
  98.         $this->_application->bootstrap('translate');
  99.         $view = $this->_application->bootstrap('view')->getResource('view');
  100.  
  101.         $className = ($this->_moduleName != 'Default' ? $this->_moduleName . '_' : '') . 'Config_Menu';
  102.         $moduleName = strtolower($this->_moduleName);
  103.         $methodName = Zend_Registry::get('ADMIN') ? 'getBackend' : 'getFrontend';
  104.  
  105.         if (method_exists($className, $methodName)) {
  106.             $view->menu->addPage(call_user_func(array($className, $methodName)));
  107.         }
  108.  
  109.         return $view->menu;
  110.     }
  111. }
Add Comment
Please, Sign In to add comment