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

CakePHP3レポート

 CakePHP3レポート

PHPカンファレンス福岡2016での登壇資料

Junkins

May 26, 2016
Tweet

More Decks by Junkins

Other Decks in Technology

Transcript

  1. CakePHP3Ϩϙʔτ
    2016/05/21 PHPΧϯϑΝϨϯε෱Ԭ
    ҏ౻ ५थ

    View full-size slide

  2. Introduction
    ҏ౻ ५थ
    Junkins_110
    Junkins
    1.3
    2.ʙ
    3.ʙ

    View full-size slide

  3. Agenda
    CakePHP3 Ϩϙʔτ
    ࣮ࡍʹҊ݅Ͱ࠾༻ͨ͠ॴײ (ྑ͔ͬͨͱ͜Ζɺѱ͔ͬͨͱ͜Ζ)
    Model ( TableɺEntity )
    1. EntityͬͯԿʁ
    2. Entity͸ศརͩͬͨʁ
    3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ
    ࠓ·Ͱ$BLF1)1Λ࢖͍ͬͯͯɺ͜Ε͔Β$BLF1)1Λ࢖͏ํ޲͚
    CakePHP2ͱͷൺֱ͕ͪΐͪ͜ΐ͜ɻɻɻɻ

    View full-size slide

  4. 1. EntityͬͯԿʁ
    1. What is Entity?

    View full-size slide

  5. 1. EntityͬͯԿʁ
    1-1. MVC
    1-2. TableͱEntity
    1-3. Entityͷొ৔γʔϯ
    1. What is Entity?

    View full-size slide

  6. 1. What is Entity?
    V C M
    MVC Model View Controller
    View Controller Model

    View full-size slide

  7. 1. What is Entity?
    MVC Model View Controller
    V C M
    View Controller Model

    View full-size slide

  8. 1. What is Entity?
    V C M
    CakePHP2
    MVC of CakePHP2

    View full-size slide

  9. 1. What is Entity?
    V C T
    CakePHP3
    E
    Table
    Entity
    MVC of CakePHP3

    View full-size slide

  10. T
    1. What is Entity?
    E
    ɾ$BLF1)1ͷʮ.PEFMʯʹ͍ۙ໾ׂ
    Table
    Entity
    ɾ%#ͷʮ5BCMFʯ΁ͷΞΫηε
    ɾσʔλϨίʔυ
    TableͱEntity
    ɾϨίʔυ͝ͱʹΠϯελϯεԽ
    ɾ഑ྻͰ͸ͳ͍ͷͰ֦ு͕༰қ
    ɾ7BMJEBUJPO Associationͷઃఆ

    View full-size slide

  11. 1. What is Entity?
    E
    Entityͷొ৔γʔϯ
    E
    E
    E
    E
    E
    E
    E
    E
    E
    E
    E
    E
    E
    E
    E
    E E
    E
    E
    E
    E
    E
    E
    E
    E
    Ma
    Request Data
    DB
    ResultSet
    Marshaller
    beforeMarshal() Validation()
    SELECT
    SELECT

    View full-size slide

  12. 1. EntityͬͯԿʁ
    Entity͸CakePHP2Ͱ͍͏ModelͷҰ෦෼
    CakePHP2ͷModel͸TableͱEntityʹ෼͔Εͨ
    find(SELECT)ͨ͠ͱ͖ + POST͞Εͨͱ͖
    POST͞ΕͨσʔλΛEntityԽ͢Δͱ͖ʹόϦσʔγϣϯ͕ಈ͘
    ( CakePHP2ͱಉ༷ʹอଘ࣌ʹ΋όϦσʔγϣϯ͸ಈ͘ )
    1. What is Entity?

    View full-size slide

  13. 2. Entity͸ศརͩͬͨʁ
    2. Is Entity useful ?

    View full-size slide

  14. 2. Is Entity useful ?
    2. Entity͸ศརͩͬͨʁ
    2-1. ॲཧ͕؆ܿʹͳͬͨ
    ɾFat Controller -> Fat Model -> ?
    2-2. GetterͱSetter
    ɾ.7$ͷͲ͔͜ΒͰ΋ΞΫηεՄೳ

    View full-size slide

  15. V C M
    Fat Controller
    ॳ৺ऀͷ͜Ζ
    2. Is Entity useful ?

    View full-size slide

  16. V C M
    Fat Model
    খ׳Ε͖ͯͨ͜Ζ
    2. Is Entity useful ?

    View full-size slide

  17. V C M
    T E
    Finder
    Validation
    Association
    Save
    2. Is Entity useful ?
    ͜ͷ͝Ζ
    μΠΤοτ

    View full-size slide

  18. V
    C M
    T E
    μΠΤοτ
    Finder
    Validation
    Association
    Save
    2. Is Entity useful ?
    ͜ͷ͝Ζ

    View full-size slide

  19. 2. Is Entity useful ?
    V
    C
    M
    E
    CakePHP3
    E
    E
    E
    function hoge()
    V
    C
    M
    CakePHP2
    V
    C
    M array( )
    array( )
    array( )
    function hoge()
    Ͳ͔͜ΒͰ΋ΞΫηε

    View full-size slide

  20. 2. Is Entity useful ?
    V
    C
    M
    E
    Ͳ͔͜ΒͰ΋ΞΫηε
    CakePHP3
    E
    E
    E
    function hoge()
    V
    C
    M
    CakePHP2
    V
    C
    M array( )
    array( )
    array( )
    function hoge()
    hoge()
    hoge()
    hoge()

    View full-size slide

  21. 2. Is Entity useful ?
    V
    C
    M
    E
    CakePHP3
    E
    E
    E
    function hoge()
    V
    C
    M
    CakePHP2
    V
    C
    M array( )
    array( )
    array( )
    function hoge()
    hoge()
    hoge()
    Ͳ͔͜ΒͰ΋ΞΫηε

    View full-size slide

  22. 2. Is Entity useful ?
    Getter
    ྫ) ੏ͱ໊Λͭͳ͛ͯग़ྗ
    ̎ͭͷϑΟʔϧυΛͭͳ͛ͯग़ྗ
    ϑΟʔϧυʹॲཧΛՃ͑ͯग़ྗ
    ྫ) ֹۚΛ੫ࠐʹ
    ※ CakePHP2ͷafterFind()͕ෆཁʹͳΔ

    View full-size slide

  23. 2. Is Entity useful ?
    Setter
    ྫ) อଘ࣌ͷύεϫʔυΛϋογϡԽ
    ྫ) ੜ೥݄೔ͷอଘͱಉ࣌ʹ೥ྸ΋อଘ
    อଘ͢Δલͷ஋ͷมߋ
    ผϑΟʔϧυ΁ͷ஋ͷ௥Ճ
    ※ CakePHP2ͷbeforeSave()ͷهड़͕ݮΔ

    View full-size slide

  24. 2. Is Entity useful ?
    2. Entity͸ศརͩͬͨʁ
    1Ϋϥε͋ͨΓͷهड़ྔ͕ݮͬͨ
    ViewͰͷԋࢉࢠͷྔ͕ݮͬͨ
    ModelͷίʔϧόοΫͷهड़ྔ͕ݮͬͨ
    Fat EntityʹͳΒͳ͍ͨΊͷTips
    ڞ௨ॲཧ͸5SBJUԽʂ

    View full-size slide

  25. 3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ

    View full-size slide

  26. 3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ
    1. อଘ࣌ʹ(FUUFS͕૸Δ
    2. ෳ਺ճ4FUUFS͕૸Δ

    View full-size slide

  27. 3-1.อଘ࣌ʹ(FUUFS͕૸Δ
    ঢ়گ) ֹۚΛද͍ࣔͨ͠ʂJOQVUͷ஋΋ΧϯϚ۠੾Γʹ͍ͨ͠ʂ
    1000
    int text 1,000
    text 1,000 1000
    int
    1000
    int text 1,000
    1000
    int text1,000
    text 1,000 1000
    int
    Getter
    Setter
    Getter
    Setter
    Getter
    ཧ૝
    ݱ࣮
    SQL Error
    ※ ΧϥϜ໊Ͱ(FUUFSΛ࡞੒͢Δ࣌͸஫ҙ

    View full-size slide

  28. 3-2.ෳ਺ճ4FUUFS͕૸Δ
    ঢ়گ) ϚϧνεςοϓͷϑΥʔϜΛ࡞Γ͍ͨ
    Request Data
    Ma
    Form1
    Form2
    _setPassword()
    E
    adminadmin dsfknadfgnadflgkng
    Request Data
    Ma
    _setPassword()
    E
    dsfknadfgnadflgkng 32ekwnesihwenfansrueaf
    ͋Εʁ
    ※EntityͷઃఆΛมߋ͢Ε͹͍͍͕ɺ
    ɹɹ Marsherӽ͠Ͱ͸ઃఆΛมߋͰ͖ͳ͍

    View full-size slide

  29. 3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ
    ҙਤ͍ͯ͠ͳ͍λΠϛϯάͰॲཧ͕૸Δ
    Entityͷઃఆ͸৮Γʹ͍͘
    EntityҎ֎ͷ෦෼ͷམͱ݀͠͸͋·Γͳ͍

    View full-size slide

  30. ·ͱΊ
    EntityΛ࢖͍͜ͳͤΕ͹ɺޮ཰తͳ։ൃ͕Մೳ
    TableɺEntity͕෼͔Εͯɺඇৗʹॻ͖΍͍͢
    Entity͸ඇৗʹศརͰCakePHP3Λ࢖͏ͳΒੋඇཧղͯ͠΄͍͠
    Entity͸ศརͳ෼ɺཧղͯ͠࢖Θͳ͍ͱམͱ͕݀͋͠Γ·͢
    PluginΛ࡞Δͱ͖͸Entityͷಈ͖ʹؾΛ͚ͭͳ͍ͱ͍͚ͳ͍

    View full-size slide

  31. ͍͞͝ʹ
    Fusic͸ςΫϊϩδʔ͕
    ޷͖ͳΤϯδχΞΛืू͍ͯ͠·͢
    https://fusic.github.io

    View full-size slide

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

    View full-size slide