Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

ʢօ͞Μ͍͖ͭͯ ͍͚ͯͨͩͯ· ͢ʁʣ

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

ʮͳΔ΄Ͳʯ » Ͱ͸ຊ୊ʹೖ͍͖ͬͯ·͢ɻ

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

༗໊ͳFW Symfony, Laravel, Lumen, Slim Framework, Yii, PHPixie, FuelPHP, CodeIgniter, CakePHP, ZendFramework, Phalcon, Nette, Silex, fatfree, limonade, DietCake, DietCube, Lithium, Aura, Ethna, etc. etc. 㙽ʹ֯୔ࢁ

Slide 16

Slide 16 text

΋ͬͱ͋Δʂଟ ͍ʂ » 2016-04-12ௐ΂ » ͲΜͲΜ૿͑ͯΔ » (ແ࿦ɺ͜ͷ਺ࣈ͸ϊΠζ ΛؚΉ) » ͜ͷ΄͔ʹɺηϯύΠ͔Β ౉͞ΕͨFWͱ͔΋͋ΔͰ ͠ΐ͏

Slide 17

Slide 17 text

໨తಛԽܕFW΋ » ϒϩάΤϯδϯͷWordpress ౳ » CMSͷDrupal ౳ » ECαΠτͷECCUBE ౳

Slide 18

Slide 18 text

FWΛ࢖͏ཧ༝ - ੜ࢈ੑͷ޲্ - ܾ·Γ੾ͬͨίʔυΛॻ͔ͣʹࡁΉ - ྑ͋͘Δػೳ͸ϓϥάΠϯ͕͋Δ͜ͱ΋ - ʮ੍ݶʯ͕Ͱ͖Δ͜ͱͰɺઃܭ͕͠΍͍͢ - ඼࣭ͷ޲্ - ϩδοΫʹूதͰ͖ɺ৽نίʔυྔΛݮΒͤΔ - ʮྑ͍ઃܭʯ͔Βဃ཭ͮ͠Β͘ͳΔ - ηΩϡϦςΟϗʔϧ͕উखʹຒΊΒΕ͍ͯΔࣄ΋ଟ͍ - େن໛։ൃͷجૅʹͳΓ΍͍͢ - νʔϜʹن໿Λཁٻ͠΍͍͢ - ʢେ఍ʣγοΧϦͨ͠υΩϡϝϯτ͕ଘࡏ͢ΔͷͰֶशɾڭҭ͠΍͍͢

Slide 19

Slide 19 text

ॴͰɺFW͸ඞਢͳͷ͔ʁ » (PHP<=3ͷࣄ͸লུ) » PHP4͔ΒɺPHPࣗମ͕ϑϨʔϜϫʔΫʹͳͬͨ » DBαϙʔτ΋Sessionαϙʔτ΋͋Δʂ » PHP͚ͩͰେମͷࣄ͸ॻ͚Δ » ͍·ͩʹ͜ͷૉ๿ͳੈք͸Ұ෦Ͱ݈ࡏ

Slide 20

Slide 20 text

࣌͸ྲྀΕ… ʮৗࣝʯ͕มΘΔ

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

ʮςϯϓϨʔτΤϯδϯ΋ॏཁͩʯ » ςϯϓϨʔτΤϯδϯͱͯ͠PHP͸ΞϧςΟϝοτ » ηΩϡΞ͞Λపఈ͢Δͷ͕Ή͔ͣ͗͢͠Δ » ͜͜ʹ͍Δਓ͕ॻ͘ͱ͸ࢥ͑ͳ͍͕ɺ΢οΧϦॻ͚ ͪΌ͏ » ʢBlogΧελϜҊ݅ͩͱׂͱݟΔ…ίϫΠ…ʣ » ʮੈքฏ࿨ͷҝʹPHPͷྗΛ෧ҹ͢Δඞཁ͕͋Δʯ

Slide 23

Slide 23 text

