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

Laravelとドメインモデルと永続化モデル @ laravel.osaka #12

n1215
November 15, 2017

Laravelとドメインモデルと永続化モデル @ laravel.osaka #12

2017/11/15 laravel.osaka#12で使用したスライドです
Laravelと永続化モデルのサンプルコード (Todo管理)
https://github.com/n1215/lara-todo-persistence

n1215

November 15, 2017
Tweet

More Decks by n1215

Other Decks in Programming

Transcript

  1. LaravelͱυϝΠϯϞσϧͱӬଓԽϞσϧ
    for laraval.osaka #12
    2017/11/15 גࣜձࣾNextat தᒇ ݈ೋ

    View full-size slide

  2. Domain Driven Development
    • DDDͰ࡞ΒΕͨOSSͷྫ͕গͳ͍orͳ͍
    • →ͱᷖᮣʹൃݴ͢ΔͱSNS্Ͱͭͬ͜·ΕΔ
    • → Α͘Ͱ͖ͨOSS͸υϝΠϯϞσϧͷ޷ྫͩɺͱ
    → λγΧχ
    • ͕͔ͩ͠͠ɺ࣮͸൴Β͕஌Γ͍ͨͷ͸DDDͷຊ࣭
    ͷ෦෼Ͱ͸ͳ͘ɺΫϦʔϯΞʔΩςΫνϟ΍Ϩϙδ
    τϦύλʔϯͷ࣮૷ྫͷWebΞϓϦͰ͸ʁ

    View full-size slide

  3. ຊ೔ͷ͓࿩
    • DDDͷ࿩͸΄΅͠·ͤΜ
    • LaravelͰυϝΠϯϞσϧʢΤϯςΟ
    ςΟʣΛͲͷΑ͏ʹ࣮૷͠ӬଓԽ͢Δ͔ɺ
    ͕য఺
    • →RepositoryύλʔϯɺӬଓԽϞσϧ

    View full-size slide

  4. • EloquentʢActiveRecordύλʔϯʣΛ࢖͏ͱDBϑΝʔε
    τʹͳΓ͕ͪ
    • ؆୯ͳாථͷCRUDͳΒे෼
    • υϝΠϯͷ࢓༷͕ෳࡶͳ৔߹͸ʁ
    • ӬଓԽΛ෼཭ͯ͠υϝΠϯϞσϧΛத৺ʹߟ͍͑ͨ
    • Repositoryύλʔϯ
    • EloquentΛͲ͏࢖͏ʁ 3ύλʔϯΛ঺հ
    LaravelͱӬଓԽ

    View full-size slide

  5. ͓୊ɿTodo؅ཧ ΤϯςΟςΟ

    View full-size slide

  6. ͓୊ɿTodo؅ཧ ϨϙδτϦ

    View full-size slide

  7. ͓୊ɿTODO؅ཧ όϦϡʔΦϒδΣΫτ
    • Ұ෦ͷVO͸ڞ༻
    ΄΅εΧϥʔΛϥοϓ͚ͨͩ͠

    View full-size slide

  8. ͓୊ɿTodo؅ཧ ϨϙδτϦར༻ྫ
    InterfaceʹͷΈґଘ
    ←͍ΘΏΔServiceΫϥε

    View full-size slide

  9. Ҏ্ͷ࣮૷Λ3ύλʔϯͰ

    View full-size slide

  10. ύλʔϯ1 Eloquent Model=Entity

    View full-size slide

  11. ύλʔϯ1 Eloquent Model=Entity
    • هड़ྔతʹ͸΋ͷָ͘͢͝
    • EloquentΛ௚ʹ࢖͏ํ๏ͱ΄΅ࠩ͸ͳ͍
    • ϨϙδτϦͷ࢓ࣄ΋΄΅ͳ͍
    • Eloquent Model͕࿐ग़͢ΔͨΊɺυϝΠϯϞσ
    ϧͷ੹຿֎ͷίʔυΛॻ͖΍͍͢
    • ex) $todoItem->save() ͳͲ
    ←FXCKING!!!! PhpStorm͞Μ΋͓͜

    View full-size slide

  12. ύλʔϯ2 Entity has Eloquent Model
    Eloquent Model͸ΤϯςΟςΟͱ͸ผ్࡞੒

    View full-size slide

  13. ύλʔϯ2 Entity has Eloquent Model
    Eloquent ModelΛதʹ࣋ͭ

    View full-size slide

  14. ύλʔϯ2 Entity has Eloquent Model
    • Eloquent ModelΛ֎෦͔Β৮Βͤͳ͍
    ͷͰ1ΑΓ͸ߗ͍
    • Entity಺෦Ͱ͸ґવͱͯ͠ةݥ͕ͩɺ൓
    ໘Eloquentͷػೳͷ׆༻͸͠΍͍͢
    • Entityͷ࢓༷มߋׂ͕ͱָ

    View full-size slide

  15. ύλʔϯ3 POPO Entity and Eloquent Model
    όϦϡʔΦϒδΣΫτ͔Β࡞੒

    View full-size slide

  16. ύλʔϯ3 POPO Entity and Eloquent Model
    ϑΝΫτϦΛ࡞͓ͬͯ͘ͱศར
    2ͱಉ͡Eloquent Model

    View full-size slide

  17. ύλʔϯ3 POPO Entity and Eloquent Model
    ϨϙδτϦ͸͜Μͳײ͡
    2ͱಉ͡Eloquent Model

    View full-size slide

  18. ύλʔϯ3 POPO Entity and Eloquent Model
    • POPO = Plain Old PHP Object
    • ΃ͪ͜Μͱ͔ͷൃදͰΑ͘ݟ͔͚Δ
    • ӬଓԽΛ͸͖ͬΓͱ෼͚Δ
    • ΤϯςΟςΟͷߏ଄͕Θ͔Γ΍͍͢
    • ίʔυͷهड़ྔ͸૿͑·͢

    View full-size slide

  19. ൺֱ
    • جຊతʹ1→2→3ͷॱʹʢͦͷ৔ͷʣ࣮
    ૷ίετ͸্͕Γอकੑ/Ҡ২ੑ΋্͕Δ
    • Interface͑͞ఆ·Ε͹ɺ1→2→3ͷॱͰ
    ϦϑΝΫλϦϯά΋Մೳ
    • υϝΠϯͷෳࡶ͞ʹ߹Θͤͨબ୒Λ

    View full-size slide

  20. ͦͷଞͷબ୒ࢶ
    • ӬଓԽϞσϧͱͯ͠EloquentҎ֎Λ࠾༻͢Δέʔε
    • 4. POPO Entity + ΫΤϦϏϧμʔ
    • →EloquentϞσϧ͕ػೳա৒ؾຯͳͨΊγϯϓϧʹ
    • 5. POPO Entity + PDO
    • →4Λಥ͖٧Ίͯ΋͏PDOͰΑ͘Ͷʁͱ͍͏ύλʔϯ
    • 6. POPO Entity + other DataMapper
    • → DoctrineͳͲͱࠩ͠ସ͑Δ

    View full-size slide

  21. ·ͱΊ
    • Laravel AppͷӬଓԽͷ࣮૷ύλʔϯ΋͍Ζ͍Ζ͋Δ
    • ӬଓԽͷམͱ͠ॴΛݟ͚ͭͯυϝΠϯʹूத͠Α͏
    • ྫͷ؆୯ͳTodo؅ཧΞϓϦʹؒ઀૚Λ૿΍͗͢͠Δ
    ͷ͸ΦʔόʔΤϯδχΞϦϯάؾຯɻඞཁʹԠͯ͡
    • GitHubʹHTTP૚·ͰؚΊͨαϯϓϧίʔυUP༧ఆ
    • → https://github.com/n1215/lara-todo-persistence

    View full-size slide

  22. ࢀߟจݙ
    • Domain Models - atlashphp.io (http://
    atlasphp.io/mapper/2.x/
    domain.html#1-1-10)
    • ↑Atlas͍͍ΑAtlas

    View full-size slide