/**
  * 拦截器的执行入口
  * 
  * @param mixed $var=..
  *        该接口接受任意参数,并将依次传递给拦截器的前置和后置操作
  * @return mixed 返回拦截链执行的最终结果
  */
 public function handle($method)
 {
     if (method_exists($this, $method)) {
         $this->{$method}();
     }
     $handler = $this->interceptorChain->getHandler();
     if (null !== $handler) {
         $handler->handle($method);
     }
     return;
 }
Exemplo n.º 2
0
 /**
  * 拦截器的执行入口
  * 
  * @param mixed $var=.. 该接口接受任意参数,并将依次传递给拦截器的前置和后置操作
  * @return mixed 返回拦截链执行的最终结果
  */
 public function handle()
 {
     $args = func_get_args();
     $this->result = call_user_func_array(array($this, 'preHandle'), $args);
     if ($this->result !== null) {
         return $this->result;
     }
     if (null !== ($handler = $this->interceptorChain->getHandler())) {
         $this->result = call_user_func_array(array($handler, 'handle'), $args);
     } else {
         $this->result = call_user_func_array(array($this->interceptorChain, 'handle'), $args);
     }
     call_user_func_array(array($this, 'postHandle'), $args);
     return $this->result;
 }
Exemplo n.º 3
0
 /**
  * 创建并返回过滤链,如果过滤链已经被创建不重复创建
  * 
  * @return WindHandlerInterceptorChain
  * @throws WindException
  */
 private function _getInterceptorChain()
 {
     if (null === $this->_interceptorChain) {
         $chain = Wind::import($this->_class_interceptorChain);
         $this->_interceptorChain = WindFactory::createInstance($chain);
         $this->_interceptorChain->addInterceptors($this->_listener);
     }
     return $this->_interceptorChain;
 }
Exemplo n.º 4
0
 /**
  * 创建并返回过滤链,如果过滤链已经被创建不重复创建
  * 
  * @param string $event 事件名称 默认值为空
  * @return WindHandlerInterceptorChain
  * @throws WindException
  */
 private function _getInterceptorChain($event = '')
 {
     if (null === $this->_interceptorChain) {
         $chain = Wind::import($this->_class_interceptorChain);
         $this->_interceptorChain = WindFactory::createInstance($chain);
     }
     $this->_interceptorChain->reset();
     return $this->_interceptorChain;
 }
 /**
  * 注册过滤器,监听Application Run
  * 
  * @param WindHandlerInterceptor $filter        
  */
 public function registeFilter($filter)
 {
     if ($this->_chain === null) {
         Wind::import("WIND:filter.WindHandlerInterceptorChain");
         $this->_chain = new WindHandlerInterceptorChain();
     }
     if ($filter instanceof AbstractWindBootstrap) {
         $this->_chain->addInterceptors($filter);
     }
 }
Exemplo n.º 6
0
 /**
  * 创建对应标签的解析器类实例对象,并加载到处理链中.
  * 
  * @param string content 模板内容
  * @param string compiler 标签编译器
  * @param string regex 正则表达式
  * @param WindViewerResolver $windViewerResolver 默认为null
  * @return string 返回处理后的模板内容
  */
 private function creatTagCompiler($content, $compiler, $regex, $windViewerResolver = null)
 {
     $content = preg_replace_callback($regex, array($this, '_creatTagCompiler'), $content);
     if ($this->windHandlerInterceptorChain === null) {
         $this->windHandlerInterceptorChain = new WindHandlerInterceptorChain();
     }
     $_compilerClass = Wind::import($compiler);
     $this->windHandlerInterceptorChain->addInterceptors(new $_compilerClass($this->_compilerCache, $this, $windViewerResolver, $this->getRequest(), $this->getResponse()));
     $this->_compilerCache = array();
     return $content;
 }
Exemplo n.º 7
0
 /**
  * 拦截器的执行入口
  * 
  * @param mixed $var=.. 该接口接受任意参数,并将依次传递给拦截器的前置和后置操作
  * @return mixed 返回拦截链执行的最终结果
  */
 public function handle($event, $targetObject = null)
 {
     $args = func_get_args();
     $_args = array_slice($args, 2);
     $this->targetObject = $targetObject;
     if (method_exists($this, 'pre' . $event)) {
         $this->result = call_user_func_array(array($this, 'pre' . $event), $_args);
         if (null !== $this->result) {
             return $this->result;
         }
     }
     if (null !== ($handler = $this->interceptorChain->getHandler())) {
         $this->result = call_user_func_array(array($handler, 'handle'), $args);
     } else {
         $this->result = call_user_func_array(array($this->interceptorChain, 'handle'), $_args);
     }
     if (method_exists($this, 'post' . $event)) {
         call_user_func_array(array($this, 'post' . $event), $_args);
     }
     return $this->result;
 }
Exemplo n.º 8
0
 /**
  * 创建并返回过滤链,如果过滤链已经被创建不重复创建
  * 
  * @param string $event 事件名称 默认值为空
  * @return WindHandlerInterceptorChain
  * @throws WindException
  */
 private function _getInterceptorChain($event = '')
 {
     if (null === $this->_interceptorChainObj) {
         $chain = Wind::import($this->_interceptorChain);
         $interceptorChain = WindFactory::createInstance($chain);
         if ($interceptorChain && $interceptorChain instanceof WindHandlerInterceptorChain) {
             $this->_interceptorChainObj = $interceptorChain;
         } else {
             throw new WindException('[base.WindClassProxy._getInterceptorChain] Unable to create interceptorChain.');
         }
     }
     $this->_interceptorChainObj->reset();
     return $this->_interceptorChainObj;
 }
Exemplo n.º 9
0
 public function setConfig($config)
 {
     parent::setConfig($config);
     if ($this->_config) {
         $this->_module = $this->getConfig('module', 'default-value', $this->_module);
         $this->_controller = $this->getConfig('controller', 'default-value', $this->_controller);
         $this->_action = $this->getConfig('action', 'default-value', $this->_action);
         $this->moduleKey = $this->getConfig('module', 'url-param', $this->moduleKey);
         $this->controllerKey = $this->getConfig('controller', 'url-param', $this->controllerKey);
         $this->actionKey = $this->getConfig('action', 'url-param', $this->actionKey);
         foreach ($this->getConfig('routes', '', array()) as $routeName => $route) {
             if (!isset($route['class'])) {
                 continue;
             }
             $instance = WindFactory::createInstance(Wind::import($route['class']));
             $instance->setConfig($route);
             $this->addRoute($routeName, $instance, isset($route['default']) && $route['default'] === true);
         }
     }
 }
 /**
  * 创建并运行当前应用
  * 
  * 配合过滤链策略部署,可以通过{@see AbstractWindFrontController::registeFilter}
  * 方法注册过滤器,当应用被执行时会判断当前时候有初始化过滤链对象,并选择是否是通过过滤链方式执行应用
  * @return void
  */
 protected function _run()
 {
     $application = $this->createApplication();
     if ($this->_chain !== null) {
         $this->_chain->setCallBack(array($application, 'run'), array(true));
         $this->_chain->getHandler()->handle($this);
     } else {
         $application->run($application->getConfig('filters'));
     }
     restore_error_handler();
     restore_exception_handler();
     $this->_app->getResponse()->sendResponse();
     $this->_app->getWindFactory()->executeDestroyMethod();
     if ($this->_cache !== null && $this->_cached === false) {
         $this->_cache->set('factory', $this->_factory);
         $this->_cache->set('classes', Wind::$_classes);
         $this->_cache->set('imports', Wind::$_imports);
         $this->_cache->set('config', $this->_config);
     }
 }