ηΩϡϦςΟ͕௿ͯ͘ةݥ » ݱ୅͸༷ʑͳରࡦΛ͠ͳ͍ͱੈքฏ࿨͕อͯͳ͍ » ಙؙຊ͸جຊΫϦΞ͠ͳ͍ͱ͍͚ͳ͍ » PHP͚ͩͰ͸҆શͷͨΊͷ࢓૊Έ͸օແ » ໪࿦࣮૷͸Ͱ͖Δɺ͔͠͠ݸਓͷೳྗࠩ͸ܹ͍͠ » htmlspecialcharsͱ͍͏ਖ਼࿐ؙ͔͠ͳ͍ਓ΋… » ਖ਼࿐ؙ͢Βͳ͍ݱ৔΋͠͹͠͹ݟ·͢ » FWΛਖ਼͔ͭ͑͘͠͹ɺ݁ߏԡ͑͞ࠐΊΔ(ཁग़య

Slide 24

Slide 24 text

ͦͷޙ΋ଓʑͱ » ʮ˓˓(ྫ:ORM)͕͋ΔͱΑͦ͞͏ʯʮ࡞Ζ͏ʯ » ͦΕΒϥΠϒϥϦ͕·ͱ·͍͖ͬͯɺ͍͔ͭ͠օ͕஌ ΔFWͱ͍͏ू߹ମʹ » ͞ΒʹFWؒɺݴޠؒͰݚᮎ͠ɺύΫϦ͋ͬͨΓͯ͠ ྑ͍෺͕Ͱ͖Δ » ݱࡏ͸Ұൠਓ͸Α͍FWΛ૪͏Α͏ʹબͿ

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

׬!

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

ΦϨΦϨͱϊοτΦϨΦϨͷҧ͍͸ʁ » ϑϨʔϜϫʔΫͱͯ҆͠ఆ͍ͯ͠Δʢയવʣ » օ͕ͦͷ࢓༷Λֶ΂ͯʢυΩϡϝϯτ͕੔උ » Ͱ͖Ε͹୔ࢁͷ໨ͱɺݱ৔Ͱࢼ͞Ε͍ͯͯ » Ͱ͖Ε͹σΩ͕Α͚Ε͹Α͍ » Ͱ͖Ε͹೔ຊޠॻ੶ͳΜ͔΋ͰͯΕ͹࠷ߴ » ʢఆٛͳΜͯͳ͍ɺͱ͍͏͜ͱͰ͢ʣ

Slide 30

Slide 30 text

ΦϨΦϨϑϨʔϜϫʔΫѪ޷Ոͷห » ʮΦϨͳΒͦ͜ΒͷFWΑΓྑ͍෺͕ͭ͘ΕΔʂʯ ʢ…ͳΜͯਓ͸গͳ͍ʣ » ʮෳࡶͳFWʹख़ୡ͢ΔΑΓɺ࡞ͬͨํ͕ૣ͍ʯ » ʮ࡞ͬͯΔਓ͕ԣʹ͍Δ͔Βָʯ » ʮઌ૆୅ʑड͚ܧ͕Ε͖ͯͨ͜ͷFW͸࠷ߴʯ » ʮOSSΛಋೖ͢ΔͷʹελϯϓϦϨʔ͕஍ࠈʯ » ʮ࡞ͬͯΈ͔ͨͬͨʯ

Slide 31

Slide 31 text

ΦϨΦϨϑϨʔϜϫʔΫʹର ͢Δ൷൑ྫ » ʮ඼࣭͕ѱ͍ʯ » ʮ΄͍͠ػೳ͕ͳ͍ʯ » ʮܧ͗઀͗ઃܭ͕ଟ͘ɺ೺Ѳͮ͠Β͍ʯ » ʮηΩϡϦςΟʹ໰୊͕͋Δʯ » ʮυΩϡϝϯτ͕ͳ͍͠ɺ࡞ͬͨਓ͕ୀ৬ͯ͠஍ࠈʯ » ʮPHPͷόʔδϣϯ্͕͛ΒΕͳ͍ʯ

Slide 32

Slide 32 text

ͲΕ΋΋ͬͱ΋ͳ͝൷൑ » ͔ͦ͠͠ΕΒ͸੹೚͋ΔॴͰͷ࿩ » झຯͷ୳ڀ৺ͷͨΊͳΒ໰୊ʹͳΒͳ͍ » ࡞ͬͯΈ͍ͨͳΒ࡞Δ΂͖ » ʢ͍ͬͯ͏͔࡞ͬͨ͜ͱͳ͍ͷʁϗϯτʹʁʣ » ΦϨΦϨΛ࡞ΔࣄͰ͔Β͔ΘΕΔʢʁʣͷ͸ ͓͔͍͠ʂ

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Ͱ͸ૣ଎… ͦͷલʹ

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Ͱ͸࡞ͬͯΈ·͢

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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,

Slide 43

Slide 43 text

ແཧ

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

ϏΪφʔ͸·ͣ͸ϚΠΫϩϑ ϨʔϜϫʔΫ » ϧʔλʔʢίϯτϩʔϥʔʣ » ςϯϓϨʔτΤϯδϯʢϏϡʔʣ ͜ͷೋͭͰϑϨʔϜϫʔΫͱݴ͍ுΕΔͷͰΦτΫʂ

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

route('/', 'post_list'); route('/post/create', 'post_create'); route('/post/:id', 'post_show'); route('/reset', 'post_reset'); run();

Slide 56

Slide 56 text

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; }

