PHP-FIGのHTTP処理標準の設計はなぜPSR-7/15/17になったのか

 PHP-FIGのHTTP処理標準の設計はなぜPSR-7/15/17になったのか

PHPカンファレンス2018 発表資料です

8c1ecc738eee0254a41c2d4b33cda7b6?s=128

Hisateru Tanaka

December 15, 2018
Tweet

Transcript

  1. 9.
  2. 10.
  3. 24.

    3FRVFTU)BOEMFS*OUFSGBDF ϑϨʔϜϫʔΫ 3%# $BDIF -PH %PNBJO.PEFM )5.- "TZOD 6*69 %FTJHO1BUUFSO

    .77. $234 "%0 $MFBO "SDIJUFDUVSF 5FTU $POpHVSBUJPO ࠓޙͷϑϨʔϜϫʔΫʹ ҙࣝͯ͠΄͍͠ྖҬ ͔͜͜ΒԼδΣωϦοΫͳ໰୊ͳΒ αʔυύʔςΟͰͥΜͥΜ͍͍Α %*$POUBJOFS 3PVUJOH )551.FTTBHJOH %%%%$*
  4. 27.
  5. 33.

    IBOEMF  4FSWFS3FRVFTU*OUFSGBDFSFRVFTU 3FTQPOTF*OUFSGBDF 3FRVFTU)BOEMFS*OUFSGBDF 143 QSPDFTT  4FSWFS3FRVFTU*OUFSGBDFSFRVFTU 

    3FRVFTU)BOEMFS*OUFSGBDFIBOEMFS 3FTQPOTF*OUFSGBDF .JEEMFXBSF*OUFSGBDF ϛυϧ΢ΣΞͷ࢓༷ͱࢥΘΕ ͕͚ͪͩͲɺΉ͠Ζ͍ͭ͜ͷ ൃݟͷํ͕ॏཁ
  6. 34.

    app.get('/', function (req, res) { res.send('Hello World!'); }); app.use(function (req,

    res, next) { console.log('LOGGED'); next(); }); ·ͣ͸ͪ͜ΒΛ͝ཡ͍ͩ͘͞ 143ͷॳظҊ͸͜͏͍͏/PEFKTͷΑ͏ͳܗΛ͍ͯ͠·ͨ͠ɻ 4MJNͷ࣮૷ΛҰൠԽͨ͠ײ͡Ͱ͢ɻ ೥ϦϦʔε͞Εͨܗͱ͸͍ͩͿҧ͍·͢ɻ
  7. 39.

    app.use(function (req, res, next) { console.log('LOGGED'); next(); }); $middleware =

    new class($logger) implements MiddlewareInterface { // ུ public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { $this->logger->log(LogLevel::INFO, 'LOGGED'); return $handler->handle($request); } }; ೖྗϦΫΤετ  ࣍ͷεςοϓ΁ͷϙΠϯλʔ ग़ྗϨεϙϯε
  8. 40.

    w IBOEMFS͸ඞͣIBOEMF ϝιουΛ࣋ͭอূ͕͋Δ w IBOEMF ϝιουͷҾ਺ʹ͸ܕ੍໿͕͋Δ w IBOEMF ϝιου͕ϨεϙϯεΛฦ͢อূ͕͋Δ return

    $handler->handle($request); IBOEMF  4FSWFS3FRVFTU*OUFSGBDFSFRVFTU 3FTQPOTF*OUFSGBDF 3FRVFTU)BOEMFS*OUFSGBDF ܕͷ͔ͪΒ
  9. 46.

    $handler = new class implements RequestHandlerInterface { public function handle(

    ServerRequestInterface $request ): ResponseInterface { // ͳʹ͔Λॲཧ͢Δ return new } }; ͋Ε ͜͜Ͳ͏͢Μͩ
  10. 50.

    class MyAppHandler implements RequestHandlerInterface { private $responseFactory; private $streamFactory; public

    function __construct( ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; } public function handle( ServerRequestInterface $request ): ResponseInterface { // ུ return $this->responseFactory->createResponse() ->withHeader('Content-Type', 'application/json') ->withBody($this->streamFactory->createStream($data)); } };
  11. 51.
  12. 54.
  13. 55.

     class MyAppHandler implements RequestHandlerInterface { private $responseFactory; private $streamFactory;

    public function __construct( ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; } public function handle( ServerRequestInterface $request ): ResponseInterface { // ུ return $this->responseFactory->createResponse() ->withHeader('Content-Type', 'application/json') ->withBody($this->streamFactory->createStream($data)); } };
  14. 56.

    class MyAppHandler implements RequestHandlerInterface { private $responseFactory; private $streamFactory; public

    function __construct( ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; } public function handle( ServerRequestInterface $request ): ResponseInterface { // ུ return $this->responseFactory->createResponse() ->withHeader('Content-Type', 'application/json') ->withBody($this->streamFactory->createStream($data)); } }; 
  15. 57.

    class MyAppHandler implements RequestHandlerInterface { private $responseFactory; private $streamFactory; public

    function __construct( ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory ) { $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; } public function handle( ServerRequestInterface $request ): ResponseInterface { // ུ return $this->responseFactory->createResponse() ->withHeader('Content-Type', 'application/json') ->withBody($this->streamFactory->createStream($data)); } };