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

SymfonyとDoctrineで
簡単クリーンアーキテクチャ

 SymfonyとDoctrineで
簡単クリーンアーキテクチャ

2021/10/02, 03に開催されてPHP Conference Japan 2021の登壇でお話ししたスライドです。

#phpcon2021 #phpcon #php

Ippei Sumida

October 03, 2021
Tweet

More Decks by Ippei Sumida

Other Decks in Programming

Transcript

  1. PHP Conference Japan 2021 Day2
    SymfonyͱDoctrineͰ

    ؆୯ΫϦʔϯΞʔΩςΫνϟ
    ʙϓϩτλΠϐϯάʹͦ͜ΫϦʔϯͳTDD͕׆͖ͨ࿩ʙ

    View full-size slide

  2. ֯ాɹҰฏ
    • ޿ౡݝग़਎ɺେࡕ෎ࡏॅ


    • ϑϦʔϥϯε Webσϕϩούʔ


    • Symfony Meetup KansaiӡӦ౳

    ίϛϡχςΟ׆ಈ΍ͬͯ·͢
    WordCamp Osaka 2019


    ippei Wapuu sukisuki

    View full-size slide

  3. ͨͳ͔ɹͻͯ͞Δ
    • ಉ͘͡େࡕͷ PHPer Ͱ͢


    • ͜ͱ͹ݚڀॴɾॴ௕


    • ͳ͔ͥωοτͱٕज़ࢽͰϚϯΨ
    Λඳ͍͍ͯ·͢
    SoftwareDesign


    PHP ΧϯϑΝϨϯε௨৴

    View full-size slide

  4. • Symfony+DoctrineͰΫϦʔϯΞʔΩςΫνϟͳ࣮Ҋ݅Λ΍ͬͨΑ


    • Symfony, Doctrine, ΫϦʔϯΞʔΩςΫνϟ௒֓ཁ


    • ͳʹΛͲͷΑ͏ʹ࡞͍͔ͬͯͬͨ
    • Symfony, Doctrine, ΫϦʔϯΞʔΩςΫνϟ·ͰͷOOP


    • ৄࡉͳίʔυͷઆ໌
    ↑͓࿩͠͠·͢
    ↓ׂѪ͠·͢
    ࠓ೔͓͸ͳ͢͠Δ಺༰

    View full-size slide

  5. ͜ͱͷ͸͡·Γ

    View full-size slide

  6. ͋͟·͢ʔʂ΍Γ·͢ʔʂ
    ϓϩτλΠϓͭ͘Δ͓࢓ࣄ͋ΔΜͰ͕͢ɺͲ͏Ͱ͔͢ʁ
    ͍ͬ͠ΐʹͲ͏Ͱ͔͢ʁ

    View full-size slide

  7. ࠓճͷҊ݅֓ཁʢԾ૝ʣ
    ϦΞϧλΠϜಈը഑৴αʔϏεͷϓϥοτϑΥʔϜ
    ར༻اۀA
    ར༻اۀB
    AͷϢʔβʔ
    BͷϢʔβʔ
    Ϛελʔίϯςϯπ
    ൪૊දA
    ൪૊දB
    ೝূɾ഑৴
    ஫: ͏ͦ΍Ͱ

    View full-size slide

  8. ͍͟ϓϩτλΠϐϯά
    ͦͷલʹ

    View full-size slide

  9. ։ൃํ਑ͷ૬ஊɺࡦఆ
    #1

    View full-size slide

  10. Ͱ͢Ͷʔɻ
    ͱΓ͍͋͑ͣͬͨΜू·Γ·͔͢ʁ

    View full-size slide

  11. ·ͣ͸ཁٻ֬ೝ
    • ͍͍ͨͩͨཁٻΛ֬ೝ


    • ͦΕΛͲͷΑ͏ͳٕज़ɺํ๏Ͱ࡞͍͔ͬͯ͘૬ஊ

    View full-size slide

  12. ֎෦αʔϏεͱ͔ɺԿ࢖͏͔΋Θ͔Βͳ͍Ͱ͢͠Ͷʔ
    ͍ͬ͡͞ޙͰͲ͏มߋ͞ΕΔ͔Θ͔Μͳ͍ͷͰɺ


    ͳΔ΂͘ૉͷPHPͰ͔ͨΊ·͠ΐ͏͔ɻ
    Ͱ͋Ε͹ɺ͜ͷΞʔΩςΫνϟ͍ͬͯΈ·͔͢

    View full-size slide

  13. ΫϦʔϯΞʔΩςΫνϟ
    ઃܭํ਑͸
    Λ࠾༻

    View full-size slide

  14. ؆୯ͳΫϦʔϯΞʔΩςΫνϟͷઆ໌
    • ґଘํ޲Λ಺෦ʹ޲͔͏Α͏ʹ޲͚ͯͶ


    • ҎԼͷ༷ʹ࣮૷Λ৺͕͚ΔͱΑ͍Α


    • EntitiesʢԫʣʹυϝΠϯϞσϧΛ


    • Use Casesʢ੺ʣʹۀ຿ͷػೳཁ݅Λ


    • Controllersʢ྘ʣʹӬଓԽͱೖग़ྗΛ


    • Devices / DB / UIʢ੨ʣʹٕज़తͳԼࢧ͑΍ϑϩϯτΤϯυΛ


    • ্هͷ࡞ΓํΛνʔϜͰҙࣝͯ͠࡞ΔͱΈΜͳ͕޾ͤͩΑ


    • มʹݻࣥ͠ͳ͍Α͏ʹ͖Λ͚ͭͯͶ

    View full-size slide

  15. ֎ଆ
    ٕज़Λϓϩάϥϛϯά͢Δͱ͜Ζ


    ը໘΍ετϨʔδͳͲ
    ಺ଆ
    ۀ຿Λϓϩάϥϛϯά͢Δͱ͜Ζ


    ݴޠʹΑΔ७ਮͳϩδοΫ


    ͖Ε͍ʹอ͍ͪͨ
    ґଘํ޲
    DIPΛ׆͔ͯ͠಺ଆ͔Β֎ଆ΁ґଘ͠ͳ͍Α͏ʹ
    use
    implement
    🙅

    View full-size slide

  16. ͳ͖ͥΕ͍ʹอ͍ͪͨʁ
    • ۀ຿ʹΑٕͬͯज़͕มΘΔͷ͸Α͋͘Δ͜ͱ


    • ۀ຿ϩδοΫ͕ٕज़ʹґଘ͍ͯ͠Δͱɺٕज़ͷӨڹͰۀ຿ϩδοΫ͕มΘΔ
    ͜ͱʹͳΔ
    ۀ຿ϩδοΫ͕ෳࡶʹͳΔݪҼΛݮΒ͍ͨ͠

    View full-size slide

  17. ֎ଆ ಺ଆ
    ϩάΛMySQLʹอଘ
    ྫɿμʔςΟʔͳϩάอଘ
    ϩά͸MySQLʹอଘ
    MySQL

    View full-size slide

  18. ֎ଆ ಺ଆ
    ϩάΛDynamoDBʹอଘ
    ྫɿμʔςΟʔͳϩάอଘ
    DynamoDBʹม͑·͢
    ۀ຿ϩδοΫΛ

    मਖ਼͠ͳ͍ͱ͍͚ͳ͍
    DynamoDB
    MySQL
    ❗❓

    View full-size slide

  19. ֎ଆ
    ϩάΛMySQLʹӬଓԽ
    ಺ଆ
    ϩάσʔλΛ࡞੒͢Δ
    ґଘํ޲
    ྫɿΫϦʔϯͳϩάอଘ
    ϩά͸MySQLʹอଘ

    View full-size slide

  20. ֎ଆ
    ϩάΛDynamoDBʹӬଓԽ
    ಺ଆ
    ϩάσʔλΛ࡞੒͢Δ
    ґଘํ޲
    ྫɿΫϦʔϯͳϩάอଘ
    DynamoDBʹม͑·͢

    View full-size slide

  21. SymfonyͰ͔͢Ͷʔ
    ͳΔ΂͘ૉͷPHPͰݻΊΔͳΒɺϑϨʔϜϫʔΫ͸

    View full-size slide

  22. όοΫΤϯυ ϑϩϯτΤϯυ

    View full-size slide

  23. ͳͥSymfony+Doctrine?

    View full-size slide

  24. ͳͥSymfony + DoctrineΛબΜ͔ͩ
    • ཁٻ͕ΦϒδΣΫτΛෳ਺ίϯςΩετͰฤू͠Α͏ͱͯ͠Δ


    • ActiveRecordͩͱΫϥε͕ංେͯͪ͠ΐͬͱେม͔΋͠Εͳ͍


    • Doctrine ͸ Data Mapper ܕͷ ORM


    →ϑϨʔϜϫʔΫͱಠཱͨ͠ϥΠϒϥϦ͔ͩΒ


    →Entity ͕ POPO ͳͷͰҙਤͤͣDB͕ಈ͘৺഑͕ͳ͍


    • ΦʔτϫΠϠϦϯάͰඞཁͳΫϥεΛࣗಈͰ஫ೖͰ͖Δ


    • ඞཁʹͳͬͨ࣌఺ͰɺػೳΛίϯϙʔωϯτͱͯ͠ΠϯετʔϧͰ͖Δ

    View full-size slide

  25. Data Mapper ܕ v.s. Active Record ܕ
    id=1
    id=4
    id=1
    id=4
    id=4
    id=1
    id=1
    id=1
    id=4
    ࢀর
    ίϐʔ
    ૢ࡞
    ૢ࡞
    ϏδωεϩδοΫ
    ->save()
    ->
    f
    lush()
    ஗Ԇ


    ϑΣον
    Entity Manager
    ಉظ
    ->save()
    ->save()
    ίϯτϩʔϥʔ
    ΫΤϦ͝ͱʹҟͳΔΠϯελϯεੜ੒ɻ


    ΠϯελϯεʹҰҙੑ͕ͳ͍ɻ != Entity


    DB ࣮ମ͕ͳ͍ͱ੔߹ੑ͕੒Γཱͨͳ͍ɻ


    ϏδωεϩδοΫ͕ʮDBอଘʯ੹຿Λ࣋ͭɻ
    ͢΂ͯͷ Entity ͸Ծ૝తʹΦϯϝϞϦͰ


    ଍Γͳ͍΋ͷ͚ͩΛ஗ԆϑΣονɻ


    Repository ͸ࢀরΛఏڙ͢Δ͚ͩɻ


    ϏδωεϩδοΫ͸OOP͚ͩͰ׬݁͢Δɻ
    ࠩ෼SQLੜ੒

    View full-size slide

  26. Symfony ͷΦʔτϫΠϠϦϯά
    • ΦʔτϫΠϠϦϯά = DI ͷઃఆʹొ৔͠ͳ͍Φϒ
    δΣΫτͰ΋ɺܕએݴʹ߹͏ΦϒδΣΫτΛࣗಈత
    ʹ஫ೖͯ͠ੜ੒͢Δػೳ


    • Laravel ͳͲଟ͘ͷ PHP จԽͰ͸ʮఆٛ͞Εͨ΋ͷ
    ͷத͔Βదͨ͠΋ͷʯΛ஫ೖ͢Δ͜ͱ


    • Symfony ͷ৔߹ɺݸผఆ͍ٛͯ͠ͳ͍ΫϥεͰ΋஫
    ೖ͢ΔΦϒδΣΫτʹͳΕΔ!!


    • → ஫ೖʮ͞ΕΔଆʯͱʮ͢Δ΋ͷʯͷ۠ผ͕ෆཁͳ
    ͷͰɺؾܰʹґଘΛνΣʔϯ͢Δઃܭ͕Ͱ͖Δ
    ͜͜ʹ͋ΔΫϥε͸


    (ྫ֎Λআ͍ͯ) ͥΜͿ


    ࣗಈͰґଘղܾͨ͠Ζ

    View full-size slide

  27. ։ൃ؀ڥ
    ޙʹඞཁʹͳͬͨͷͰ௥Ճ

    View full-size slide

  28. ͜͜·Ͱ·ͱΊ
    • ϓϩτλΠϓΛ࡞Δʹ͋ͨͬͯɺཁٻΛ֬ೝ


    • ࢖༻͢ΔϞσϦϯάٕ๏ɺϑϨʔϜϫʔΫΛબఆ


    • ͳΔ΂͘ૉͷPHPͰϏδωεϩδοΫΛ։ൃ͍ͯ͘͜͠ͱΛ֬ೝ

    View full-size slide

  29. ϖΞϓϩͰσϞ։ൃ
    #2

    View full-size slide

  30. Ͱ͢Ͷʔɻ
    ͜ͷํ਑ͰͲ͏΍ͬͯ࡞͍͔ͬͯ͘ɺҰ౓ϖΞϓϩ͠·͠ΐ͏͔ɻ

    View full-size slide

  31. ։ൃର৅
    mapping

    View full-size slide

  32. ͔ͤͬ͘ͳΜͰɺΦϯϥΠϯͰ͜Εˢ΍ͬͯΈ·ͤΜʁ

    View full-size slide

  33. Symfony CLI
    ͍Ζ͍Ζ࡞ۀͷ͓ख఻͍
    • symfony ( php | pecl | composer | console … )

    .php-versionͰࢦఆͨ͠PHPͷόʔδϣϯͰίϚϯυΛ࣮ߦ

    ෳ਺όʔδϣϯͷPHP͕ೖ͍ͬͯΔ࣌ศརʂ


    • symfony server:start -d

    ϩʔΧϧWebαʔόʔىಈɻ

    docker-compose.ymlͷ಺༰͔Β؀ڥม਺Λੜ੒

    View full-size slide

  34. Symfony CLI + Symfony Console
    ͍Ζ͍Ζ࡞ۀͷ͓ख఻͍
    • symfony console make:”࡞Γ͍ͨ΋ͷ”

    ΤϯςΟςΟ΍ɺίϯτϩʔϥʔʢ&ςϯϓϨʔτʣͳͲͷ࡞੒΢Οβʔυ


    • symfony console doctrine:schema:update —force

    ΤϯςΟςΟΫϥεͱDBͷࠩҟΛௐ΂ɺςʔϒϧߏ੒Λߋ৽


    • Symfony console doctrine:migrations:di
    ff

    ΤϯςΟςΟΫϥεͱDBͷࠩҟΛௐ΂ɺϚΠάϨʔγϣϯϑΝΠϧΛ࡞੒

    View full-size slide

  35. 1. ΤϯςΟςΟ࡞੒
    উखʹೖΕͯ͘ΕΔ
    ͋ͬͯ΋ͳͯ͘΋ςετͷಈ࡞ʹ͸
    ؔ܎ͳ͍͔Βͦͷ··͍࣍͜͏

    View full-size slide

  36. 2. ςετ࡞੒ (PHPUnit)
    ࢦఆͨ͠಺༰ͰΤϯςΟςΟ͕

    ࡞ΒΕΕ͹0,

    View full-size slide

  37. 3. Ϣʔεέʔε࡞੒

    View full-size slide

  38. 3-a. ςετௐ੔
    ύεϫʔυϋογϡԽΛϞοΫ
    ࢦఆͨ͠಺༰ͰΤϯςΟςΟ͕

    ࡞ΒΕΕ͹0,

    View full-size slide

  39. 4. WebαʔϏεʹ૊ΈࠐΈ
    ϧʔςΟϯά
    ࡞ͬͨϢʔεέʔε

    View full-size slide

  40. 5. ϑϩϯτ࡞੒ (TypeScript+JSX)

    View full-size slide

  41. Ͱ͢Ͷʔɻ
    ͳΜ͔͍͚ͦ͏Ͱ͢Ͷɻ

    View full-size slide

  42. ͜͜·Ͱ·ͱΊ
    • ࣮ࡍʹબఆͨ͠΋ͷ͕ػೳ͢Δ͔খ͘͞࡞ͬͯࢼ͢ͱ٢


    • ΫϦʔϯΞʔΩςΫνϟΛҙࣝͯ͋͠Δఔ౓Ϋϥε࡞੒


    • ͜͜ͰTDDɻ


    • Ϣʔεέʔεʹରͯ͠ςετΛهड़


    • DBʹอଘ͠ͳ͍ͷͰɺEntity͕Ͱ͖Ε͹OK


    • ϖΞϓϩʹ͸Code with Me͕ศརͰͨ͠

    View full-size slide

  43. Ϩοπϓϩτʂ
    #3

    View full-size slide

  44. ϓϩτͰ࡞ΔετʔϦʔΛચ͍ग़͠·͠ΐ͏͔

    View full-size slide

  45. ϢʔβʔετʔϦʔϚοϐϯά

    View full-size slide

  46. ϢʔβʔετʔϦʔϚοϐϯάͱ͸
    • ϢʔβʔͷετʔϦʔΛ࣌ܥྻͰચ͍ग़͠ɺ༏ઌ౓Λ͚͍ͭͯ͘


    • ϓϩδΣΫτࢀըऀશһͰ࣮ࢪ


    • ࣌ܥྻɾ༏ઌ౓Ͱ੔ཧ͢Δ͜ͱͰɺҎԼΛ೺Ѳ͢Δ


    • ։ൃॱংʢ·ͣͲ͜ʹ஫ྗ͢Δඞཁ͕͋Δ͔ʣ


    • ൈ͚࿙Ε͕ͳ͍͔


    • ϓϩδΣΫτʹࠐΊͨࢥ͍ʢΊ͋ͯʣ

    View full-size slide

  47. ༏ઌ౓௿
    ༏ઌ౓ߴ
    Ϣʔβ࣌ܥྻ
    اۀొ࿥ ϓϥϯ࡞੒ ϓϥϯҰཡ اۀฤू …
    اۀ৘ใΛొ࿥
    ୅දऀΛొ࿥
    ࢧ෷͍ํ๏Λ

    ొ࿥
    ࣄલϓϥϯ͔Β

    ࡞੒
    ProgramΛ

    ௥Ճ
    ΧελϚΠζ

    ͯ͠࡞੒
    ϓϥϯҰཡΛ

    Ӿཡ
    ϓϥϯͷৄࡉΛ

    Ӿཡ
    اۀ৘ใΛฤू
    ࢧ෷͍ํ๏Λ

    ฤू

    Twitterͱ࿈ܞ
    ઈରඞཁ
    ૣΊʹཉ͍͠
    ٸ͗Ͱ͸ͳ͍
    ϓϩτ։ൃର৅
    ϢʔβΛొ࿥
    ୅දऀΛฤू
    ˞ಛʹॏཁͳՕॴͷΈ

    View full-size slide

  48. Γΐ͏͔͍Ͱ͢ʔ
    Ͱ͸؆୯ͳϞσϦϯά͍͖ͯ͠·͠ΐ͏͔
    ·ͣ͸Entityͷચ͍ग़͔͠Βʙ

    View full-size slide

  49. ॳظͷཁٻ࢓༷ʢԾ૝ʣ
    • ܖ໿๏ਓ͸ࣗ෼ͷ഑৴αΠτͰ഑৴͠์୊


    • ऩ࿥ࡁΈͷίϯςϯπ୯ҐΛʰϓϩάϥϜʱͱݺͿ


    • ϓϩάϥϜΛ഑৴νϟϯωϧͷʰϓϥϯʱʹฒ΂Δ


    • ഑৴ऀ͸ϓϥϯΛΧελϚΠζͰ͖Δ


    • ഑৴αΠτ͸ϓϥϯΛෳ਺νϟϯωϧઃ͚Δ͜ͱ΋Ͱ͖Δ


    • ӡӦ͔Βࣄલఆٛ͞Εͨϓϥϯ͕ఏڙ͞ΕΔ


    • ࢹௌऀΞΫλʔ͸ϓϩάϥϜ୯ମͷΞʔΧΠϒΛ؍Δ͜ͱ͕Ͱ͖Δ
    ஫: ͏ͦ΍Ͱ

    View full-size slide

  50. ͋ʔͦ͏͔ͦ͏͔ɻ͡Όɺ͜Ε͸εΫϦʔϯͬͯײ͡Ͱ͔͢Ͷʁ
    ͳΜ͔ཁ๬ͷ༻ޠ͕͔ͭΈͲ͜Ζͳ͍ͳ͋ɻ

    ͜Εͬͯ΋࣮͠෺͕͋ͬͨΒөըؗΈ͍ͨͳ΋ͷͰʙ
    ϐϯͱ͖·ͨ͠Ͷʙɻ͜͜͸Ͱ͢Ͷ…
    ΈΜͳ༻ޠΛ


    औΓҧ͑Δ

    View full-size slide

  51. ࣮ମΛΠϝʔδͰ͖Δ΋ͷʹஔ͖׵͑Δ
    ※ Մࢉ໊ࢺʹ͢ΔͱΦϒδΣΫτʹ͠΍͍͢

    View full-size slide

  52. ͜͜͸؆୯ʹݴ͑͹͜͏͍͏͜ͱͰ͢ΑͶʔ
    ͜Εͬͯɺཁ͸͜͏͍͏͜ͱͰ͢ΑͶʔʢ࡞੒ͨ͠ਤΛݟͳ͕Βʣ
    Ͱ͢Ͷʔ
    ϞσϦϯάͨ݁͠ՌΛશһʹڞ༗
    ୭΋ޡղ͠ͳ͘


    ͳͬͨ
    💯

    View full-size slide

  53. Γΐ͏͔͍Ͱ͢ʔ
    ͭ͗͸ϢʔεέʔεͷϞσϦϯά͠·͠ΐ͏͔ʔ
    Ͱ͸ϢʔβʔετʔϦʔϚοϐϯάͷʙ͔ΒखΛ͚ͭ·͠ΐ͏

    View full-size slide

  54. ͍͞͠ΐʹͲ͏΍ͬͯ࡞Δ͔࿩͠߹ͬͨͷ͕ޮ͍ͯ·͢Ͷ
    ͍͞͠ΐʹ૬ஊͯ͠࡞ͬͨϨΠϠʔʹ͋Θ͍ͤͯ͘ͱ͜Μͳײ͡Ͱ͔͢Ͷ
    Ͱ͸ɺίʔυʹམͱͯ͠Έ·͔͢…

    View full-size slide

  55. өըؗͰձһొ࿥͢Δײ͡Ͱ͢ΑͶʔ
    Ϣʔβ௥Ճ͢Δͱɺ͜͏ͳΔͬͯ͜ͱͰ͢ΑͶʢ࣮ߦ݁ՌΛݟͳ͕Βʣ
    Ͱ͢Ͷʔ
    ίʔυʹམͱͨ݁͠ՌΛશһʹڞ༗

    View full-size slide

  56. Ͱ͢Ͷʔ
    ͡ΌɺϝʔϧΛૹͬͯɺϢʔβ͕ඞཁͳ৘ใೖྗͨ͠Βొ࿥Ͱ͢Ͷʔ
    ࣮ࡍ͸ϢʔβʹԾొ࿥ϝʔϧૹΔ͔Μ͡Ͱ͔͢Ͷʔ
    ೝࣝ߹Θͤͳ͕ΒϒϥογϡΞοϓ͢ΔՕॴΛ֬ೝ

    View full-size slide

  57. ͳͷͰɺϢʔβͷσʔλ͸͜Μͳײ͡Ͱ͓࣋ͬͯ͘ͷͲ͏Ͱ͔͢ʁ
    ͋ͬɺ΋͔ͨ͠͠Β͜Μͳӡ༻χʔζ΍

    ͋Μͳӡ༻χʔζ͕ग़ͯ͘Δ͔΋ɻೝূ͸ΞΫλʔ͝ͱʹ෼͚ͣɺ

    ΈΜͳڞ௨͕౎߹ྑ͍ͱࢥ͏ΜͰ͕͢Ͳ͏Ͱ͔͢ʁ
    ͳΔ΄Ͳʔ
    ࡞੒࣌ͷؾ͖ͮΛϑΟʔυόοΫ

    View full-size slide

  58. ίʔυͷ௥Ճɾมߋɾഁغ͕ଟൃ
    ࡞੒࣌ͷؾ͖ͮΛϑΟʔυόοΫ
    ʹ

    View full-size slide

  59. ͜͜ͰSymfony + Doctrine͕׆༂!

    View full-size slide

  60. ͜͜ͳ
    Ϣʔεέʔε͸DBอଘॲཧΛ࣋ͨͳ͍ʂ
    4BWFΛݺͿ͡Όͳͯ͘ʮಉظ͢ΔʯΠϝʔδɻϢʔεέʔε͸ʮอଘʯΛҙࣝ͠ͳ͍͍͔ͯ͘Β͍͡Γ΍͍͢ɻ

    View full-size slide

  61. ʮςʔϒϧ͔Βʙͳσʔλऔಘ͢Δ͜ͱͳʂʯͰςετͰ͖Δɻ
    ςετͰͷDBݕࡧ͸ϞοΫͰ୅༻Մʂ

    View full-size slide

  62. Ͱ͢Ͷʔ
    ίʔυ͔͠৺഑͠ͳ͍͍ͯ͘ͷָɻβΫβΫ΍ͬͪΌ͍·ͨ͠ɻ

    ͳΜ͔͍͚ͦ͏Ͱ͢Ͷ

    View full-size slide

  63. ϞσϦϯά
    ςετ࡞Δ
    ։ൃ
    ςετௐ੔
    ΈΜͳʹڞ༗ɾϑΟʔυόοΫ
    ʰϞσϦϯάˠڞ༗ʱ


    Λ܁Γฦͯ͠ɺ

    ϓϩτΛ࡞੒
    σϞɾ׬ྃ

    View full-size slide

  64. ͍Ζ͍Ζ͋ͬͨ͜ͱ

    View full-size slide

  65. ϑϩϯτΤϯυͷਓ͕ͳ͔ͳ͔Έ͔ͭΒͳͯ͘…

    View full-size slide

  66. ͜ΕɺTwigʹ͍͍ͯ͠Ͱ͔͢Ͷʁ
    PHPer ͩͦ͠ͷํ͕εϐʔυग़·͢ΑͶɻ

    Ϣʔεέʔε͸มΘΒͳ͍͠ࢍ੒ʙ

    View full-size slide

  67. όοΫΤϯυ

    View full-size slide

  68. ΍Γ͍ͨ͜ͱΑΓ΋ݟͤΔ͜ͱʹ஫ྗ
    • ૣ͘࡞ͬͯɺૣ͘ϓϩτݟ͍ͤͨͷͰ׳ΕͯΔٕज़ʹγϑτͨ͠


    ※ ৔߹ʹΑΔ


    • Next.jsʢ& TypeScriptʣͷຽͰ͸ͳ͔ͬͨͷͰɺ଎౓͕ࢥ͍ͷ֎ग़ͳ͔ͬͨ
    ͷ΋͋Δɻ

    View full-size slide

  69. ϢʔεέʔεʹRepositoryʢςʔϒϧʣ͕ͲΜͲΜ͍ࢗͬͯ͘͞ͳʔ…

    View full-size slide

  70. ར༻͢Δςʔϒϧ਺͚ͩҾ਺͕૿͑Δ…

    View full-size slide

  71. ඞཁͳςʔϒϧ͕૿͑Δ͝ͱʹɺมߋ͕ඞཁ
    ແବʹςετͷमਖ਼͕૿͑ͯ͠·͏…

    View full-size slide

  72. ͜Εɺࠓ͸଱͑Ε·͚͢Ͳޙʑ͠ΜͲ͘ͳΓ·͢Ͷʔ
    ͻΒΊ͍ͨ

    View full-size slide

  73. %BUB4FSWJDF*OUFSGBDFΛ
    ͭ͘Δ
    %BUB4FSWJDFͰ
    ࣮૷
    4FSWJDFͰ3FQPTJUPSZΛ

    ར༻

    View full-size slide

  74. Repositoryʢςʔϒϧʣʹґଘ͠ͳ͍࡞Γʹʂ

    View full-size slide

  75. ΦʔτϫΠϠϦϯά
    ࣮૷Ϋϥεʹ޷͖ͳ͚ͩRepositoryΛૠͤΔ

    View full-size slide

  76. ʮ%#͔Βʙͳσʔλऔಘ͢Δ͜ͱͳʂʯͰςετͰ͖Δɻ
    ςετͷमਖ਼΋ෆཁʹʂ
    ςʔϒϧ͕૿͑ͯ΋มߋͷඞཁ͕ͳ͍

    View full-size slide

  77. DBͱͷ΍ΓͱΓΛServiceʹ·ͱΊΔ
    • Ϣʔεέʔε͝ͱʹDBͷ΍ΓͱΓΛInterfaceͱͯ͠ఆٛ͢Δ


    • ϦϙδτϦ܈Λ·ͱΊΔϑΝαʔυ໾ͷײ͡


    • ςετͷमਖ਼΋ָʹͳΔ


    • ͜͜͸SymfonyͷΦʔτϫΠϠϦϯά͕େ׆༂ʂ

    View full-size slide

  78. ʢը໘ʴίϯτϩʔϥʔɺؒʹ߹͏͔ͳʔ…
    Ϣʔεέʔε͸ॱௐͦ͏Ͱ͚͢Ͳɺը໘पΓ͸େৎ෉Ͱ͔͢ʁ
    ։ൃظؒ΋ͦΖͦΖऴ൫Ͱ͢͠ɺ࡞͍͖ͬͯ·͢Ͷʔ

    View full-size slide

  79. ͳΜ͔ɺ͜ΕΊͬͪΌૣ͘࡞Εͯٯʹෆ҆ͳΜͰ͚͢Ͳ…
    ࢥͬͯͨҎ্ʹ໎͏͜ͱͳ͍Ͱ͢Ͷ
    ։ൃத

    View full-size slide

  80. ೖྗ஋Λ༻ҙ͢Δ
    ϢʔεέʔεΛ࢖͏
    ݁ՌΛ֬ೝ͢Δ
    ೖྗ஋Λड͚औΔ
    ϢʔεέʔεΛ࢖͏
    ݁ՌΛը໘දࣔ͢Δ
    Ϣʔεέʔεςετ ίϯτϩʔϥʔʴը໘
    ͕͜͜มΘ͚ͬͨͩ
    DBͱಉظ

    View full-size slide

  81. ೖྗ஋Λ༻ҙ͢Δ
    ϢʔεέʔεΛ࢖͏
    ݁ՌΛ֬ೝ͢Δ
    ೖྗ஋Λड͚औΔ
    ϢʔεέʔεΛ࢖͏
    ݁ՌΛը໘දࣔ͢Δ
    Ϣʔεέʔεςετ ίϯτϩʔϥʔʴը໘
    ͕͜͜ΫϦʔϯͳ΄Ͳɺ

    ίϯτϩʔϥʔͰ΍Δ͜ͱ͕গͳ͍
    DBͱಉظ

    View full-size slide

  82. ͋ͱͰɺͦͦͬ͘͜͜͞ΓೖΕΔ͜ͱͰ͖ΔΜͰେৎ෉Ͱ͢Αʂ
    ͜ͷϖʔδ͸ೝূޙͷϖʔδͳΜͰ͕͢ɻ
    ࠓ͸Πϝʔδڞ༗Λ༏ઌͯ͠ΔͷͰɺೝূͬ͢ͱ͹ͯ͠·͢

    View full-size slide

  83. ೖྗ஋Λड͚औΔ
    ϢʔεέʔεΛ࢖͏
    ݁ՌΛը໘දࣔ͢Δ
    ίϯτϩʔϥʔʴը໘
    DBͱಉظ
    Ϣʔβೝূ͢Δ
    ͜ΕΛ௥Ճ

    View full-size slide

  84. ࠓݟͯΔਓ͕ݟͨ͜ͱ͋Δ͔Λ

    ஌Δʹ͸ೝূ͕͍Δ
    ݟͨ͜ͱ͕͋Δ

    View full-size slide

  85. ೖྗ஋Λड͚औΔ
    ϢʔεέʔεΛ࢖͏
    ݁ՌΛը໘දࣔ͢Δ
    ίϯτϩʔϥʔʴը໘
    DBͱಉظ
    Ϣʔβೝূ͢Δ
    ඞཁʹͳͬͨ࣌఺Ͱૠೖ

    View full-size slide

  86. ೝূΛ͔͚Δ৔ॴ
    ೝূͷઃఆ
    ର৅Ϣʔβͷઃఆ

    View full-size slide

  87. ͜ΕΛ΋ͱʹຊ։ൃʹ͏ͭΕΔͱࢥ͍·͢ɻ
    ϓϩτ͜Μͳײ͡Ͱ͢
    େ·͔ͳ࢖༻ײ΍՝୊΋ݟ͖͑ͯ·ͨ͠ɻ

    View full-size slide

  88. ϓϩτ։ൃ׬ྃ🎉

    View full-size slide

  89. ΫϦʔϯΞΩςΫνϟ


    …ͬͯԿͳͷʁʲ࠶ʳ
    ͪΐͬ͜ͱͻͯ͞Δ͞Μίʔφʔ
    ޠΒͤͯ

    View full-size slide

  90. ΫϦʔϯΞΩςΫνϟ͸ந৅
    • ͜Ε͚ͩ͸ಡΊ: https://blog.tai2.net/the_clean_architecture.html


    • > هࣄ๯಄ͷਤ͸ɺ͜ΕΒ (ΦχΦϯ΍ϔΩαΰφϧͳͲ) ͷΞʔΩ
    ςΫνϟΛ୯Ұͷ֓೦ʹແཧͳ͘౷߹͢ΔࢼΈͰ͋Δɻ


    • ಉ৺ԁͷਤ͸ͨͩͷྫͰ͔͠ͳ͍ɻ

    ΦχΦϯΞʔΩςΫνϟͱ΄΅ಉ͡ਤ →


    • ΦχΦϯ/ϔΩαΰφϧ/DCI/… ʹ ۩৅ΞʔΩςΫνϟ


    • ΫϦʔϯΞʔΩςΫνϟ = ΞʔΩςΫνϟͷσβΠϯύλʔϯ

    View full-size slide

  91. ΫϦʔϯΞΩςΫνϟ͸഑ஔਤͰ͸ͳ͍
    • ༏ΕͨΞʔΩςΫνϟʹڞ௨͢Δಛ௃:


    ✓ த৺΄ͲϏδωεͷຊ࣭


    ✓ ֎प΄Ͳίϯϐϡʔλʔͷࣄ৘


    ✓ ૚͸จ຺Λม׵͢ΔΞμϓλʔͩ


    ✓ ґଘΛͭͶʹத৺ͷ҆ఆʹ޲͚Δ


    • ʮ͜ΕͲΜͳΞʔΩςΫνϟʹ΋ৗࣝͳʯ


    • ʮ΋ͪΖΜ܅Β͕ࣗ෼ͷϓϩμΫτʹ࡞ΔΞʔΩςΫνϟʹ΋΍Ͱʯ

    View full-size slide

  92. ໰.ϑϨʔϜϫʔΫ͸ΠϯϑϥετϥΫνϟ͔
    • ΫϦʔϯΞΩςΫνϟຊʹ͸ʮWeb ϑϨʔϜϫʔΫ͸֎ଆʯͱॻ͍ͯ͋Δ


    • Ͱ΋ૄ݁߹ͳઃܭΛαϙʔτ͢ΔͨΊͷϑϨʔϜϫʔΫ΋͋Δ


    • ಉ͡ϑϨʔϜϫʔΫͱ͍͏໊Ͱ΋ͦΕͧΕΧόʔൣғ͕શ͘ҧ͏


    • Կ͕ґଘͯ͠΋Α͍҆ఆ֓೦͔ɺԿ͕ෆ҆ఆ͞Λট͘۩৅ͳͷ͔ΛݟۃΊΑ


    • ḏࢠఆنʹΞʔΩςΫνϟਤͷܗ௨Γʹ͢Δ౒ྗ͸ແବ

    View full-size slide

  93. ͜Μͳϓϩτͷ࡞ΓํͰͨ͠
    #1 ։ൃํ਑ܾఆ
    ܾΊͨ։ൃํ਑ʹ͸ݻࣥ͠ͳ͍Α͏ʹ
    #2 ํ਑֬ೝ
    ظ଴௨Γ͔খ͘͞ࢼ͢
    #3 ετʔϦʔϚοϐϯά
    ϓϩμΫτͷࢥ͍΍༏ઌ౓ͷߴ͍λεΫͷચ͍ग़͢
    #4 ϞσϦϯάɺ։ൃɺϨϏϡʔ
    ϞσϦϯάʙϨϏϡʔΛ܁Γฦ͢ɻςετ͕ޮ͍ͯ͘Δ

    View full-size slide

  94. ґଘํ޲Λҙࣝ͠΍͍͢
    Ϣʔεέʔεͷσʔλґଘ͕গͳ͍
    ϞοΫ͕༻ҙ͠΍͍͢ ςετ͕खް͘ͳΔ
    ΦʔτϫΠϠϦϯάͰґଘղܾ
    Symfony + ɹDoctrineΛ࢖͏͜ͱͰ
    ίʔυͷมߋʹڧ͍

    View full-size slide

  95. ⭕ Α͔ͬͨ͜ͱ
    • ࠷ॳʹߟ͑ͨʰ։ൃࢦ਑ʱʹ͸ΊΔ͜ͱͰ։ൃεϐʔυ͕ૣ͔ͬͨ


    • มߋʢ࢓༷มߋɾϦϑΝΫλʣʹڧ͔ͬͨ


    • ʢࠓճͷܦݧΛܦͯʣ͖Ε͍ʹͭ͘Ζ͏ͬͯҙ͕ࣝժੜ͑ͨ

    Ϟσϧతʹ΋ίʔυతʹ΋


    • ͜ͷޙͷຊ։ൃʹ΋ϓϩτͷίʔυ͕׆͖ͨ

    View full-size slide

  96. ✅ վળ఺
    • ։ൃʹ͍ͭͯͷυΩϡϝϯτΛ·ͱΊ͓͚ͯ͹Α͔ͬͨɻ


    • ຊ։ൃͰϑΝοτίϯτϩʔϥʔؾຯʹͳͬͨͷͰɺΞʔΩςΫνϟͷҙ
    ٛΛͪΌΜͱ఻͑ͳ͍ͱ؆୯ʹ่Εͯ͠·͏


    • Ұ෦ɺυϝΠϯϩδοΫ͕ͬͪ͝Όʹͳͬͯ͠·ͬͨɻ


    • ΋ͬͱΠϕϯτʹཔΕ͹Α͔ͬͨɻ


    • Next.jsͰಥ͖௨͢ͷ΋ͳ͠Ͱ͸ͳ͔ͬͨɻ


    • ͨͿΜɺ΋ͬͱ͖Ε͍ʹͰ͖Δ

    View full-size slide

  97. ࢼ࣌ͦ͢͜ɺΞʔΩςΫνϟΛҙࣝ͢Δ

    View full-size slide

  98. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ

    View full-size slide