Exemplo n.º 1
0
 /**
  * 解析action过滤链的配置信息
  * 
  * @param WindSimpleController $handler        
  * @return void
  */
 protected function resolveActionFilters(&$handler)
 {
     if (!($filters = $this->getConfig('filters'))) {
         return;
     }
     /* @var $cache AbstractWindCache */
     $_filters = array();
     if ($cache = Wind::getComponent('windCache')) {
         $_filters = $cache->get('filters');
     }
     $_token = $this->handlerAdapter->getModule() . '/' . $this->handlerAdapter->getController() . '/' . $this->handlerAdapter->getAction();
     if (!isset($_filters[$_token])) {
         foreach ($filters as $_filter) {
             if (empty($_filter['class'])) {
                 continue;
             }
             $_pattern = empty($_filter['pattern']) ? '' : $_filter['pattern'];
             unset($_filter['pattern']);
             if ($_pattern) {
                 $_pattern = str_replace(array('*', '/'), array('\\w*', '\\/'), $_pattern);
                 if (in_array($_pattern[0], array('~', '!'))) {
                     $_pattern = substr($_pattern, 1);
                     if (preg_match('/^' . $_pattern . '$/i', $_token)) {
                         continue;
                     }
                 } else {
                     if (!preg_match('/^' . $_pattern . '$/i', $_token)) {
                         continue;
                     }
                 }
             }
             $_filters[$_token][] = $_filter;
         }
         $cache && $cache->set('filters', $_filters);
     }
     if (empty($_filters[$_token])) {
         return;
     }
     /* @var $proxy WindClassProxy */
     $proxy = WindFactory::createInstance(Wind::import('WIND:filter.proxy.WindClassProxy'));
     $proxy->registerTargetObject($handler);
     foreach ($_filters[$_token] as $value) {
         $proxy->registerEventListener($this->factory->createInstance(Wind::import($value['class']), array($handler->getForward(), $handler->getErrorMessage(), $this->handlerAdapter, $value)), 'doAction');
     }
     $handler = $proxy;
 }