phprs\Response::flush PHP Метод

flush() публичный Метод

想缓存写出
public flush ( $limit = null, $func = null ) : array:
$limit 取指定的项目
$func 取出后调用的方法
Результат array:
    public function flush($limit = null, $func = null)
    {
        foreach ($this->sender as $name => $sender) {
            if (!isset($this->buffer[$name])) {
                continue;
            }
            if ($limit !== null) {
                if ($limit !== $name) {
                    continue;
                }
                if ($func !== null) {
                    $sender = $func;
                }
            }
            $funcs = $this->buffer[$name];
            foreach ($funcs as $args) {
                // 确保所有参数均已设置
                ksort($args, SORT_NUMERIC);
                $i = 0;
                foreach ($args as $k => $v) {
                    Verify::isTrue($k === $i++, "the no.{$i} arg from {$name} not exist");
                }
                call_user_func_array($sender, $args);
            }
            if ($limit !== null) {
                break;
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * 调用路由规则匹配的api
  * @param Request $request
  * @param Response $respond
  * @return void
  */
 public function __invoke($request = null, &$respond = null)
 {
     if ($request === null) {
         $request = new Request(null, $this->url_begin);
     }
     if ($respond == null) {
         $respond = new Response();
     }
     $request['$.router'] = $this;
     //先按配置的顺序调用hook
     foreach ($this->hook_routes as $hook) {
         $res = new BufferedRespond();
         if (!$this->invokeRoute($hook, $request, $res)) {
             continue;
         }
         $respond->append($res->getBuffer());
         $break = false;
         $respond->flush('break', function ($var) use(&$break) {
             $break = $var;
         });
         if ($break) {
             Logger::info("invoke break");
             $respond->flush();
             return;
         }
     }
     $res = new BufferedRespond();
     Verify::isTrue($this->invokeRoute($this->routes, $request, $res), new NotFound());
     $respond->append($res->getBuffer());
     $respond->flush();
 }