Slide 57

Slide 57 text

function run() { // ݱࡏͷΞΫηεʹରԠ͢ΔPathΛݕࡧ $path = find_match_path(); // pathʹରԠ͢Δؔ਺໊ΛͱΓͩ͠ɺ࣮ߦ call_user_func(route($path)); }

Slide 58

Slide 58 text

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; }

Slide 59

Slide 59 text

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[^/]+)\z# } return $regex_list; }

Slide 60

Slide 60 text

function render($template, $params = array()) { extract($params); ob_start(); include(TEMPLATE_DIR . $template); $html = ob_get_clean(); echo $html; }

Slide 61

Slide 61 text

// ݺͼग़͠ render('ʙʙ',array('name'=>$name)); ↓ // include͞ΕΔςϯϓϨ಺ͷίʔυ // ↑Ͱ͸ͳ͘ɺ↓Έ͍ͨʹ͔͖͍ͨΑͶʁ

Slide 62

Slide 62 text

௕͘ͳΔͷͰ͜ͷ΁ΜͰ » Githubʹʢ͸͔ͣ͠ͳ͕Βʣ͕͍͋ͬͯ·͢ͷͰɺ ޙͰಡΜͰস͍ͬͯͩ͘͞ɻ

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

Έͳ͞Μͷײ૝ ʮੲ࿩͡Όͳ͍͔ʂ;͚͟Μͳʂʯ

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

ػೳ (໺๬) » ϧʔλʔ » TwigͬΆ͍ςϯϓϨʔτΤϯδϯ » ϩΨʔ » PSR-7ɺMiddlewareରԠ » ίϯςφʢϩέʔλʣ » ηογϣϯ

Slide 69

Slide 69 text

ػೳ (ݱ࣮) » ϧʔλʔ » TwigͬΆ͍ςϯϓϨʔτΤϯδϯ × » ϩΨʔ » PSR-7ɺMiddlewareରԠ˚ » ίϯςφʢϩέʔλʣ » ηογϣϯ ˚

Slide 70

Slide 70 text

ʮࡾ೔Ͱ͸ແཧ!!ʯ » ςϯϓϨʔτΤϯδϯ » ύʔαʔϨΩαʔτʔΫφΠβʔ » Request/ResponseInterface ʢͱ෇ਵ͢ΔServerRequestInterface౳ʣ࣮૷େม » ZendઌੜʹཔΓ·ͨ͠ » ηογϣϯ » ੜࣽ͑ʢਅͷPSR-7ରԠͷηογϣϯ໘౗ʂʣ

Slide 71

Slide 71 text

get('/', function(){ return $this->html('123'); }); $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);

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

Ͱ͸ίʔυ঺հ… » ͱ͍͕ͨ͠ɺ͕͢͞ʹεϥΠυͰͭΒͭΒ঺հ͢Δ ͷ͕ݫ͍͠ίʔυྔ » ͳͷͰμΠδΣετͰ঺հ » ڵຯ͕͋Δํ͸GithubͰݟ͍ͯͩ͘͞

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

