*/ class Module implements AutoloaderProviderInterface, BootstrapListenerInterface, ConfigProviderInterface, ControllerPluginProviderInterface, ViewHelperProviderInterface { /** * {@inheritDoc} */ public function onBootstrap(EventInterface $event) { /* @var $app \Zend\Mvc\ApplicationInterface */ $app = $event->getTarget(); /* @var $sm \Zend\ServiceManager\ServiceLocatorInterface */ $serviceManager = $app->getServiceManager(); //fatiha //$match = $event->getRouteMatch(); //$routeName = $match->getMatchedRouteName(); //fin fth $config = $serviceManager->get('BjyAuthorize\Config'); $strategy = $serviceManager->get($config['unauthorized_strategy']); $guards = $serviceManager->get('BjyAuthorize\Guards'); $authorize = $serviceManager->get('BjyAuthorize\Provider\Identity\ProviderInterface'); $roles = $authorize->getIdentityRoles(); $roleId = !empty($roles)?$roles[0]:'guest'; //fth $tableObj = new Tables('modules',$serviceManager->get('Zend\Db\Adapter\Adapter')); $select = $tableObj->getTable()->getSql()->select(); $select->join('modules_role', 'modules_role.idModule = modules.id'); $select->where(array('modules_role.idRole' => $roleId)); $rows = $tableObj->getTable()->selectWith($select); $allow = true; $myGuards = array(); //echo $routeName."

"; if($roleId != "guest" && $roleId != "user"){ $allow = false; foreach ($rows as $r){ if($r->droit == 'R' || $r->droit == 'W'){ $myGuards[] = array( 'controller'=>$r->controller, 'roles' => array($roleId), ); } $dbRoute = "zfcadmin/".$r->route; $droit = $r->droit; //echo $dbRoute." -- ".$droit."
"; /*if($routeName == 'zfcadmin'){ $allow = true; } if($routeName == $dbRoute && $droit!="X"){ $allow = true; }*/ } //var_dump($allow); //$config['guards']['BjyAuthorize\Guard\Controller'] = $myGuards; //exit(); } //fin fth foreach ($guards as $guard) { //print_r($guard);exit(); //$guard= new \BjyAuthorize\Guard\Controller($myGuards, $serviceManager); $app->getEventManager()->attach($guard); } $app->getEventManager()->attach($strategy); //exit(); } /** * {@inheritDoc} */ public function getViewHelperConfig() { return array( 'factories' => array( 'isAllowed' => function (AbstractPluginManager $pluginManager) { $serviceLocator = $pluginManager->getServiceLocator(); /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $serviceLocator->get('BjyAuthorize\Service\Authorize'); return new View\Helper\IsAllowed($authorize); } ), ); } /** * {@inheritDoc} */ public function getControllerPluginConfig() { return array( 'factories' => array( 'isAllowed' => function (AbstractPluginManager $pluginManager) { $serviceLocator = $pluginManager->getServiceLocator(); /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $serviceLocator->get('BjyAuthorize\Service\Authorize'); return new Controller\Plugin\IsAllowed($authorize); } ), ); } /** * {@inheritDoc} */ public function getAutoloaderConfig() { return array( 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/../../src/' . __NAMESPACE__, ), ), ); } /** * {@inheritDoc} */ public function getConfig() { return include __DIR__ . '/../../config/module.config.php'; } }