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

PHPer人生、一度はフレームワークを作っておこう!

271fad8d53cd1f12f2b4b6d38e3d7bd3?s=47 uzulla
April 16, 2016

 PHPer人生、一度はフレームワークを作っておこう!

PHPカンファレンス北海道 2016 発表資料
20160416

271fad8d53cd1f12f2b4b6d38e3d7bd3?s=128

uzulla

April 16, 2016
Tweet

Transcript

  1. PHPerਓੜɺ Ұ౓͸ϑϨʔϜϫʔΫΛ࡞͓ͬͯ͜͏ʂ » at: PHPΧϯϑΝϨϯε๺ւಓ » date: 20160415 » speaker:

    uzulla
  2. ʢ஫ҙɺຊεϥΠυ͸ޱ಄Ͱ఻͑ͨࣄ͕͔ͳΓൈ͚͍ͯ ·͢ʣ

  3. "who are you ?" UZULLA PHPer ʮ౦ژํ໘͔Β͖·ͨ͠ʯ

  4. PHPerਓੜɺ Ұ౓͸ϑϨʔϜϫʔΫΛ ࡞͓ͬͯ͜͏ʂ

  5. 201X೥ʂ ੈք͸ن໿ͷԌʹแ·Εͨʂʂ

  6. » ʮҪށ͸ރΕɺാ͸ߥΕɺ͋ΒΏΔ$_GET͸ઈ໓ͨ͠ ͔ʹݟ͑ͨɻ ͕ͩɺΦϨΦϨϑϨʔϜϫʔΫ͸ࢮ໓ ͍ͯ͠ͳ͔ͬͨ…ʯ

  7. » ʮ͕͞ΕʂಓΛ͚͋Ζʙʂʯ » ʮʢ༗໊FWʣ༷ͷ͓௨Γͩʙʂʯ » ʰ΅͘ϑϨʔϜϫʔΫ࡞Γ·ͨ͠ʈʈʱ » ʮԚ෺͸ফಟͩʙʙʂʂʯ » ʰΪϟʔʂʂʂʱ

    » ʮΘ͸͸͸౔Լ࠲͠Ζʂʂফಟ͞Ε͔ͯ͑ʔʔʂʂʯ
  8. ʢօ͞Μ͍͖ͭͯ ͍͚ͯͨͩͯ· ͢ʁʣ

  9. » ཱ೿ͳFW͕૿͑ͨݱࡏɺϚοτ΢ͳFWΛ࢖Θͳ͍ ͜ͱ͸(ৗࣝతPHPerͱͯ͠ͷ)ࢮΛҙຯ͢Δͷͩɺί ϫΠʂʂ » ΦϨΦϨϑϨʔϜϫʔΧʔ͸ΦϨΦϨङΓʹૺΘ͵Α ͏ɺଉΛͻͦΊɺެʹ͢Δ͜ͱͳ͘ɺΦϨΦϨϑϨ ʔϜϫʔΫΛѪͰΔͷͰ͋ͬͨ…ɻ

  10. » ͔ͯ͘͠ʮΦϨΦϨϑϨʔϜϫʔΫਓޱʯ͸ݮগ͠ɺ Ұ౓΋ΦϨΦϨͨ͜͠ͱͷͳ͍ඇΦϨΦϨਓͷ૿Ճ Λࢲ͸ײ͍ͯ͡Δ… » ʮڐͤΜʂΦϨΦϨϑϨʔϜϫʔΫѪ޷Ոͱͯ͠͸அ ݻઓ͍͍ͨʂʢݸਓͷײ૝Ͱ͢ʣʯ » ͱ͍͏ͷ͕ɺ͜ͷτʔΫͷΞϯάϧͰ͢

  11. ·ͣ࠷ॳʹɺࠓ೔ࢲ͕ͲΕ͘ Β͍ఢΛͭ͘Δͷ͔஌͓ͬͯ ͖͍ͨΜͰ͕͢ɺ » օ͞Μ͸ » ʮΦϨΦϨͬͯͳʹʁʯͰ͔͢ʁ » ʮҰ౓͸ΦϨΦϨʯͰ͔͢ʁ »

    ʮωόʔΦϨΦϨʯͰ͔͢ʁ » ʮҰੜΦϨΦϨʯͰ͔͢ʁ
  12. ʮͳΔ΄Ͳʯ » Ͱ͸ຊ୊ʹೖ͍͖ͬͯ·͢ɻ

  13. FWΛ࡞Δલʹ FWͱ͸ͳΜͳͷ͔

  14. ϑϨʔϜϫʔΫͱ͸ʁ Ŗ PHPͰ͸ʮ΢ΣϒΞϓϦέʔγϣϯ੡࡞࣌ʹ໾ཱͭϥ ΠϒϥϦͷηοτͱੈք؍ʴΤίγεςϜʯΛࢦ͢ࣄ͕ ଟ͍ - աڈ͸ಛʹલऀ͕ͩͬͨɺࡢࠓ͸ޙऀ΋ॏཁʹ - ʢҎޙɺFWͱུশ͠·͢ʣ

  15. ༗໊ͳFW Symfony, Laravel, Lumen, Slim Framework, Yii, PHPixie, FuelPHP, CodeIgniter,

    CakePHP, ZendFramework, Phalcon, Nette, Silex, fatfree, limonade, DietCake, DietCube, Lithium, Aura, Ethna, etc. etc. 㙽ʹ֯୔ࢁ
  16. ΋ͬͱ͋Δʂଟ ͍ʂ » 2016-04-12ௐ΂ » ͲΜͲΜ૿͑ͯΔ » (ແ࿦ɺ͜ͷ਺ࣈ͸ϊΠζ ΛؚΉ) »

    ͜ͷ΄͔ʹɺηϯύΠ͔Β ౉͞ΕͨFWͱ͔΋͋ΔͰ ͠ΐ͏
  17. ໨తಛԽܕFW΋ » ϒϩάΤϯδϯͷWordpress ౳ » CMSͷDrupal ౳ » ECαΠτͷECCUBE ౳

  18. FWΛ࢖͏ཧ༝ - ੜ࢈ੑͷ޲্ - ܾ·Γ੾ͬͨίʔυΛॻ͔ͣʹࡁΉ - ྑ͋͘Δػೳ͸ϓϥάΠϯ͕͋Δ͜ͱ΋ - ʮ੍ݶʯ͕Ͱ͖Δ͜ͱͰɺઃܭ͕͠΍͍͢ -

    ඼࣭ͷ޲্ - ϩδοΫʹूதͰ͖ɺ৽نίʔυྔΛݮΒͤΔ - ʮྑ͍ઃܭʯ͔Βဃ཭ͮ͠Β͘ͳΔ - ηΩϡϦςΟϗʔϧ͕উखʹຒΊΒΕ͍ͯΔࣄ΋ଟ͍ - େن໛։ൃͷجૅʹͳΓ΍͍͢ - νʔϜʹن໿Λཁٻ͠΍͍͢ - ʢେ఍ʣγοΧϦͨ͠υΩϡϝϯτ͕ଘࡏ͢ΔͷͰֶशɾڭҭ͠΍͍͢
  19. ॴͰɺFW͸ඞਢͳͷ͔ʁ » (PHP<=3ͷࣄ͸লུ) » PHP4͔ΒɺPHPࣗମ͕ϑϨʔϜϫʔΫʹͳͬͨ » DBαϙʔτ΋Sessionαϙʔτ΋͋Δʂ » PHP͚ͩͰେମͷࣄ͸ॻ͚Δ »

    ͍·ͩʹ͜ͷૉ๿ͳੈք͸Ұ෦Ͱ݈ࡏ
  20. ࣌͸ྲྀΕ… ʮৗࣝʯ͕มΘΔ

  21. ʮPHPͰ΋ϧʔλʔ͕ඞཁͰ͸ʁʯ » ʢURLʹ͋Θͤͯॲཧ಺༰Λม͑Δʣ » PHPͰͷϧʔςΟϯά͸HTTPD೚ͤ » form.php,confirm.phpͳͲʹผ͚Δݹ͖Ώ͔͍͠ε λΠϧ͸ʮμα͍ʯʮඇޮ཰తʯ » SEOͩͳΜͩͰɺྑ͍ײ͡ͷURL͕ٻΊΒΕΔ࣌୅

    » RESTʂRESTʂ
  22. ʮςϯϓϨʔτΤϯδϯ΋ॏཁͩʯ » ςϯϓϨʔτΤϯδϯͱͯ͠PHP͸ΞϧςΟϝοτ » ηΩϡΞ͞Λపఈ͢Δͷ͕Ή͔ͣ͗͢͠Δ <?php echo $_GET['foo']; ?> »

    ͜͜ʹ͍Δਓ͕ॻ͘ͱ͸ࢥ͑ͳ͍͕ɺ΢οΧϦॻ͚ ͪΌ͏ » ʢBlogΧελϜҊ݅ͩͱׂͱݟΔ…ίϫΠ…ʣ » ʮੈքฏ࿨ͷҝʹPHPͷྗΛ෧ҹ͢Δඞཁ͕͋Δʯ
  23. ηΩϡϦςΟ͕௿ͯ͘ةݥ » ݱ୅͸༷ʑͳରࡦΛ͠ͳ͍ͱੈքฏ࿨͕อͯͳ͍ » ಙؙຊ͸جຊΫϦΞ͠ͳ͍ͱ͍͚ͳ͍ » PHP͚ͩͰ͸҆શͷͨΊͷ࢓૊Έ͸օແ » ໪࿦࣮૷͸Ͱ͖Δɺ͔͠͠ݸਓͷೳྗࠩ͸ܹ͍͠ »

    htmlspecialcharsͱ͍͏ਖ਼࿐ؙ͔͠ͳ͍ਓ΋… » ਖ਼࿐ؙ͢Βͳ͍ݱ৔΋͠͹͠͹ݟ·͢ » FWΛਖ਼͔ͭ͑͘͠͹ɺ݁ߏԡ͑͞ࠐΊΔ(ཁग़య
  24. ͦͷޙ΋ଓʑͱ » ʮ˓˓(ྫ:ORM)͕͋ΔͱΑͦ͞͏ʯʮ࡞Ζ͏ʯ » ͦΕΒϥΠϒϥϦ͕·ͱ·͍͖ͬͯɺ͍͔ͭ͠օ͕஌ ΔFWͱ͍͏ू߹ମʹ » ͞ΒʹFWؒɺݴޠؒͰݚᮎ͠ɺύΫϦ͋ͬͨΓͯ͠ ྑ͍෺͕Ͱ͖Δ »

    ݱࡏ͸Ұൠਓ͸Α͍FWΛ૪͏Α͏ʹબͿ
  25. ͳΜ΍͔Μ΍͋Γ » ͔ͯ͘͠ੈք͸༷ʑͳFWʹͭͭ·ΕɺΤϯδχΞ͸ ฏ࿨ͷ಺ʹ฻Βͨ͠ͷͩͬͨ… » ʢͲͷFW͕͍͍͔બͿͷ͕େมͳࣄ͸আ͘ʣ

  26. ׬!

  27. ׬Ͱ͸ͳ͍ » ͱ͍͏͜ͱͰɺFW͸ͭ͘Δ΋ͷͰͳ͘બͿͷ͕ݱ୅ » ࣗ෼Ͱۤ࿑͢Δඞཁ͸ͳ͍ » ඞཁ͸ͳ͍ͷʹ… » ΦϨΦϨϑϨʔϜϫʔΫΛ࡞ͬͯ͠·͏ਓ͸͍Δ »

    ࢲͱ͔
  28. ΦϨΦϨϑϨʔϜϫʔΫͱ͸ʁ » ੈͷதʹ͸ྑ͍FW͕୔ࢁ͋Δͷʹɺ Θ͟Θࣗ͟࡞ͯ͠͠·ͬͨFW » ओʹݸਓ΍ɺ৬৔ͳͲڱ͍ͱ͜ΖͰͷΈ࢖ΘΕ͍ͯΔ ࣄ͕ଟ͍ » ʮΦϨΦϨFW͸߹๏Ͱ͢ʂʯ »

    ͦ΋ͦ΋ଟ͘ͷ༗໊FW΋ΦϨΦϨ͔Β࢝·ͬͨΖ͏
  29. ΦϨΦϨͱϊοτΦϨΦϨͷҧ͍͸ʁ » ϑϨʔϜϫʔΫͱͯ҆͠ఆ͍ͯ͠Δʢയવʣ » օ͕ͦͷ࢓༷Λֶ΂ͯʢυΩϡϝϯτ͕੔උ » Ͱ͖Ε͹୔ࢁͷ໨ͱɺݱ৔Ͱࢼ͞Ε͍ͯͯ » Ͱ͖Ε͹σΩ͕Α͚Ε͹Α͍ »

    Ͱ͖Ε͹೔ຊޠॻ੶ͳΜ͔΋ͰͯΕ͹࠷ߴ » ʢఆٛͳΜͯͳ͍ɺͱ͍͏͜ͱͰ͢ʣ
  30. ΦϨΦϨϑϨʔϜϫʔΫѪ޷Ոͷห » ʮΦϨͳΒͦ͜ΒͷFWΑΓྑ͍෺͕ͭ͘ΕΔʂʯ ʢ…ͳΜͯਓ͸গͳ͍ʣ » ʮෳࡶͳFWʹख़ୡ͢ΔΑΓɺ࡞ͬͨํ͕ૣ͍ʯ » ʮ࡞ͬͯΔਓ͕ԣʹ͍Δ͔Βָʯ » ʮઌ૆୅ʑड͚ܧ͕Ε͖ͯͨ͜ͷFW͸࠷ߴʯ

    » ʮOSSΛಋೖ͢ΔͷʹελϯϓϦϨʔ͕஍ࠈʯ » ʮ࡞ͬͯΈ͔ͨͬͨʯ
  31. ΦϨΦϨϑϨʔϜϫʔΫʹର ͢Δ൷൑ྫ » ʮ඼࣭͕ѱ͍ʯ » ʮ΄͍͠ػೳ͕ͳ͍ʯ » ʮܧ͗઀͗ઃܭ͕ଟ͘ɺ೺Ѳͮ͠Β͍ʯ » ʮηΩϡϦςΟʹ໰୊͕͋Δʯ

    » ʮυΩϡϝϯτ͕ͳ͍͠ɺ࡞ͬͨਓ͕ୀ৬ͯ͠஍ࠈʯ » ʮPHPͷόʔδϣϯ্͕͛ΒΕͳ͍ʯ
  32. ͲΕ΋΋ͬͱ΋ͳ͝൷൑ » ͔ͦ͠͠ΕΒ͸੹೚͋ΔॴͰͷ࿩ » झຯͷ୳ڀ৺ͷͨΊͳΒ໰୊ʹͳΒͳ͍ » ࡞ͬͯΈ͍ͨͳΒ࡞Δ΂͖ » ʢ͍ͬͯ͏͔࡞ͬͨ͜ͱͳ͍ͷʁϗϯτʹʁʣ »

    ΦϨΦϨΛ࡞ΔࣄͰ͔Β͔ΘΕΔʢʁʣͷ͸ ͓͔͍͠ʂ
  33. ͱ͍͏͜ͱͰʢʁʣ » օ͞ΜΦϨΦϨϑϨʔϜϫʔΫΛ࡞Γ·͠ΐ͏ʂ » Ͱ΋ɺҰ౓΋ͭͬͨ͘͜ͱ͕ͳ͍ਓ΋͍ͦ͏ » ͱ͍͏͜ͱͰɺຊ೔͸ΦϨʹΑΔΦϨΦϨϏΪφʔ ʹΉ͚ͨΦϨྲྀΦϨΦϨϑϨʔϜϫʔΫ࡞੒ྫΛ঺ հ

  34. ΦϨΦϨϏΪφʔ޲͚৘ใ » ΦϨΦϨϑϨʔϜϫʔΫͷ࡞Γํ » ඞཁͳ΋ͷ » ͋Δͱྑ͍΋ͷ » ͓͢͢Ίࢦ਑

  35. ඞཁͳ΋ͷ » ΍Δؾ » ࢀߟʹͳΔଞͷFW » ࠷ۙݟͨΦγϟϨͳTipsͱ͔ͷϒΫϚ

  36. ͋Δͱྑ͍෺ » ϝʔϧϑΥʔϜ΍ܝࣔ൘Έ͍ͨͳΞϓϦ » ීஈ͔͔͍͑ͯΔطଘFWʹର͢Δෆຬ » ΦϒδΣΫτࢦ޲ϓϩάϥϛϯάͷڭՊॻ » gitɺPHPStormͳͲ

  37. ͓͢͢Ίͳࢦ਑ » ແܭը » ແ੹೚ » ແςετ » ༗ݶ࣌ؒ

  38. Ͱ͸ૣ଎… ͦͷલʹ

  39. ҎԼͷࣄ͸ආ͚Α͏ʂ » ଞਓʹ࢖ΘͤΔ » ࢓ࣄ΍ݸਓαʔϏεͷ੹೚͕͔͔Δॴʹ࢖͏ » ׬੒ͤ͞ΒΕͳ͍͜ͱΛޙչ͢Δ » ʢͦ͏͓͚ͯ͠͹ɺ୭΋൵͠·ͳ͍ʣ

  40. Ͱ͸࡞ͬͯΈ·͢

  41. ʮͳʹ͕͋Ε͹FW͔ͳʁʯ » FW͕ͲΜͳ΋ͷ͔օ͞Μ஌ͬͯΔͱ͸ࢥ͍·͕͢ɺ ͲΜͳFWΛͭ͘Δ͔ͪΐͬͱߟ͑·͠ΐ͏ » ͱΓ͋͑ͣLaravelͷػೳҰཡΛݟͯΈͨ

  42. Routing, Middleware, Controllers, Requests, Responses, Views, Blade Templates, Authentication, Authorization,

    Artisan Console, Billing, Cache, Collections, Elixir, Encryption, Errors & Logging, Events, Filesystem / Cloud Storage, Hashing, Helpers, Localization, Mail, Package Development, Pagination, Queues, Redis, Session, SSH Tasks, Task Scheduling, Testing, Validation, Query Builder, Migrations, Seeding, Eloquent ORM,
  43. ແཧ

  44. ΦϨΦϨϑϨʔϜϫʔΫ੡࡞ ৺ಘΛࢥ͍ग़͢ » ༗ݶ࣌ؒʹऴΘΒͤΔ » ࠷ॳʹࢭΊॴΛܾΊ͓ͯ͘ » ྫʮ߹ܭ˓೔Ҏ಺ʹͰ͖ΔΑ͏ʹ͢Δʯ » ྫʮ͋Δ࣮૷ʹ਺࣌ؒ೰ΜͩΒࠓճ͸ఘΊΔʯ

    » ྫʮ͓खຊΛ౔೔Ͱཧղग़དྷͳ͍ͳΒ࣍ճʹʯ
  45. ϏΪφʔ͸·ͣ͸ϚΠΫϩϑ ϨʔϜϫʔΫ » ϧʔλʔʢίϯτϩʔϥʔʣ » ςϯϓϨʔτΤϯδϯʢϏϡʔʣ ͜ͷೋͭͰϑϨʔϜϫʔΫͱݴ͍ுΕΔͷͰΦτΫʂ

  46. ϧʔλʔ » URLˍMethod౳ͷ൑ఆύλʔϯΛొ࿥ɾอ࣋ » ࣮ߦ࣌ʹରԠ͢Δ΋ͷΛܾఆͯ͠ฦ͢

  47. ςϯϓϨʔτΤϯδϯ » ϧʔλʔͰ࣮ߦͨ͠ίʔυͷ݁ՌΛ੔ܗ͢Δɺओʹ HTMLΛग़ྗ͢Δͷʹ࢖ΘΕΔͷ͸͝ଘ͡ͷ௨Γ » PHPࣗମ͕΄ͱΜͲςϯϓϨʔτΤϯδϯ

  48. ͜ͷೋ͚ͭͩͰ͢ΑɺͳΜ͔͙͢ʹͰ͖ͦ͏Ͱ͢Ͷʂ͍ ·͙ͭͬͯ͘͢Έ·͠ΐ͏ʂ

  49. ͱ͍͏͜ͱͰ׬੒ ͨ͠΋ͷ͕ίνϥ Ͱ͢

  50. Ore frameworkര஀ʂʂ » ΦϨϑϨʔϜϫʔΫʂ » ࡞੒೔਺͸̍೔͘Β͍ʂ » https://github.com/uzulla/Ore

  51. ػೳ » ૉ๿ͳϧʔλʔ » '/post/:post_id' Έ͍ͨͳࢦఆ΋ҰԠͰ͖Δ » ૉࡐΛ׆͔ͨ͠ςϯϓϨʔτΤϯδϯ » ͍ͬͯ͏͔΄΅PHPͦͷ··

  52. ಛ௃ » 10೥͘Β͍લʹΈͨײ͡Λ࠶ݱʂ » ݱ୅ͷFW͔ΒΈΕ͹ҟ༷ʹγϯϓϧʂ » 1ϑΝΠϧɺؔ਺10ݸ͘Β͍ͰͰ͖ͯΔͧʂ » ॳ৺ऀʹΉ͔͍ͣ͠OOP΋ແ͠ʂؔ਺Ͱ͓̺ʂ

  53. <?php // index.php require_once(dirname(dirname(__FILE__)) . "/app/ore.php"); define("DB_DSN", 'sqlite:' . dirname(dirname(__FILE__))

    . "/db.sqlite"); option('HTML_TITLE', "ͳ͔ͭ͠ͷੈքͰ͢"); route('/', 'post_list'); route('/post/create', 'post_create'); route('/post/:id', 'post_show'); route('/reset', 'post_reset'); run(); ?>
  54. None
  55. route('/', 'post_list'); route('/post/create', 'post_create'); route('/post/:id', 'post_show'); route('/reset', 'post_reset'); run();

  56. function route($path = null, $func_name = null) { // ؔ਺ऴྃ࣌ʹ΋ফ͑ͳ͍഑ྻͱͯ͠$route_listΛએݴ

    static $route_list = array(); // $keyͱ$val྆ํʹԿ͔ೖ͍ͬͯΕ͹ɺ$pathΛΩʔʹ$func_nameΛอଘ if (!is_null($path) && !is_null($func_name)) $route_list[$path] = $func_name; // Ҿ਺ࢦఆແ͠ͳΒɺ$route_listΛ·Δ͝ͱฦ͢ if (is_null($path)) return $route_list; // $pathҾ਺͕༗ΓɺͦͷΩʔ͕route_listʹ͋Ε͹ɺͦΕΛฦ͢ if (isset($route_list[$path])) return $route_list[$path]; // Έ͔ͭΒͳ͔ͬͨͷͰɺnullΛฦ͢ return null; }
  57. function run() { // ݱࡏͷΞΫηεʹରԠ͢ΔPathΛݕࡧ $path = find_match_path(); // pathʹରԠ͢Δؔ਺໊ΛͱΓͩ͠ɺ࣮ߦ

    call_user_func(route($path)); }
  58. function find_match_path() { $uri = $_SERVER['REQUEST_URI']; foreach (path_regex() as $path

    => $regex) { if (preg_match($regex, $uri, $matches)) { $match_path = $path; break; } } if (!isset($match_path)) { return 'notfound'; } foreach ($matches as $k => $v) { if (preg_match('/^[0-9]/u', $k)) { continue; } option($k, urldecode($v)); } return $match_path; }
  59. function path_regex() { $regex_list = array(); foreach (route() as $route

    => $cb) { $regex_list[$route] = '#\A' . preg_replace_callback( '#:([\w]+)#', function ($m) { return "(?P<{$m[1]}>[^/]+)"; }, $route ) . '\z#'; // ex: #\A/post/(?P<id>[^/]+)\z# } return $regex_list; }
  60. function render($template, $params = array()) { extract($params); ob_start(); include(TEMPLATE_DIR .

    $template); $html = ob_get_clean(); echo $html; }
  61. // ݺͼग़͠ render('ʙʙ',array('name'=>$name)); ↓ // include͞ΕΔςϯϓϨ಺ͷίʔυ <?php echo $params['name']; ?>

    // ↑Ͱ͸ͳ͘ɺ↓Έ͍ͨʹ͔͖͍ͨΑͶʁ <?php echo $name; ?>
  62. ௕͘ͳΔͷͰ͜ͷ΁ΜͰ » Githubʹʢ͸͔ͣ͠ͳ͕Βʣ͕͍͋ͬͯ·͢ͷͰɺ ޙͰಡΜͰস͍ͬͯͩ͘͞ɻ

  63. ʮͨͷ͍͠ʂʯ » ͳ͔ͭ͠ςΫχοΫΛͻ͞ͼ͞ʹ͔ͭ͏ͱ৽઱ʂ » ͳΜ͔ͩΜͩମ͕͓΅͑ͯͯεΠεΠ͔͚ͯͨͷ͠ ͍ʂ » Ͳ͏Ͱ͢ʁ10೥લͷςΫχοΫ΋झ͕͋Γ·͢Α Ͷʁ »

    ʮΦϨΦϨFW࡞Γͬͯͨͷ͍ͦ͠͏ʙʂʯ » Ͳ͏Ͱ͢ʁͨͷͦ͠͏Ͱ͠ΐ͏ʁ
  64. Έͳ͞Μͷײ૝ ʮੲ࿩͡Όͳ͍͔ʂ;͚͟Μͳʂʯ

  65. ͜ͷ··ͩͱՈʹؼΕͳ͘ͳ Γͦ͏ͳͷͰ » ΋͏ҰͭϑϨʔϜϫʔΫΛ࡞Γ·ͨ͠

  66. Ore2 Framework ര஀ʂ » ΦϨΦϨϑϨʔϜϫʔΫʂ » ੡࡞೔਺͸̏ഒͷ໿ࡾ೔ʂ » https://github.com/uzulla/Ore2

  67. ಛ௃ » OreͱҧͬͯOOPରԠʢʁʣʂ » PSR-3,4,7,11(Draft)ʹ(ଟ෼)४ڌʂ » ྲྀߦΔ͔΋͠Εͳ͍PSR-7Λ࢖ͬͨϛυϧ΢ΣΞʹ ରԠʂ » PHP7ରԠʂͱ͍͏͔7Ҏ߱Ͱ͔͠͏͔͝ͳ͍ʂ

  68. ػೳ (໺๬) » ϧʔλʔ » TwigͬΆ͍ςϯϓϨʔτΤϯδϯ » ϩΨʔ » PSR-7ɺMiddlewareରԠ

    » ίϯςφʢϩέʔλʣ » ηογϣϯ
  69. ػೳ (ݱ࣮) » ϧʔλʔ » TwigͬΆ͍ςϯϓϨʔτΤϯδϯ × » ϩΨʔ »

    PSR-7ɺMiddlewareରԠ˚ » ίϯςφʢϩέʔλʣ » ηογϣϯ ˚
  70. ʮࡾ೔Ͱ͸ແཧ!!ʯ » ςϯϓϨʔτΤϯδϯ » ύʔαʔϨΩαʔτʔΫφΠβʔ » Request/ResponseInterface ʢͱ෇ਵ͢ΔServerRequestInterface౳ʣ࣮૷େม » ZendઌੜʹཔΓ·ͨ͠

    » ηογϣϯ » ੜࣽ͑ʢਅͷPSR-7ରԠͷηογϣϯ໘౗ʂʣ
  71. <?php //index.php declare(strict_types=1); include __DIR__."/../vendor/autoload.php"; // Route ొ࿥ $router =

    new \Ore2\Router(); $router->get('/', function(){ return $this->html('<span style="color:red">123</span>'); }); $router->get('/name/:name', function(){ return $this->html("hello {$this->c->routeParams['name']}"); }); $router->get('/sample', '\\MyApp\\SampleAction::sample'); $router->get('/sample_json', '\\MyApp\\SampleAction::sampleJson'); // PSR-7ΦϒδΣΫτͷϑΝΫτϦΛ࣮૷͢ΔͷఘΊ·ͨ͠ $request = \Zend\Diactoros\ServerRequestFactory::fromGlobals(); $response = new \Zend\Diactoros\Response(); // route ղܾ $match_result = $router->findMatch($request->getMethod(), $request->getRequestTarget()); // ֤छϔϧύʔΛίϯςφʹ͍ΕΔ $container = new \Ore2\Container(); $container->config = require __DIR__."/../settings.php"; $container->session = new \Ore2\Session(new \Ore2\Session\Storage\PHPSession()); $container->template = new \Ore2\Template($container->config['template']); $container->logger = new \Ore2\Logger(); // ΞΫγϣϯΛ࡞੒ $action = $match_result->buildAction($container); // Middlewareͱ࣮ͯ͠ߦ $seqencer = new \Ore2\MiddlewareSequencer([ new \Ore2\Transmitter(), $action ]); $seqencer($request, $response);
  72. None
  73. Ͱ͸ίʔυ঺հ… » ͱ͍͕ͨ͠ɺ͕͢͞ʹεϥΠυͰͭΒͭΒ঺հ͢Δ ͷ͕ݫ͍͠ίʔυྔ » ͳͷͰμΠδΣετͰ঺հ » ڵຯ͕͋Δํ͸GithubͰݟ͍ͯͩ͘͞

  74. » PHP7લఏͰ૊Έ࢝Ίͨ͠ɺ͔ͤͬ͘ͳͷͰ declare(strict_types=1);ɺҾ਺ܕࢦఆ΍ฦ஋ܕ ࢦఆ΋υϯυϯ෇༩ » PSR-4ରԠͳͷͰComposerͷAutoloader » ϧʔλʔ͸ؔ਺໊Ͱͳ͘Ϋϩʔδϟɺ·ͨ͸Ϋϥεϝ ιου໊ࢦఆ͕Մೳ »

    ྲྀੴʹHTTPϝιουʹରԠ » Logger͸PSR-3४ڌ
  75. » ίϯςφ͸ҙຯͳ͘PSR-11(Draft)ʹ΋ରԠ͠ɺ ArrayAccessͱ__get/set΋࣮૷ » Session͸(ҰԠ)PSR-7Ͱಈ͘Α͏ʹ࡞੒ » CSRFΨʔυ΍ྫ֎τϥοϓ౳ΛPSR-7 Middleware ͱ࣮ͯ͠૷ »

    relay(relayphp.com)෩ͷϛυϧ΢ΣΞ࣮ߦػೳΛ ༻ҙ » ϧʔτઃఆͰɺΞΫγϣϯʹΫϩʔδϟΛ౉ͯ͠΋ bindToͰ$thisܦ༝Ͱ৭ʑ৮ΕΔ » etc,etc
  76. PSRͰॻ͚ͦ͏ͳ΋ͷશ෦ॻ ͍ͯΈͨ » ͱ͍͏͜ͱͰɺݸਓతʹ͸ຬ଍Ͱ͢ʂ » ʢԿΛ͍ͬͱΔΜ͍ͩͭ͜͸ʣ

  77. PSR-7ʹ͍ͭͯͪΐͬͱ঺հLT

  78. PSR-7ʹ͍ͭͯ » Request/Response ObjectͷInterface࢓༷ » ϒϥ΢β͔ΒͷϦΫΤετ৘ใ͕શ෦͸͍ͬͨΦϒδ ΣΫτ » PerlͰ͸PSGIɺRubyͩͱRackΈ͍ͨͳ΋ͷ »

    PHPͰ΋աڈͳ͔ͬͨΘ͚Ͱ͸ͳ͍͕ɺFWຖʹޓ׵ ੑ͸ͳ͔ͬͨ
  79. ͳʹ͕خ͍͠ͷʁ » ී௨͸ɺಛʹ͏Ε͘͠ͳ͍ » ݸਓతʹ͸ » ΦϨΦϨFWѪ޷Ոతʹ͸ָʹςετͰ͖ͦ͏ » ଞͷݴޠͬΆͯࣗ͘વʹײͯ͡خ͍͠ »

    ReactPHP౳ΞϓϦέʔγϣϯαʔόʔ͕ରԠ͢ Ε͹ָͦ͠͏ʂ=>࣮ࡍπΠʔτΛݟͨ » Middleware͕ͨͷͦ͠͏
  80. ͳʹ͕خ͘͠ͳ͍ͷʁ » ʢ౰໘͸ʣແବ͕૿͑ΔͷͰ஗͘ͳΔ » $_*Λ௚Ͱ৮Δࠓ·Ͱͱޓ׵ੑ͕ແ͍ » PHP७ਖ਼ͷsession͕(ຊདྷͳΒ)ແ͘ͳΔ » ·ͩ࢖͑Δ࣮૷͕બ΂ͳ͍

  81. ·͋ɺී௨ͷਓ͸ؾʹ͠ͳ͍ » FWͷϔϧύ΍γϣʔτΧοτͰӅṭ͞ΕΔͩΖ͏ » FW੍࡞ऀ͚͕ͩؾʹ͍ͯ͠Ε͹͍͍ͷͰ͸… » ͦ͏ɺΦϨΦϨFW੍࡞ऀͳΒؾʹ͠ͳ͍ͱͶʂʈʈ

  82. // ZendͷPSR-7࣮૷ $request = \Zend\Diactoros\ServerRequestFactory::fromGlobals(); $response = new \Zend\Diactoros\Response(); //

    ΞΫγϣϯΛϧʔλʔͰܾఆ ΞΫγϣϯ = ϧʔλʔ($request); // ࣮ߦ $response = ΞΫγϣϯ($request, $response); // ԿΒ͔ͷํ๏Ͱ$responseΛૹ৴ ૹ৴͢Δ܅($response);
  83. // request͔ΒPOSTऔಘྫ $name = $request->parsedBody['name'] ?? ''; // ϨεϙϯεΦϒδΣΫτ࡞੒ $response

    = $response ->withStatus(200); ->withHeader('Content-Type', 'text/html'); $body = new \Zend\Diactoros\Stream('php://memory', 'w'); $body->write("Hello world"); $response = $response->withBody($body); return $response; // ͜ͷޙͰૹ৴܅ͳͲͰૹ৴͞ΕΔ
  84. PSR-7 middlewareʹ͍ͭͯ » ঢ়ଶ͕άϩʔόϧม਺͔ΒҾ͖͸͕͞ΕͨͷͰɺϑΟ ϧλʔΈ͍ͨͳ͜ͱ͕΍Γ΍͍͢ » Rack Middleware΍Plack Middleware »

    ʮͦ͜ΒͷFWʹ΋ϛυϧ΢ΣΞ͋Δ͡ΌΜʁʯ ʮͦΕ͕શ෦ͷFWͰڞ௨ͷIFʹͳΕ͹ɺເ͕ʁʯ ʮʮ޿͕Δʂʂʯʯ
  85. ϛυϧ΢ΣΞͷ֓೦ਤ (A,B,C,D͸ϛυϧ΢ΣΞ) A B C D |-req&res->| |-req&res->| |-req&res->| |

    |<-res-----| |<-res-----| |<-res-----|
  86. ༻్͸ແ਺ɺΦϨΦϨతʹ͸ ເ͕͋Δ » ೖྗ/ग़ྗͷՃ޻ » CSRFରࡦ » ೝূ » ҆શੑ޲্ʹ༗༻ͳϔομʔͷૹ৴

    » ग़ྗ࣌ʹஔ׵
  87. » ϑοΫ » Ωϟογϡ » ϩΨʔ » ྫ֎Ωϟον

  88. PSR-7ͷ͠ΜͲ͍ͱײͨ͡ॴ » ͋͘·Ͱ΋HTTPϦΫΤετͷঢ়ଶͳͷͰ… » ஌ͬͯ͸͍͕ͨɺ$_SESSION͕ͳ͍ʂ » Ore2Ͱ͸ޡຐԽ࣮ͯ͠૷ » ͦ΋ͦ΋immutableͳPSR-7ͱ૬ੑ͕ѱ͍ »

    ͏͏ʔʔΜ…
  89. ·͋Ͱ΋ָ͍͠ʂ » mod_phpͱ͔php-fpmͱ͔๞͖ͨͥʂ » ͱ͍͏ํ͸ੋඇ΍ͬͯΈͯ͸͍͔͕Ͱ͠ΐ͏͔

  90. ׬!!!

  91. ׬Ͱ͸ͳ͍

  92. ʮΦϨΦϨϑϨʔϜϫʔΫͷ࿩ͩͬͨ͠ͷͰ͸ʁʯ » ͜͜·Ͱ͢΂ͯ༨ஊʂ » ͜ͷΑ͏ʹɺੜࣽ͑ͷٕज़ΛάΠάΠ࢖ͬͯࢼ͢ͷ ΋ɺΦϨΦϨͷָ͠͞ͳͷͰ͢ʂʂ » Ͳ͏Ͱ͔͢ʁͨͷͦ͠͏Ͱ͠ΐ͏ʁ

  93. ͯ͞ɺOreͱOre2ΛৼΓฦͬ ͯΈ·͠ΐ͏ » Ore͸ͱʹ͔͘࠷খݶͰ͔͔Ε͍ͯΔ » Ore2͸ڽͬͯ͸͍ͳ͍͚Ͳཉுͬͨ » Ͱɺ࣮ࡍ͜ΕͲΕ͘Β͍େมͳͷʁ

  94. None
  95. » Ore » 9 commits / 588 ++ / 168

    -- » Ore2 » 62 commits / 4,106 ++ / 1,063 --
  96. ͱɺΈΔͱɺͲ͏Ͱ͔͢ » ʮॴḨ͜Μͳ΋ͷʢʣͳͷʹɺͦΕͬΆ͘͢Δͷ໘౗ ͦ͏…ʯ » ͦ͏͓΋͍·ͤΜ͔ʁ » ʮΘͨ͠ʹ΋౔೔Ͱ࡞ΕΔ͔ͳʁʯ » ͦ͏ࢥ͏͔΋͠Ε·ͤΜ…

  97. ͦΜͳ͜ͱͳ͍ʂ ͋ͳͨ΋ࠓ໷தʹ ͋ͳ͚ͨͩͷ FWʂʂ

  98. ࡢࠓͷPHP͸… » ϥΠϒϥϦ͕ΊͬͪΌͦΖͬͯΔʂ

  99. » ʮϧʔλʔ͸ʁʯ » ୔ࢁ͋Γ·͢ʂ » ʮςϯϓϨʔτΤϯδϯ͸ʁʯ » ୔ࢁ͋Γ·͢ʂ » ʮ˓˓͸ʁʯ

    − ʢଟ෼ʣ୔ࢁ͋Γ·͢ʂ
  100. େ஍(OSS)ͷܙΈʹײँ…ʂ » ΠέͯΔϥΠϒϥϦΛެ։ͯ͠Βͬ͠ΌΔํʑ » ຊ೔΋Կਓ΋͍Βͬ͠Ό͍ͬͯΔ

  101. બͿͷ͸͠ΜͲ͍ͷͰ͸ » ·͋ΦϨΦϨ͔ͩΒαϯϓϧͷงғؾ͔Βؾܰʹ͑Β ΅͏ʂ

  102. ͱ͍͏͜ͱͰ΍ͬͯΈͨ » ຊ೔ࡾͭ໨! » Oredakedenai FW! » ςϯϓϨʔτΤϯδϯ͸Twig » ϧʔλʔ͸zonuexe/simple-routing

  103. <?php include __DIR__."/../vendor/autoload.php"; \MyApp\Db::$pdo = new \PDO("sqlite:".__DIR__."/../db.sqlite"); $container = [

    'template' => new Twig_Environment( new Twig_Loader_Filesystem(__DIR__."/../template") ) ]; $routing_map = [ ['GET', '/', '\MyApp\Post::showList' ], ['GET', '/post/:id', '\MyApp\Post::show', ['id' => '/^(\d+)$/']], ['POST', '/post/create', '\MyApp\Post::create' ], ['GET', '/reset', '\MyApp\Post::reset' ], '#404' => '\MyApp\Post::notfound' ]; $router = new \Teto\Routing\Router($routing_map); $action = $router->match($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']); if (!preg_match('|\A([\\a-zA-Z0-9_]*)::([a-zA-Z0-9_]+)\z|u', $action->value, $matches)) throw new \InvalidArgumentException('invalid action string:' . $action->value); $method_name = $matches[2]; (new $matches[1]($container))->$method_name($action->param);
  104. » 2 commits / 398 ++ / 0 -- »

    ੡࡞࣌ؒ30෼͆ʂ » ୹͍ʂ
  105. » ެ։͞Ε͍ͯΔϥΠϒϥϦΛ͔ͭͬͯFWΛͭ͘Δͷ खܰʂʂʂ

  106. ͡Ό͋ͳΜͰࠓճૉखͰೋͭ ΋ॻ͍ͨͷʁ » झຯͰ͢

  107. ͪΐͬͱ·ͬͯɺͦΕͰΦϨΦϨͱ͍͑Δͷ͔ʁ » ॻ͍ͨॴ͸5ʙ10ߦ͘Β͍ͳͷʹΦϨΦϨʁ » ΋ͪΖΜ͜Ε΋وํ͚ͩͷΦϨΦϨͱ͍͑·͢ » ʢ·͋ɺOre2ͩͬͯTwig͔ͭͬͯΔ͠…ʣ » ͍·΍֎෦ͷϥΠϒϥϦ΋͔ͭ͏ͷ͕౰વͰ͋Δ »

    ͋ΜͳFW΍͜ΜͳFWͩͬͯɺͳΜ͔ͩΜͩ Symfony͋ͨΓͷίϯϙʔωϯτΛ͔͍ͭͬͯΔ
  108. ͜ΕͰखܰʹΦϨΦϨͰ͖Δʂ » ࣗ෼͕ॻ͚ͳ͍ͱ͜Ζ͸ؾܰʹआΓΔ » Githubͷ͓ӄͰʮਓؾʯ͸ελʔͰՄࢹԽ » ʢਓؾ≠ग़དྷʣ » ΦϨΦϨϑϨʔϜϫʔΫ࡞੒ʹ͸࠷ߴͷ࣌୅Ͱ͸ʁ »

    Ͱ͖Δͱ͜Ζ͔ΒؾܰʹΦϨΦϨʂ
  109. » ͱ͍͏͜ͱͰɺ΍Βͳ͍ཧ༝͕͋Γ·ͤΜͶʂ(ʁ)

  110. ·ͱΊʹೖ͍͖ͬͯ·͢ » ʢ࣌ؒௐ੔ͱ΋͍͍·͢ʣ

  111. ϛογϯάϐʔεʹؾ෇͚Δ » ϗϯτʹ0͔Β͔͚Δʁҙ֎ͱ͔͚ͳ͍ » ຊ౰ʹ0͔Βͭͬͯ͘Έͳ͍ͱɺΘ͔Βͳ͍΋ͷ͕Θ ͔Βͳ͍ » ੒Ռ෺ͦͷ΋ͷΑΓɺաఔͰ৭ʑͳ෺͕ಘΒΕΔ » ͔ͭ͏͚ͩɺಡΉ͚ͩͰ͸ͳ͍

    » ීஈ࢖͏͚ͩͷϥΠϒϥϦͷҙຯͱԞਂ͞Λ஌ΕΔ » PHP͚ͩͰͳ͍஌͕ࣝඞཁʹͳ͖ͬͯͨΓ
  112. ໪࿦ྗ΋্͕Δ » ίʔυಡղྗ্͕Δ » ίʔυΛ໨త࣋ͬͯಡΉͷ͸ޮՌత » యܕతͳελΠϧΛ͓΅͑ΒΕΔ » ෳ਺ͷFWͰ͔ͭΘΕ͍ͯͨΒఆ൪ͬΆ͍ »

    ઃܭྗ΋্͕Δ
  113. ޻෉Λແࢹ͠ɺγϯϓϧॻ͖௚͢ͱ » ʢࣗ෼Ͱॻ͚ΔϨϕϧʹམͱ͠ࠐΉͱʣ » ٯʹطଘFWͷ޻෉͕ݟ͑Δ » ෳࡶͳͷ͸ಛผͳέʔεʹରԠ͢ΔҝͩͬͨΓ » ʮ஗͍ʯʮॏ͍ʯͷʹ͸ཧ༝͕͋ͬͨΓ »

    ʮ଎͍ʯϥΠϒϥϦ͕৭ʑ޻෉͍ͯ͠Δͷʹؾ෇͘
  114. ݹ͍ٕज़΋ॏཁͱվΊͯؾ෇͘ » ࠓ෩ͳFWͰ΋ɺ࣮૷͸౰વͲΖ͔ͬͨ͘͞Γ » ྫɿ݁ہͳΜͰ΋Ͱ͖Δਖ਼نදݱ͸ਖ਼ٛʂ » ʢࠓճϧʔλʔͷਖ਼نදݱ͸࢖͍ճ͠ʣ » ͳΜ͔ͩΜͩྺ࢙͋Δٕज़͸௕͘࢖͑Δٕज़ͩͱؾ ෇͘

    » ʮ͕Μ͹ͬͯΉ͔ͭͦ͠͏ͳࣄΛษڧ͍ͯͧ͘͠ʂʯ ʮύʔαϨΩαʔτʔΫφΠβʔεςʔτϚγϯʯ ʮ΢ο΢οʯ
  115. ͱֶ͍ͬͨͼ͕͋Δ » PHPΧϯϑΝϨϯεʹ͍Βͬ͠ΌΔ΄Ͳɺͳʹֶ͔ Ϳͷ͕޷͖ͳਓͳΒ͖ͬͱͨͷ͍͠ » ͳΜ͔ͩΜͩͰΈΜͳ΍ͬͯΔͬͯɺͨͷ͍ͬͯ͠ʂ » ͱ͍͏͜ͱͰ » ΦϨΦϨ͠Α͏ͥʂ

  116. ΦϨΦϨ্ڃऀϓϨΠ » ΋͏ΦϨΦϨʹ๞͖ͨ(௄Γͨ)ํ΁ » റΓϓϨΠʢม਺ΛҰݸ΋࢖Θͳ͍ͱ͔ʣ » ৽͍͠࢓༷Λ࣮૷ϓϨΠʢࠓճ͸Ore2͕PSR7ʣ » ͋ΔFWͷίϐʔϓϨΠʢࠓճOre͕͔ͳΓLimonde ͷϚωʣ

    » ੍ݶ࣌ؒͰͲ͜·Ͱͭ͘ΕΔ͔ʢػೳΛఘΊΒΕΔ ͔ʣϋοΧιϯϓϨΠ ϫΠϫΠ΍Δͷ΋ͨͷ͍͠Ͱ͢Αʂʂ
  117. ͦ͏͍͑͹ɺΦϨΦϨͨ͠ޙ ʹͳʹΛ͢Ε͹͍͍ͷ͔ʁ » τʔΫͷԠืͷ࠷ޙʹॻ͍ͯ·͕ͨ͠…

  118. ࣺͯΑ͏ʂʂʂ

  119. ΦϨΦϨΛ࢖͏ͷ͸ඍົ » ʮ࢖͍͍ͨΦϨΦϨFW΋࢖͑ͳ͍ɺ ͜Μͳੈͷத͡Όʢʣʯ » ΦϨΦϨ͸ઑΓ͕ͪ » ΦϨΦϨ͸ଞਓʹ͸ཧղ͞ΕͮΒ͍ » ੹೚͕ͱ΋ͳ͏ͱɺΦϨΦϨͷࣗ༝ָ͕ͭ͞͠͞Β

    ͞ʹͳΔ » ͍͔ͭ͸ϝδϟʔʁͰ΋ࠓͰ͸ͳ͍ͦͬͱด͡Α͏
  120. ͭ·Γ » ਓੜҰ౓Ҏ্͸ΦϨΦϨͯ͠ » ͙͢ʹࣺ͍ͯͯ͜͏ͥʂ » લ͚ͩΛ޲͍ͯʂ » ΤϯδϣΠʂΦϨΦϨʂ

  121. ΦϨΦϨτʔΫ͸Ҏ্Ͱ͢ʂ օ͞·ͷ͝ਗ਼ௌ ΦϨ͍ਃ্͛͠·͢ʂ

  122. ׬