Пример #1
0
 /**
  * 获得指定扩展点的全部扩展调用
  * 
  * 过滤当前挂在的所有{@see $filters},根据filter的表达式定义过滤当前需要被执行的所有filter,
  * 并返回.该方法在{@see PwBaseController::runHook}中被使用.当前表达式参数解析支持,
  * <i>request,service(PwBaseHookService)</i>{@example <code>
  * 例如: 'expression' => 'special.get==1'
  * 则该该方法会去判断request,get请求中的special的值是否等于1,
  * 如果为true则注册该过滤器,如果为false则不注册该过滤器,当expression不定义时,
  * 则认为在任何条件下都注册该过滤器.
  * </code>}
  * @param array $filters
  * @param PwBaseHookService $service
  * @return array
  */
 public static function resolveActionHook($filters, $service = null)
 {
     $_filters = array();
     foreach ((array) $filters as $filter) {
         if (empty($filter['class'])) {
             continue;
         }
         if (!is_file(Wind::getRealPath($filter['class']))) {
             continue;
         }
         if (!empty($filter['expression'])) {
             $v1 = '';
             list($n, $p, $o, $v2) = WindUtility::resolveExpression($filter['expression']);
             switch (strtolower($n)) {
                 case 'service':
                     $call = array($service, 'getAttribute');
                     break;
                 case 'config':
                     $call = 'PwHook::_getConfig';
                     break;
                 default:
                     $call = 'PwHook::_getRequest';
                     break;
             }
             $v1 = call_user_func_array($call, explode('.', $p));
             if (!WindUtility::evalExpression($v1, $v2, $o)) {
                 continue;
             }
         }
         $_filters[] = $filter;
     }
     return $_filters;
 }