前言
第一部分: 半协程调度器
- 统一生成器接口
- 生成器迭代
- 生成器返回值
- 生成器委托
- 改写 return
- 抽象异步模型
- 引入异常处理
- 异常: 嵌套任务透传
- 异常: 传递流程
- 异常: 重新进行 CPS 变换
- 异常: 重新加入 Async
- Syscall 与 Context
- 调度器: 里程碑
- spawn
- callcc
- race 与 timeout
- all 与 parallel
- channel 与协程间通信
- 无缓存 channel
- 缓存 channel
- channel 演示
- FutureTask 与 fork
第二部分: Koa
- 穿越地心之旅
- 洋葱圈模型
- rightReduce与中间件compose
- Koa::Application
- Koa::Context
- Koa::Request
- Koa::Response
- Koa - HelloWorld
- Middleware Interface
- Middleware: 全局异常处理
- Middleware: Router
- Middleware: 请求超时
- 一个综合示例
附录
参考
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
Koa::Request
Koa::Request
Request
组件是对swoole_http_request
的简单封装:
<?php
class Request
{
/** @var Application */
public $app;
/** @var \swoole_http_request */
public $req;
/** @var \swoole_http_response */
public $res;
/** @var Context */
public $ctx;
/** @var Response */
public $response;
/** @var string */
public $originalUrl;
/** @var string */
public $ip;
public function __construct(Application $app, Context $ctx,
\swoole_http_request $req, \swoole_http_response $res)
{
$this->app = $app;
$this->ctx = $ctx;
$this->req = $req;
$this->res = $res;
}
public function __get($name)
{
switch ($name) {
case "rawcontent":
return $this->req->rawContent();
case "post":
return isset($this->req->post) ? $this->req->post : [];
case "get":
return isset($this->req->get) ? $this->req->get : [];
case "cookie":
case "cookies":
return isset($this->req->cookie) ? $this->req->cookie : [];
case "request":
return isset($this->req->request) ? $this->req->request : [];
case "header":
case "headers":
return isset($this->req->header) ? $this->req->header : [];
case "files":
return isset($this->req->files) ? $this->req->files : [];
case "method":
return $this->req->server["request_method"];
case "url":
case "origin":
return $this->req->server["request_uri"];
case "path":
return isset($this->req->server["path_info"]) ? $this->req->server["path_info"] : "";
case "query":
case "querystring":
return isset($this->req->server["query_string"]) ? $this->req->server["query_string"] : "";
case "host":
case "hostname":
return isset($this->req->header["host"]) ? $this->req->header["host"] : "";
case "protocol":
return $this->req->server["server_protocol"];
default:
return $this->req->$name;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论