PSR-7
- ミドルウェアよくわからないので調べた
- 結局よくわからない
公式
http://www.php-fig.org/psr/psr-7/
http://www.php-fig.org/psr/psr-7/meta/
仕様
- Request:
Psr\Http\Message\RequestInterface
- Response:
Psr\Http\Message\ResponseInterface
- これらは
Psr\Http\Message\MessageInterface
を継承している
http headers
- headerのkeyは大文字小文字を区別しない
- headerはカンマ区切りstringかarrayで返ってくる
- すべてカンマ区切りで結合できるわけではない
- ex.Set-header
- request host headerがrequest host componentやURI host componentより優先される
stream
-
StreamInterface
は実装の詳細を隠すために継承する-
php://memory
やphp://temp
が使われる
-
-
isReadable()
,isWritable()
, andisSeekable()
で要求の可否を見る -
__toString()
はbody contents全体をどう取り扱うかをシンプルにする -
StreamInterface
はimmutableではない
URI
- requestはrequest-targetを含み、以下4つの形態がある
- origin → 相対パス
- absolute → 絶対パス
- authority → CONNECT requestsのときに使う、httpclientとproxyを繋ぐ
- asterisk → OPTIONS methodと共に使うこれ →
*
-
UriInterface
を継承する
Server-side Requests
-
$_COOKIE
,$_GET
,$_POST
,$_FILES
,$_SERVER
-
ServerRequestInterface
はRequestInterface
を継承する -
ServerRequestInterface
はこれらsuper globalを扱う
Uploaded files
-
ServerRequestInterface
はfile uploadの時、UploadedFileInterface
を使っていい感じにしてくれる
source
- https://github.com/php-fig/http-message
- 別リポジトリにutilがまとまってる
implementとかmwとか
- packagistのタグを追うと、既に色々実装されている
- https://packagist.org/search/?tags=psr-7
- https://packagist.org/search/?tags=http-message
- zendframework/zend-diactoros
- micheh/psr7-cache
- PSR-7 middleware applications
- zendframework/zend-expressive
- https://github.com/zendframework/zend-expressive
- dflydev/fig-cookies
- tuupola/slim-basic-auth
- oscarotero/psr7-middlewares
- relay/relay
- blast/turbine
もっと色々記事を探すなら
- qiitaで検索
- はてなで検索するのもよさそう
- 海外文献も見つけることが出来るから
- http://b.hatena.ne.jp/search/text?q=PSR-7
次のアクションとしては
- PSR-7使ったapp作ってみる
- 普段event-drivenなFW使っているため、ミドルウェア使うapp作ったこと無い。。。
- 実装を精読する
- 自分で仕様を実装してみる