Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Ez_Application_Module_Bootstrap extends Zend_Application_Module_Bootstrap
- {
- /**
- *
- * @var Zend_Acl
- */
- protected $_acl;
- /**
- * Load configuration file of module
- *
- * @return Zend_Config_Ini
- * @throws Zend_Config_Exception if file not found
- */
- protected function _initConfig()
- {
- $options = $this->getApplication()->getOptions();
- $moduleDir = $options['resources']['frontController']['moduleDirectory'];
- $pathToIni = $moduleDir . DIRECTORY_SEPARATOR . strtolower($this->_moduleName) . '/configs/module.ini';
- $config = new Zend_Config_Ini($pathToIni, APPLICATION_ENV);
- $this->_application->setOptions($config->toArray());
- Zend_Registry::set('config', new Zend_Config($this->_application->getOptions()));
- return $config;
- }
- /**
- *
- * @return Zend_Acl
- * @throws Zend_Application_Bootstrap_Exception
- */
- protected function _initAcl()
- {
- // Configuration automatique des acls via le fichier de config du module
- $options = $this->getApplication()->getOptions();
- $this->_acl = $this->_application->bootstrap('acl')->getResource('acl');
- $className = ($this->_moduleName != 'Default' ? $this->_moduleName . '_' : '') . 'Config_Acl';
- $moduleName = strtolower($this->_moduleName);
- // La ressource existe-t-elle en acl?
- if (!$this->_acl->has($moduleName)) {
- // Création de la ressource principale
- $this->_acl->addResource($moduleName);
- // Recherche d'un fichier de config dans le module
- if (method_exists($className, 'getResourcesDef')) {
- $resourcesDef = call_user_func(array($className, 'getResourcesDef'));
- if (!isset($resourcesDef['resources'])) {
- throw new Zend_Application_Bootstrap_Exception("Missing 'resources' parameter in {$className}::getResourcesDef()");
- }
- if (!is_array($resourcesDef['resources'])) {
- throw new Zend_Application_Bootstrap_Exception("'resource' parameter has to be an array");
- }
- // Ajout des ressources en acl
- foreach ($resourcesDef['resources'] as $mode => $resources) {
- foreach ($resources as $controllers => $actions) {
- // Groupement de controllers
- $controllers = explode('+', $controllers);
- foreach ($controllers as $controller) {
- $resource = $moduleName . '_' . $mode . '_' . $controller;
- if (!$this->_acl->has($resource)) {
- $this->_acl->addResource($resource);
- }
- // On desactive les acls sur tout le controller
- if ($actions === 'disabled') {
- $this->_acl->allow('user', $resource);
- } elseif (is_array($actions)) {
- foreach ($actions as $action=>$description) {
- // On desactive les acls sur une seule action du controller
- if ($description === 'disabled') {
- $this->_acl->allow('user', $resource, $action);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- /**
- *
- * @return array Menu for the current module
- */
- protected function _initMenu()
- {
- $this->_application->bootstrap('acl');
- $this->_application->bootstrap('translate');
- $view = $this->_application->bootstrap('view')->getResource('view');
- $className = ($this->_moduleName != 'Default' ? $this->_moduleName . '_' : '') . 'Config_Menu';
- $moduleName = strtolower($this->_moduleName);
- $methodName = Zend_Registry::get('ADMIN') ? 'getBackend' : 'getFrontend';
- if (method_exists($className, $methodName)) {
- $view->menu->addPage(call_user_func(array($className, $methodName)));
- }
- return $view->menu;
- }
- }
Add Comment
Please, Sign In to add comment