» ίϯςφ͸ҙຯͳ͘PSR-11(Draft)ʹ΋ରԠ͠ɺ ArrayAccessͱ__get/set΋࣮૷ » Session͸(ҰԠ)PSR-7Ͱಈ͘Α͏ʹ࡞੒ » CSRFΨʔυ΍ྫ֎τϥοϓ౳ΛPSR-7 Middleware ͱ࣮ͯ͠૷ » relay(relayphp.com)෩ͷϛυϧ΢ΣΞ࣮ߦػೳΛ ༻ҙ » ϧʔτઃఆͰɺΞΫγϣϯʹΫϩʔδϟΛ౉ͯ͠΋ bindToͰ$thisܦ༝Ͱ৭ʑ৮ΕΔ » etc,etc

Slide 76

Slide 76 text

PSRͰॻ͚ͦ͏ͳ΋ͷશ෦ॻ ͍ͯΈͨ » ͱ͍͏͜ͱͰɺݸਓతʹ͸ຬ଍Ͱ͢ʂ » ʢԿΛ͍ͬͱΔΜ͍ͩͭ͜͸ʣ

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

ͳʹ͕خ͍͠ͷʁ » ී௨͸ɺಛʹ͏Ε͘͠ͳ͍ » ݸਓతʹ͸ » ΦϨΦϨFWѪ޷Ոతʹ͸ָʹςετͰ͖ͦ͏ » ଞͷݴޠͬΆͯࣗ͘વʹײͯ͡خ͍͠ » ReactPHP౳ΞϓϦέʔγϣϯαʔόʔ͕ରԠ͢ Ε͹ָͦ͠͏ʂ=>࣮ࡍπΠʔτΛݟͨ » Middleware͕ͨͷͦ͠͏

Slide 80

Slide 80 text

ͳʹ͕خ͘͠ͳ͍ͷʁ » ʢ౰໘͸ʣແବ͕૿͑ΔͷͰ஗͘ͳΔ » $_*Λ௚Ͱ৮Δࠓ·Ͱͱޓ׵ੑ͕ແ͍ » PHP७ਖ਼ͷsession͕(ຊདྷͳΒ)ແ͘ͳΔ » ·ͩ࢖͑Δ࣮૷͕બ΂ͳ͍

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

// ZendͷPSR-7࣮૷ $request = \Zend\Diactoros\ServerRequestFactory::fromGlobals(); $response = new \Zend\Diactoros\Response(); // ΞΫγϣϯΛϧʔλʔͰܾఆ ΞΫγϣϯ = ϧʔλʔ($request); // ࣮ߦ $response = ΞΫγϣϯ($request, $response); // ԿΒ͔ͷํ๏Ͱ$responseΛૹ৴ ૹ৴͢Δ܅($response);

Slide 83

Slide 83 text

// 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; // ͜ͷޙͰૹ৴܅ͳͲͰૹ৴͞ΕΔ

Slide 84

Slide 84 text

PSR-7 middlewareʹ͍ͭͯ » ঢ়ଶ͕άϩʔόϧม਺͔ΒҾ͖͸͕͞ΕͨͷͰɺϑΟ ϧλʔΈ͍ͨͳ͜ͱ͕΍Γ΍͍͢ » Rack Middleware΍Plack Middleware » ʮͦ͜ΒͷFWʹ΋ϛυϧ΢ΣΞ͋Δ͡ΌΜʁʯ ʮͦΕ͕શ෦ͷFWͰڞ௨ͷIFʹͳΕ͹ɺເ͕ʁʯ ʮʮ޿͕Δʂʂʯʯ

Slide 85

Slide 85 text

ϛυϧ΢ΣΞͷ֓೦ਤ (A,B,C,D͸ϛυϧ΢ΣΞ) A B C D |-req&res->| |-req&res->| |-req&res->| | |<-res-----| |<-res-----| |<-res-----|

Slide 86

Slide 86 text

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

Slide 87

Slide 87 text

» ϑοΫ » Ωϟογϡ » ϩΨʔ » ྫ֎Ωϟον

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

׬!!!

Slide 91

Slide 91 text

׬Ͱ͸ͳ͍

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

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

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

» Ore » 9 commits / 588 ++ / 168 -- » Ore2 » 62 commits / 4,106 ++ / 1,063 --

Slide 96

Slide 96 text

