Pro Yearly is on sale from $80 to $50! »

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. 1)1'*(ͷ)551 ॲཧඪ४ͷઃܭ͸ ͳͥ143 ʹͳͬͨͷ͔

  2. ͨͳ͔ͻͯ͞Δ @tanakahisateru ॴ௕

  3. IUUQTTQFBLFSEFDLDPNUBOBLBIJTBUFSVXFIBWFQTS ڈ೥ͷ࠙਌ձͰ͜Μͳ͜ͱ΍ͬͯ ͔ͬ͢Γ143೔ຊΤόϯδΣϦετͰ͢ ·͡Ͱ࠷ۙதͷਓʹόϨͨ

  4. ͝஫ҙ w ;FOE&YQSFTTJWFͷ࢖͍ํ͸΍Γ·ͤΜ w 143ͷ)551ϝοηʔδϯάͷઃܭΛ௨ͯ͡ w ઃܭͷΤοηϯεΛֶͼऔΔ͜ͱΛ໨తͱ͠·͢

  5. ΠϯλʔϑΣʔεͷఆٛͳΜܾͯΊͷ໰୊Ͱ͠ΐ

  6. ΠϯλʔϑΣʔεͷఆٛͳΜܾͯΊͷ໰୊Ͱ͠ΐ Μͳͨ͜ͶʔΑ

  7. ໿ϲ݄ ͨͱ͑͹143ͷऩଋʹ͔͔ͬͨ࣌ؒ ʙ  

  8. w ϛϡʔλϒϧWTΠϛϡʔλϒϧ w ׳शΛ͍ٙຊ࣭Λݟग़͢ w ։์ด࠯ݪଇ͔Β҆ఆ౓ந৅౓౳Ձݪଇ·Ͱ w ந৅ͷσβΠϯ ઃܭ ͕ͦ͜ຊ࣭

    ͜ͷ௕͍ظؒͰԿ͕ܾ·͔͔ͬͨΒʜ ʜͬͯ࿩͠Α͏ͱͯͨ͠ΜͰ͚͢Ͳ
  9. Ϊϟʔ

  10. None
  11. ໾ཱͨͣͷڠௐੑͳ͍ϑϨʔϜϫʔΫج൫ͩͱ͔ʜ

  12. ߦಈنൣŗŕʜ ͸͊ ͓·͕͍͎͑ʜ

  13. ʮ͚ͯ͠;FOEͷΤΰͰ͸ͳ͍ʯ ࢲ͕Ҏલ͔Βओு͔ͨͬͨ͠ͷ͸ɺ143͔Β࢝·ͬͨઃܭ͕ ͱ͍͏͜ͱͰ͢ ΋ͱ͍

  14. /ZIPMN :JJBMQIB (V[[MF 4MJN ;FOE ͪΐͬͱ஫໨ͷ࠷଎࣮૷ 4MJN΋࣍͸͜Ε࢖͏͔ͱ͔ݴͬͯΔ ࣍ੈ୅:JJͷ)551·ΘΓ΋ 143Λ࣮૷͢ΔΑ͏ʹͳΔ ΄Β͜ͷτοϓ

  15. ࢓্͕ΓΛΑ͘ݟΖ )551ϝοηʔδϯάͦ͜ ૬ޓӡ༻ੑͷ৅௃తͳଘࡏ͡Όͳ͍͔ ʜͱɺͳ͍ͥ͑Δͷ͔

  16. 8): ͳͥඞཁͳͷ͔

  17. ͜ΕΛݟͯΈͳ͞ΜͲ͏ࢥΘΕ·͔͢ ஫-BSBWFM4XPPMF͋ΔΑͱ͍͏ͷͱ͸ҙຯ͕ҧ͍·͢

  18. &NJUUFS*OUFSGBDF 4BQJ&NJUUFS 4XPPMF&NJUUFS 3FRVFTU)BOEMFS*OUFSGBDF ϑϨʔϜϫʔΫ "QBDIF'1. 4XPPMF ૄ݁߹ͳΞʔΩςΫνϟ ͜͜Ͱ&NJUUFS͕ࠩ͠ସΘͬͯ΋ ϑϨʔϜϫʔΫ͸มΘΒͳ͍

    ։์ด࠯ݪଇ
  19. &NJUUFS*OUFSGBDF 4BQJ&NJUUFS 4XPPMF&NJUUFS 3FRVFTU)BOEMFS*OUFSGBDF ϑϨʔϜϫʔΫ "QBDIF'1. 4XPPMF ֤ϑϨʔϜϫʔΫ͕ $BLF1)1YΛ࠶ൃ໌ ͢Δͷ͸΋͏ͨ͘͞Μͩ

    ผͷઐ༻ϑϨʔϜϫʔΫ
  20. ݴ͍͔ͨ͊ͳ͍͚Ͳ͜ΕΑ &TQSFTTP3FBDU1)1 4JMFY TZNGPOZIUUQGPVOEBUJPO  ͳΜͰ͜ΜͳʹՄೳੑ͋ͬͨϓϩδΣΫτ͕ࢭ·ͬͯ͠·ͬͨΜͰ͠ΐ͏͔ͱ   

  21. ϑϨʔϜϫʔΫͱ͸ ΤϛολͷϥούϥΠϒϥϦͰ͸ͳ͍ ໰୊ʹରͯ͠࠷దͳ ղܾͷ࿮૊Έந৅ ϋʔυίʔυ͞Εͨ

  22. ໰୊Ҋ݅ݻ༗ͳۀ຿্ͷ՝୊ ղܾͲͷ૚Ͱෳࡶ͞Λ෧͡Δ͔ ໰୊ͱղ๏ʹଟ༷ੑ͕͋Δ͔Βͦ͜ 1)1ͱ1)1'*(ͷҙຯ͕͋Δ ϑϨʔϜϫʔΫબ୒ࢶ͕ଟ͍1)1ͷଘࡏҙٛͪΌ͍·͔͢͜Ε

  23. @(&5<>FDIP ϑϨʔϜϫʔΫ %# %* 7JFX .7$ શһ͕ಉ͡Χλνͨ͠΋ͷͰڝ૪ͯ͠΋ҙຯͳ͍ %# %* 7JFX

    .7$ %# %* 7JFX .7$ %# %* 7JFX .7$ ŹůžŢઠŹůžŢŕŞ
  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 %%%%$*
  25. &NJUUFS*OUFSGBDF 4BQJ&NJUUFS 4XPPMF&NJUUFS 3FRVFTU)BOEMFS*OUFSGBDF ϑϨʔϜϫʔΫ "QBDIF'1. 4XPPMF ૄ݁߹ͳΞʔΩςΫνϟ ϑϨʔϜϫʔΫ࡞Δͱ͖ ͔͜͜ΒԼ͍ͬͨΜ๨Εͯ

    ந৅౓্͍͛ͯ͜͏Α ͜͜͸ΈΜͳ͕ ࠶ར༻Ͱ͖ΔΑ͏ʹ ෼͚ͯߟ͑Α͏ͥ
  26. )08 ඞཁੑ͸ͲͷΑ͏ʹຬͨ͞ΕΔ͔

  27. 143 ϝοηʔδͷσʔλϞσϧ 143 143 ϝοηʔδͷϋϯυϦϯά ϝοηʔδͷੜ੒ 3FRVFTU*OUFSGBDF3FTQPOTF*OUFSGBDF 6SJ 4USFBN 6QMPBEFE'JMF

    3FRVFTU)BOEMFS*OUFSGBDF .JEEMFXBSF*OUFSGBDF 3FTQPOTF'BDUPSZ*OUFSGBDF 4USFBN'BDUPSZ*OUFSGBDF 
  28. XJUI)FBEFS OBNF WBMVF  HFU#PEZ 4USFBN*OUFSGBDF .FTTBHF*OUFSGBDF 3FRVFTU*OUFSGBDF 3FTQPOTF*OUFSGBDF 143

    4USFBN*OUFSGBDF SFBE MFOHUI TUSJOH   FYUFOET
  29. XJUI)FBEFS ΠϛϡʔλϏϦςΟ ࣗ਎Λมߋͤͣɺࣗ਎ͷϔομͱ௥ՃϔομΛ ࣋ͬͨ৽͍͠ΠϯελϯεΛฦ͢ 4USFBN*OUFSGBDF ஗ԆಡΈग़͠ந৅ ϝϞϦʹશ಺༰ΛཷΊࠐ·ͳͯ͘΋͍͍ 1)1ׂ౰ϝϞϦΑΓେ͖͍όΠτྻΛѻ͑Δ 143ͷϙΠϯτ

  30. SFRVFTUTFU1BSBN bGPP` CBS  ΋͠ϛϡʔλϒϧͩͬͨΒʜ

  31. @(&5<bGPP`>CBS ΋͠ϛϡʔλϒϧͩͬͨΒʜ ಉҰͷϦΫΤετΠϯελϯεΛ࢖͍ճ͢͜ͱ͸ 1)1ͷ࣮ߦ࣌ʹ͸εʔύʔάϩʔόϧͱಉ͡ҙຯ ͜Μͳ΋ͷͰαʔυύʔςΟؒͷ૬ޓӡ༻ੑΛҡ࣋Ͱ͖Δ͔ෆ҆

  32. ετϦʔϛϯάʹ͍ͭͯ͸ͪ͜ΒΛ͝ཡ͍ͩ͘͞ IUUQQTSOFUTBTF[BLJQIQDPOGVL IUUQTXXXTMJEFTIBSFOFUTBTF[BLJQIQIUUQ ཁ͸ɺඞͣετϦʔϛϯάΛ૝ఆ͠Ζͱ͢Δ͜ͱͰɺ ڊେ*0Ͱ΋ྫ֎ͳ͘ѻ͑ΔΑ͏഑ྀ͞Ε͍ͯ·͢ (V[[MFźŕŦŖ

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

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

    res, next) { console.log('LOGGED'); next(); }); ·ͣ͸ͪ͜ΒΛ͝ཡ͍ͩ͘͞ 143ͷॳظҊ͸͜͏͍͏/PEFKTͷΑ͏ͳܗΛ͍ͯ͠·ͨ͠ɻ 4MJNͷ࣮૷ΛҰൠԽͨ͠ײ͡Ͱ͢ɻ ೥ϦϦʔε͞Εͨܗͱ͸͍ͩͿҧ͍·͢ɻ
  35. w ͳͥϦΫΤετϋϯυϥ͕ʮϦΫΤετΛड͚ͯϨεϙϯε Λฦ͢ʯͱ͍͏ૉ௚ͳܗΛ͍ͯ͠ͳ͍ͷ͔ w ڞ༗Πϯελϯεͷঢ়ଶ͕มԽͨ͠Γɺଈ࠲ʹετϦʔϜʹ ϓογϡͨ͠Γ͢Δͷ͸ɺ143લఏͰ͜Ε͸ʜ app.get('/', function (req, res)

    { res.send('Hello World!'); });
  36. w OFYU ͕Կऀ͔ΛܕͰද͍ͤͯͳ͍ɻʮ@@JOWPLFΛ࣋ͭ ΦϒδΣΫτʯͳͲͱ͍͏ܕ͸ͳ͍ w DBMMBCMFͳ͚ͩͰ͸Ҿ਺ͷ਺΍ܕͷ੍໿͕༩͑ΒΕͳ͍ app.use(function (req, res, next)

    { console.log('LOGGED'); next(); });
  37. w ͔ͨ͠ʹɺଟ͘ͷϑϨʔϜϫʔΫ͕&YQSFTTͷϛυϧ΢ΣΞ ʹӨڹΛड͚ͨաڈ͸͋Δɻ1)1Ͱ΋ͦͷํ͕ଟ਺೿ͩͬͨ w Ͱ΋ɺ/PEFKTͷಈ࡞ಛੑʹରͯ͠ઃܭ͞Εͨ΋ͷΛɺΦϒ δΣΫτࢦ޲ݴޠ1)1͕ࢀߟʹ͢Δͷ͸͓͔͍͠ w ʮΠϯϥΠϯؔ਺ͻͱͭͰ؆୯ʹͰ͖Δʯͷʮ؆୯ʯ͸ɺ νϡʔτϦΞϧͰ͸༗ޮͰ΋ɺݱ৔Ͱ᠘ʹԽ͚Δ೏͍͕ϓϯ ϓϯ͢Δࢥ૝

    w ߟ͑௚ͤIUUQTCMPHJSDNBYFMMDPNBMM BCPVUNJEEMFXBSFIUNM
  38. QSPDFTT  4FSWFS3FRVFTU*OUFSGBDFSFRVFTU  3FRVFTU)BOEMFS*OUFSGBDFIBOEMFS 3FTQPOTF*OUFSGBDF .JEEMFXBSF*OUFSGBDF ͦͯ͜͠͏ͳͬͨ

  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); } }; ೖྗϦΫΤετ  ࣍ͷεςοϓ΁ͷϙΠϯλʔ ग़ྗϨεϙϯε
  40. w IBOEMFS͸ඞͣIBOEMF ϝιουΛ࣋ͭอূ͕͋Δ w IBOEMF ϝιουͷҾ਺ʹ͸ܕ੍໿͕͋Δ w IBOEMF ϝιου͕ϨεϙϯεΛฦ͢อূ͕͋Δ return

    $handler->handle($request); IBOEMF  4FSWFS3FRVFTU*OUFSGBDFSFRVFTU 3FTQPOTF*OUFSGBDF 3FRVFTU)BOEMFS*OUFSGBDF ܕͷ͔ͪΒ
  41. IBOEMF  4FSWFS3FRVFTU*OUFSGBDFSFRVFTU 3FTQPOTF*OUFSGBDF 3FRVFTU)BOEMFS*OUFSGBDF ͭ·Γ8FCΞϓϦέʔγϣϯ ൚Խ ʜ͋ɺͦ͏Ͷɺ͢΂ͯͷΞϓϦέʔγϣϯ͸ཁ͢Δʹ ϦΫΤετΛड͚ͯϨεϙϯεΛฦ͚ͩͩ͢ΑͶ ϦΫΤετΛड͚ͯ

    ϨεϙϯεΛฦ͢ʜ
  42. "QQ IBOEMF 1SPYZ QSPDFTT ϦΫΤετ Ϩεϙϯε 1SPYZ"QQؒͰɺಉҰͷϝοηʔδΠϯελϯεΛڞ༗͠ͳ͍͜ͱ͕ॏཁ ح͘͠΋143͸ ෺ཧαʔόʔߏ੒ͱಉ͡ߏਤʹ ετϦʔϛϯά

    ετϦʔϛϯά 3FRVFTU)BOEMFS*OUFSGBDF .JEEMFXBSF*OUFSGBDF $PQZXJUITUSFBNJOH $PQZXJUITUSFBNJOH
  43. ݱঢ়ͷྲྀߦΓʹଥڠͤͣͪΌΜͱઃܭ͠Α͏ͱͨ͠Β ͳΜ͔ݱ࣮ͷࣸ૾ʹ͍ۙϞσϧ͕ग़͖ͯͨͧ ͪΐͬͱײಈͳΜͰ͚͢Ͳ ߟ͑௚ͯ͠ຊ౰ʹྑ͔ͬͨ

  44. ͋ͱͪΐͬͱ଍Γͳ͍͜ͱ

  45. DSFBUF3FTQPOTF  DPEF ʜ 3FTQPOTF*OUFSGBDF 3FTQPOTF'BDUPSZ*OUFSGBDF 143 4USFBN'BDUPSZ*OUFSGBDF 3FRVFTU'BDUPSZ*OUFSGBDF ʜ

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

    ServerRequestInterface $request ): ResponseInterface { // ͳʹ͔Λॲཧ͢Δ return new } }; ͋Ε ͜͜Ͳ͏͢Μͩ
  47. return (new \Zend\Diactoros\Response()) ->withHeader( ‘Content-Type', ‘application/json' ) ->withBody( new \Zend\Diactoros\Stream($data)

    ); ʜ͑ ͜ΕͩΊ ͩΊͰ͢
  48. 143 "QQ SEQBSUZ *NQMFNFOUBUJPO ͔ͤͬ͘ΠϯλʔϑΣʔεʹґଘͯ͠ ࣮૷ϥΠϒϥϦΑΓ"QQ͕ ந৅౓্ʹͳΕΔͷʹ ґଘ ࣮૷ ΠϯϑϥετϥΫνϟ૚

    ΞϓϦέʔγϣϯ૚ ۀքඪ४ͷந৅ ࠷҆ఆ
  49. 143 "QQ SEQBSUZ *NQMFNFOUBUJPO ௚ࢀরͨ͠Β҆ఆ౓ந৅౓౳Ձݪଇͷҧ൓ ඪ४ΠϯλʔϑΣʔε୆ແ͠ ґଘ ࣮૷ ΠϯϑϥετϥΫνϟ૚ ΞϓϦέʔγϣϯ૚

    ۀքඪ४ͷந৅ ࠷҆ఆ ґଘ 
  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)); } };
  51. public function __construct( ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory ) ίϯετϥΫλͷ͋ͨΓͰ͸ ೚ҙʹ%*

    ґଘੑ஫ೖ ظ଴ͯ͠Δ͚ͩͰ͢ ͨͿΜબ୒ͨ͠143ͷ࣮૷ϥΠϒϥϦΛ஫ೖͯ͘͠ΕΔ
  52. return $this->responseFactory->createResponse() ->withHeader( ‘Content-Type', ‘application/json' ) ->withBody( $this->streamFactory->createStream($data) ); ۩৅ΛOFXͤͣɺੜ੒͸

    ந৅ϑΝΫτϦʹ೚ͤΔ Ͳͷ࣮૷ϥΠϒϥϦΛ࢖͏ͷ͔Λ ͍͍ͬ͞ؾʹͤͣࣗ෼ͷίʔυ͕׬੒͢Δ
  53. 143 "QQ SEQBSUZ *NQMFNFOUBUJPO ,&&1 ґଘ ࣮૷ ΠϯϑϥετϥΫνϟ૚ ΞϓϦέʔγϣϯ૚ ۀքඪ४ͷந৅

    ࠷҆ఆ
  54. ·ͱΊ

  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)); } };
  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)); } }; 
  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)); } }; 
  58. Α͏Θ͔ΒΜ͚Ͳ ͋Μͨͷ࿩Ϝζ͍Θ ʮΈΜͳ޲͚ͷΘ͔Γ΍͍͢΍ͭͳ͍ͷ ʯ Ͱɺ͍͍ͷͰ͠ΐ͏͔

  59. ࠓ͙͢໾ʹཱͨͳ͍ͱ ཧղ͞Εͳͯ͘΋ ະདྷͷͨΊʹ ਖ਼͠͞Λ؏͘͜ͱͦ͜ ༏Εͨந৅ͷઃܭʹͱͬͯ େࣄͳ͜ͱͳͷͰ͸

  60. ϦϑΝΫλ͕ཁΔ  ͋ͱͰޮ͍ͯ͘Δ  ࠓಈ͍ͯΔ͔Β͍͍͡ΌΜ ࠓ͙͢໾ʹཱͨͳ͍ͱ ཧղ͞Εͳͯ͘΋ ະདྷͷͨΊʹ ਖ਼͠͞Λ؏͘͜ͱͦ͜ ༏Εͨந৅ͷઃܭʹͱͬͯ

    େࣄͳ͜ͱͳͷͰ͸