Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

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

Hisateru Tanaka

December 15, 2018
Tweet

More Decks by Hisateru Tanaka

Other Decks in Technology

Transcript

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

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

    3FRVFTU)BOEMFS*OUFSGBDFIBOEMFS 3FTQPOTF*OUFSGBDF .JEEMFXBSF*OUFSGBDF ϛυϧ΢ΣΞͷ࢓༷ͱࢥΘΕ ͕͚ͪͩͲɺΉ͠Ζ͍ͭ͜ͷ ൃݟͷํ͕ॏཁ
  3. app.get('/', function (req, res) { res.send('Hello World!'); }); app.use(function (req,

    res, next) { console.log('LOGGED'); next(); }); ·ͣ͸ͪ͜ΒΛ͝ཡ͍ͩ͘͞ 143ͷॳظҊ͸͜͏͍͏/PEFKTͷΑ͏ͳܗΛ͍ͯ͠·ͨ͠ɻ 4MJNͷ࣮૷ΛҰൠԽͨ͠ײ͡Ͱ͢ɻ ೥ϦϦʔε͞Εͨܗͱ͸͍ͩͿҧ͍·͢ɻ
  4. 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); } }; ೖྗϦΫΤετ  ࣍ͷεςοϓ΁ͷϙΠϯλʔ ग़ྗϨεϙϯε
  5. w IBOEMFS͸ඞͣIBOEMF ϝιουΛ࣋ͭอূ͕͋Δ w IBOEMF ϝιουͷҾ਺ʹ͸ܕ੍໿͕͋Δ w IBOEMF ϝιου͕ϨεϙϯεΛฦ͢อূ͕͋Δ return

    $handler->handle($request); IBOEMF  4FSWFS3FRVFTU*OUFSGBDFSFRVFTU 3FTQPOTF*OUFSGBDF 3FRVFTU)BOEMFS*OUFSGBDF ܕͷ͔ͪΒ
  6. $handler = new class implements RequestHandlerInterface { public function handle(

    ServerRequestInterface $request ): ResponseInterface { // ͳʹ͔Λॲཧ͢Δ return new } }; ͋Ε ͜͜Ͳ͏͢Μͩ
  7. 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)); } };
  8.  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)); } };
  9. 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)); } }; 
  10. 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)); } };