ͱɺΈΔͱɺͲ͏Ͱ͔͢ » ʮॴḨ͜Μͳ΋ͷʢʣͳͷʹɺͦΕͬΆ͘͢Δͷ໘౗ ͦ͏…ʯ » ͦ͏͓΋͍·ͤΜ͔ʁ » ʮΘͨ͠ʹ΋౔೔Ͱ࡞ΕΔ͔ͳʁʯ » ͦ͏ࢥ͏͔΋͠Ε·ͤΜ…

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

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

Slide 99

Slide 99 text

» ʮϧʔλʔ͸ʁʯ » ୔ࢁ͋Γ·͢ʂ » ʮςϯϓϨʔτΤϯδϯ͸ʁʯ » ୔ࢁ͋Γ·͢ʂ » ʮ˓˓͸ʁʯ − ʢଟ෼ʣ୔ࢁ͋Γ·͢ʂ

Slide 100

Slide 100 text

େ஍(OSS)ͷܙΈʹײँ…ʂ » ΠέͯΔϥΠϒϥϦΛެ։ͯ͠Βͬ͠ΌΔํʑ » ຊ೔΋Կਓ΋͍Βͬ͠Ό͍ͬͯΔ

Slide 101

Slide 101 text

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

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

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);

Slide 104

Slide 104 text

» 2 commits / 398 ++ / 0 -- » ੡࡞࣌ؒ30෼͆ʂ » ୹͍ʂ

Slide 105

Slide 105 text

» ެ։͞Ε͍ͯΔϥΠϒϥϦΛ͔ͭͬͯFWΛͭ͘Δͷ खܰʂʂʂ

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

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

Slide 108

Slide 108 text

͜ΕͰखܰʹΦϨΦϨͰ͖Δʂ » ࣗ෼͕ॻ͚ͳ͍ͱ͜Ζ͸ؾܰʹआΓΔ » Githubͷ͓ӄͰʮਓؾʯ͸ελʔͰՄࢹԽ » ʢਓؾ≠ग़དྷʣ » ΦϨΦϨϑϨʔϜϫʔΫ࡞੒ʹ͸࠷ߴͷ࣌୅Ͱ͸ʁ » Ͱ͖Δͱ͜Ζ͔ΒؾܰʹΦϨΦϨʂ

Slide 109

Slide 109 text

» ͱ͍͏͜ͱͰɺ΍Βͳ͍ཧ༝͕͋Γ·ͤΜͶʂ(ʁ)

Slide 110

Slide 110 text

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

Slide 111

Slide 111 text

ϛογϯάϐʔεʹؾ෇͚Δ » ϗϯτʹ0͔Β͔͚Δʁҙ֎ͱ͔͚ͳ͍ » ຊ౰ʹ0͔Βͭͬͯ͘Έͳ͍ͱɺΘ͔Βͳ͍΋ͷ͕Θ ͔Βͳ͍ » ੒Ռ෺ͦͷ΋ͷΑΓɺաఔͰ৭ʑͳ෺͕ಘΒΕΔ » ͔ͭ͏͚ͩɺಡΉ͚ͩͰ͸ͳ͍ » ීஈ࢖͏͚ͩͷϥΠϒϥϦͷҙຯͱԞਂ͞Λ஌ΕΔ » PHP͚ͩͰͳ͍஌͕ࣝඞཁʹͳ͖ͬͯͨΓ

Slide 112

Slide 112 text

໪࿦ྗ΋্͕Δ » ίʔυಡղྗ্͕Δ » ίʔυΛ໨త࣋ͬͯಡΉͷ͸ޮՌత » యܕతͳελΠϧΛ͓΅͑ΒΕΔ » ෳ਺ͷFWͰ͔ͭΘΕ͍ͯͨΒఆ൪ͬΆ͍ » ઃܭྗ΋্͕Δ

Slide 113

Slide 113 text

޻෉Λແࢹ͠ɺγϯϓϧॻ͖௚͢ͱ » ʢࣗ෼Ͱॻ͚ΔϨϕϧʹམͱ͠ࠐΉͱʣ » ٯʹطଘFWͷ޻෉͕ݟ͑Δ » ෳࡶͳͷ͸ಛผͳέʔεʹରԠ͢ΔҝͩͬͨΓ » ʮ஗͍ʯʮॏ͍ʯͷʹ͸ཧ༝͕͋ͬͨΓ » ʮ଎͍ʯϥΠϒϥϦ͕৭ʑ޻෉͍ͯ͠Δͷʹؾ෇͘

