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

Laravel with Aspect Oriented Architecture

Laravel with Aspect Oriented Architecture

yuuki takezawa

June 17, 2016
Tweet

More Decks by yuuki takezawa

Other Decks in Technology

Transcript

  1. Aspect Oriented Architecture
    ytake

    View full-size slide

  2. Aspect Oriented Programming
    • ΞεϖΫτࢦ޲Λཧղ͢ΔͨΊʹ͢΂͖͜ͱ͸ɺ

    ΦϒδΣΫτࢦ޲Λ·ͣ஌Δ͜ͱ
    • OOPʹ୅ΘΔ΋ͷͰ͸ͳ͘ɺॊೈੑΛ࣋ͨͤΔ

    ϓϩάϥϛϯάύϥμΠϜ
    • separation of concerns ʢؔ৺ࣄͷ෼཭ʣ

    View full-size slide

  3. ϓϩάϥϜ͸Ͳ͏͋Δ΂͖͔ʁ
    • ίϯϙʔωϯτΛϕʔεʹγεςϜΛߏங͍ͯ͘͠Ұൠ
    తͳύλʔϯ
    • ΫϥεɺύοέʔδɺαʔϏεͳͲͷίϯϙʔωϯτʹ

    ཁٻΛׂΓ౰ͯͯߟ͑Δ
    • େମͷύλʔϯͰ͸ޮՌతʹίϯϙʔωϯτͱͯ͠࡞༻
    • ޮՌతͰ͸ͳ͍ύλʔϯͱ͸ɺଞͷίϯϙʔωϯτʹ
    ӨڹΛ༩͑ͯ͠·͏΋ͷ͕෼཭Ͱ͖ͳ͍ύλʔϯͰ͋Γɺ
    ͜Ε͸େ͖ͳΞϓϦέʔγϣϯʹͳΕ͹ͳΔ΄Ͳ໰୊
    ͱͳΓ·͢ɻ

    View full-size slide

  4. ސ٬ը໘
    ෦԰༧໿
    ༧໿
    ελοϑ
    check in
    check out
    ෦԰

    View full-size slide

  5. ίϯϙʔωϯτͰղܾ͕Ͱ͖ͳ͍໰୊
    • ϩΪϯάɺ෼ࢄॲཧɺτϥϯβΫγϣϯͳͲ

    ج൫తͳؔ৺ࣄ
    • ػೳཁ݅ʹ൐͏ɺϢʔεέʔεʹΑΔؔ৺ࣄ
    • ͜ΕΒΛԣஅతͳؔ৺ࣄͱݺͿ

    View full-size slide

  6. ސ٬
    Ϗδωε

    ෦԰ൢച
    ෦԰༧໿
    ෦԰࡞੒

    View full-size slide

  7. ෦԰༧໿
    • ۭ͖෦԰͕ͳ͚Ε͹ɺ

    γεςϜͰ͸ۭ͖෦԰͕ͳ͍ɺͱͯ͠ϝοηʔδग़ྗ
    • ۭ͖෦԰͕͋Ε͹ɺ

    γεςϜͰ͸༧໿Λ࡞੒

    View full-size slide

  8. makeReservation
    ۭ͖෦԰ͳ͠
    ༧໿࡞੒

    View full-size slide

  9. /**
    * @param $id
    *
    * @return mixed
    * @throws \Exception
    */
    public function makeReservation($id)
    {
    if ($this->reserve->getQuantity($id)) {
    return $this->reserve->createReservation($id);
    }
    throw new \NoRoomException();
    }

    View full-size slide

  10. ෦԰༧໿(֦ு)
    • ೝՄ͞ΕͨϢʔβʔͷΈ͕༧໿Մೳͱ͢Δ
    • ۭ͖෦԰͕ͳ͍৔߹͸ɺΩϟϯηϧ଴ͪϦετ΁௥Ճ

    • ৼΔ෣͍Λ֦ு͢΂͖֦ுϙΠϯτΛࣝผ͢Δ
    • ௥ՃͷৼΔ෣͍Λఆٛ͢Δ

    View full-size slide

  11. makeReservation
    ೝՄΤϥʔ
    ༧໿࡞੒
    Ωϟϯηϧ଴ͪ΁

    View full-size slide

  12. /**
    * @param $id
    * @WaitingList
    * @return mixed
    * @throws \Exception
    */
    public function makeReservation($id)
    {
    if ($this->reserve->getQuantity($id)) {
    return $this->reserve->createReservation($id);
    }
    throw new \NoRoomException();
    }

    View full-size slide

  13. ෦԰༧໿(֦ு)
    • ྫͰ͸ɺৼΔ෣͍Λ௥Ճ͍ͯ͠·͢ɻ
    • ։ൃऀ͔ΒΈΔͱ࣮૷ίʔυʹΑΔมߋ͸ͳ͘ɺ

    ֦ு͸෼཭͞Ε͍ͯΔͱݴ͑Δঢ়ଶʹ͋Δ
    • ΞεϖΫτ͸ෳ਺ͷૢ࡞Λ֦ு͢Δ͜ͱ͕Ͱ͖Δ

    View full-size slide

  14. Laravel-Aspect

    (https://github.com/ytake/Laravel-Aspect)

    View full-size slide

  15. ͘͠Έ
    • ͲͷΫϥεͰͲΜͳ৚݅Ͱૢ࡞Λߦ͏͔

    (δϣΠϯτϙΠϯτɺϙΠϯτΧοτ)
    • ৚݅ʹ߹க͢ΔΫϥεΛίϯύΠϧ͠֎͔Β࣮ߦ

    (ίϯϙδγϣϯϝΧχζϜ)
    • ॲཧ࣮ߦ࣌ʹίϯςφ͕ίϯύΠϧࡁΈΫϥε΁ͱ

    ࠩ͠ସ͑Δ
    • ։ൃऀ͕ҙࣝ͠ͳ͍৔ॴͰॲཧΛ࣮ߦ͢Δ

    ίʔυ্ͷมߋ͸ΞϊςʔγϣϯͷΈ

    View full-size slide

  16. ServiceProvider
    Aspect Factory
    Aspect Driver
    Compiler
    Container
    Annotation Driver

    View full-size slide

  17. // contextual bind͔Ͳ͏͔
    if (isset($this->app->contextual[$class])) {
    //
    $this->resolveContextualBindings($class, $compiledClass);
    }
    // ίϯύΠϧͨ͠Ϋϥε΁ͱೖΕସ͑Δ
    $this->app->bind($class, function ($app) use ($bind, $compiledClass) {
    $instance = $app->make($compiledClass);
    $instance->bindings = $bind->getBindings();
    return $instance;
    });

    View full-size slide

  18. σϑΥϧτͰ༻ҙ͞ΕͨΞϊςʔγϣϯ
    • @Cacheable (Ξϥ΢ϯυΞυόΠε)

    ࢦఆͨ͠ϝιουͷ໭Γ஋ΛΩϟογϡ

    ΩϟογϡΩʔɺ࣌ؒɺλάɺΩϟογϡ໊Λࢦఆ
    • @CachePut (Ξϥ΢ϯυΞυόΠε)

    ࢦఆͨ͠ϝιουͷ໭Γ஋ͷΩϟογϡΛ্ॻ͖

    ͳ͚Ε͹࡞੒
    • @CacheEvict (ΞϑλʔΞυόΠε)

    ࢦఆͨ͠ϝιουͷ໭Γ஋ͷΩϟογϡΛ࡟আ

    View full-size slide

  19. σϑΥϧτͰ༻ҙ͞ΕͨΞϊςʔγϣϯ
    • @Transactional (Ξϥ΢ϯυΞυόΠε)

    ΞϊςʔγϣϯΛهड़ͨ͠ϝιουͷॲཧத͸

    σʔλϕʔεͷτϥϯβΫγϣϯΛ࣮ߦ͢Δ
    • @Loggable (Ξϥ΢ϯυΞυόΠε)

    ΞϊʔςʔγϣϯΛهड़ͨ͠ϝιουͷ࣮ߦ࣌ؒɺ

    Ҿ਺ɺ໭Γ஋ΛϩΪϯά
    • @LogExceptions (ΞϑλʔΞυόΠε)

    ΞϊςʔγϣϯΛهड़ͨ͠ϝιουͰ

    ΤΫηϓγϣϯ͕εϩʔ͞Εͨ৔߹ʹҾ਺ΛϩΪϯά

    ͦͷ··ϋϯυϥʔ΁εϩʔ͢Δ

    View full-size slide

  20. ࣮ࡍʹ࢖ͬͨྫ
    • @Meta (ΞϑλʔΞυόΠε)

    Template΁metaλάΛૠೖ(canonical΍pageͳͲ)
    • @Cacel (ΞϑλʔΞυόΠε)

    ಛఆͷ৚݅ԼͰ༧໿ͷΩϟϯηϧΛߦ͏
    • @PThread (Ξϥ΢ϯυΞυόΠε)

    ผεϨουͰ֘౰ͷϝιουΛ࣮ߦ͢Δ
    • @Queue (Ξϥ΢ϯυΞυόΠε)

    ΞϊςʔγϣϯͰࢦఆ͞ΕͨϝιουͷॲཧΛ

    QueueʹೖΕΔ

    View full-size slide

  21. υϝΠϯϞσϧΛ࡞੒͠ɺ
    ԣஅతͳؔ৺͝ͱΛ୳ͯ͠ΈΑ͏ʂ
    Laravel-Aspect͕αϙʔτ͠·͢

    View full-size slide