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

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

Df4978f14401325586e9e286b140ac4c?s=47 n1215
November 15, 2017

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

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

Df4978f14401325586e9e286b140ac4c?s=128

n1215

November 15, 2017
Tweet

Transcript

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

  2. Domain Driven Development • DDDͰ࡞ΒΕͨOSSͷྫ͕গͳ͍orͳ͍ • →ͱᷖᮣʹൃݴ͢ΔͱSNS্Ͱͭͬ͜·ΕΔ • → Α͘Ͱ͖ͨOSS͸υϝΠϯϞσϧͷ޷ྫͩɺͱ

    → λγΧχ • ͕͔ͩ͠͠ɺ࣮͸൴Β͕஌Γ͍ͨͷ͸DDDͷຊ࣭ ͷ෦෼Ͱ͸ͳ͘ɺΫϦʔϯΞʔΩςΫνϟ΍Ϩϙδ τϦύλʔϯͷ࣮૷ྫͷWebΞϓϦͰ͸ʁ
  3. ຊ೔ͷ͓࿩ • DDDͷ࿩͸΄΅͠·ͤΜ • LaravelͰυϝΠϯϞσϧʢΤϯςΟ ςΟʣΛͲͷΑ͏ʹ࣮૷͠ӬଓԽ͢Δ͔ɺ ͕য఺ • →RepositoryύλʔϯɺӬଓԽϞσϧ

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

    Repositoryύλʔϯ • EloquentΛͲ͏࢖͏ʁ 3ύλʔϯΛ঺հ LaravelͱӬଓԽ
  5. ͓୊ɿTodo؅ཧ ΤϯςΟςΟ

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

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

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

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

  10. ύλʔϯ1 Eloquent Model=Entity

  11. ύλʔϯ1 Eloquent Model=Entity • هड़ྔతʹ͸΋ͷָ͘͢͝ • EloquentΛ௚ʹ࢖͏ํ๏ͱ΄΅ࠩ͸ͳ͍ • ϨϙδτϦͷ࢓ࣄ΋΄΅ͳ͍ •

    Eloquent Model͕࿐ग़͢ΔͨΊɺυϝΠϯϞσ ϧͷ੹຿֎ͷίʔυΛॻ͖΍͍͢ • ex) $todoItem->save() ͳͲ ←FXCKING!!!! PhpStorm͞Μ΋͓͜
  12. ύλʔϯ2 Entity has Eloquent Model Eloquent Model͸ΤϯςΟςΟͱ͸ผ్࡞੒

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

  14. ύλʔϯ2 Entity has Eloquent Model • Eloquent ModelΛ֎෦͔Β৮Βͤͳ͍ ͷͰ1ΑΓ͸ߗ͍ •

    Entity಺෦Ͱ͸ґવͱͯ͠ةݥ͕ͩɺ൓ ໘Eloquentͷػೳͷ׆༻͸͠΍͍͢ • Entityͷ࢓༷มߋׂ͕ͱָ
  15. ύλʔϯ3 POPO Entity and Eloquent Model όϦϡʔΦϒδΣΫτ͔Β࡞੒

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

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

  18. ύλʔϯ3 POPO Entity and Eloquent Model • POPO = Plain

    Old PHP Object • ΃ͪ͜Μͱ͔ͷൃදͰΑ͘ݟ͔͚Δ • ӬଓԽΛ͸͖ͬΓͱ෼͚Δ • ΤϯςΟςΟͷߏ଄͕Θ͔Γ΍͍͢ • ίʔυͷهड़ྔ͸૿͑·͢
  19. ൺֱ • جຊతʹ1→2→3ͷॱʹʢͦͷ৔ͷʣ࣮ ૷ίετ͸্͕Γอकੑ/Ҡ২ੑ΋্͕Δ • Interface͑͞ఆ·Ε͹ɺ1→2→3ͷॱͰ ϦϑΝΫλϦϯά΋Մೳ • υϝΠϯͷෳࡶ͞ʹ߹Θͤͨબ୒Λ

  20. ͦͷଞͷબ୒ࢶ • ӬଓԽϞσϧͱͯ͠EloquentҎ֎Λ࠾༻͢Δέʔε • 4. POPO Entity + ΫΤϦϏϧμʔ •

    →EloquentϞσϧ͕ػೳա৒ؾຯͳͨΊγϯϓϧʹ • 5. POPO Entity + PDO • →4Λಥ͖٧Ίͯ΋͏PDOͰΑ͘Ͷʁͱ͍͏ύλʔϯ • 6. POPO Entity + other DataMapper • → DoctrineͳͲͱࠩ͠ସ͑Δ
  21. ·ͱΊ • Laravel AppͷӬଓԽͷ࣮૷ύλʔϯ΋͍Ζ͍Ζ͋Δ • ӬଓԽͷམͱ͠ॴΛݟ͚ͭͯυϝΠϯʹूத͠Α͏ • ྫͷ؆୯ͳTodo؅ཧΞϓϦʹؒ઀૚Λ૿΍͗͢͠Δ ͷ͸ΦʔόʔΤϯδχΞϦϯάؾຯɻඞཁʹԠͯ͡ •

    GitHubʹHTTP૚·ͰؚΊͨαϯϓϧίʔυUP༧ఆ • → https://github.com/n1215/lara-todo-persistence
  22. ࢀߟจݙ • Domain Models - atlashphp.io (http:// atlasphp.io/mapper/2.x/ domain.html#1-1-10) •

    ↑Atlas͍͍ΑAtlas