Slide 114

Slide 114 text

ݹ͍ٕज़΋ॏཁͱվΊͯؾ෇͘ » ࠓ෩ͳFWͰ΋ɺ࣮૷͸౰વͲΖ͔ͬͨ͘͞Γ » ྫɿ݁ہͳΜͰ΋Ͱ͖Δਖ਼نදݱ͸ਖ਼ٛʂ » ʢࠓճϧʔλʔͷਖ਼نදݱ͸࢖͍ճ͠ʣ » ͳΜ͔ͩΜͩྺ࢙͋Δٕज़͸௕͘࢖͑Δٕज़ͩͱؾ ෇͘ » ʮ͕Μ͹ͬͯΉ͔ͭͦ͠͏ͳࣄΛษڧ͍ͯͧ͘͠ʂʯ ʮύʔαϨΩαʔτʔΫφΠβʔεςʔτϚγϯʯ ʮ΢ο΢οʯ

Slide 115

Slide 115 text

ͱֶ͍ͬͨͼ͕͋Δ » PHPΧϯϑΝϨϯεʹ͍Βͬ͠ΌΔ΄Ͳɺͳʹֶ͔ Ϳͷ͕޷͖ͳਓͳΒ͖ͬͱͨͷ͍͠ » ͳΜ͔ͩΜͩͰΈΜͳ΍ͬͯΔͬͯɺͨͷ͍ͬͯ͠ʂ » ͱ͍͏͜ͱͰ » ΦϨΦϨ͠Α͏ͥʂ

Slide 116

Slide 116 text

ΦϨΦϨ্ڃऀϓϨΠ » ΋͏ΦϨΦϨʹ๞͖ͨ(௄Γͨ)ํ΁ » റΓϓϨΠʢม਺ΛҰݸ΋࢖Θͳ͍ͱ͔ʣ » ৽͍͠࢓༷Λ࣮૷ϓϨΠʢࠓճ͸Ore2͕PSR7ʣ » ͋ΔFWͷίϐʔϓϨΠʢࠓճOre͕͔ͳΓLimonde ͷϚωʣ » ੍ݶ࣌ؒͰͲ͜·Ͱͭ͘ΕΔ͔ʢػೳΛఘΊΒΕΔ ͔ʣϋοΧιϯϓϨΠ ϫΠϫΠ΍Δͷ΋ͨͷ͍͠Ͱ͢Αʂʂ

Slide 117

Slide 117 text

ͦ͏͍͑͹ɺΦϨΦϨͨ͠ޙ ʹͳʹΛ͢Ε͹͍͍ͷ͔ʁ » τʔΫͷԠืͷ࠷ޙʹॻ͍ͯ·͕ͨ͠…

Slide 118

Slide 118 text

ࣺͯΑ͏ʂʂʂ

Slide 119

Slide 119 text

ΦϨΦϨΛ࢖͏ͷ͸ඍົ » ʮ࢖͍͍ͨΦϨΦϨFW΋࢖͑ͳ͍ɺ ͜Μͳੈͷத͡Όʢʣʯ » ΦϨΦϨ͸ઑΓ͕ͪ » ΦϨΦϨ͸ଞਓʹ͸ཧղ͞ΕͮΒ͍ » ੹೚͕ͱ΋ͳ͏ͱɺΦϨΦϨͷࣗ༝ָ͕ͭ͞͠͞Β ͞ʹͳΔ » ͍͔ͭ͸ϝδϟʔʁͰ΋ࠓͰ͸ͳ͍ͦͬͱด͡Α͏

Slide 120

Slide 120 text

ͭ·Γ » ਓੜҰ౓Ҏ্͸ΦϨΦϨͯ͠ » ͙͢ʹࣺ͍ͯͯ͜͏ͥʂ » લ͚ͩΛ޲͍ͯʂ » ΤϯδϣΠʂΦϨΦϨʂ

Slide 121

Slide 121 text

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

Slide 122

Slide 122 text

׬