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

Ray.Di-Ray.AopからみるPHP5.4+フレームワークBEAR.Sunday

 Ray.Di-Ray.AopからみるPHP5.4+フレームワークBEAR.Sunday

madapaja

July 30, 2012
Tweet

More Decks by madapaja

Other Decks in Technology

Transcript

  1. Ray.Di/Ray.Aop ͔ΒΈΔ
    PHP5.4+ϑϨʔϜϫʔΫBEAR.Sunday
    ୈ61ճPHPษڧձ@౦ژ
    2012/07/30
    ؠ࡚ߊ࢘ @madapaja

    View Slide

  2. Ray.Di/Ray.Aop ͔ΒΈΔ
    PHP5.4+ϑϨʔϜϫʔΫBEAR.Sunday
    ୈ61ճPHPษڧձ@౦ژ
    2012/07/30
    ؠ࡚ߊ࢘ @madapaja

    View Slide

  3. • ؠ࡚ߊ࢘ @madapaja
    • blog.madapaja.net
    • Symfony Ϣʔβʔձ
    • גࣜձࣾΤεɾΤϜɾΤε
    • հޢॅ୐ࣄۀ෦
    • ΋͏͙͢ 0x1F ࡀ
    WHO AM I?

    View Slide

  4. BEAR.SUNDAY KEYWORDS
    • PHP (5.4+)
    • Ϧιʔεࢦ޲ϑϨʔϜϫʔΫ / Because Everything is A Resource
    • ؔ৺ͷ෼཭
    • REST
    • ίϚϯυΫΤϦ੹຿෼཭(CQRS)
    • APIۦಈ։ൃ
    • ΞεϖΫτࢦ޲ϓϩάϥϛϯά(AOP)
    • ґଘੑͷ஫ೖ(DI)
    • Cache
    • HATEOAS(Hypermedia as the Engine of Application State)
    • ...

    View Slide

  5. AGENDA
    • BEAR.Sunday
    • Ray
    • DI
    • Ray.Di

    View Slide

  6. BEAR.SUNDAY 2ͭͷப
    • Ray
    • DI / AOP support
    • BEAR.Resource
    • Ϧιʔεࢦ޲ΞʔΩςΫνϟʢROAʣʹΑΔίϯϙ
    ʔωϯτ઀ଓͷͨΊͷαʔϏεϨΠϠϑϨʔϜϫʔ
    Ϋ

    View Slide

  7. RAY
    • Google Guice ͔ΒΠϯεύΠΞ
    • 2ͭͷύοέʔδ
    • Ray.Di
    • Ξϊςʔγϣϯϕʔεͷ Dependency Injection ϑϨʔϜϫʔΫ
    • ґଘੑͷ஫ೖΛ൐͏ΦϒδΣΫτͷੜ੒ͱ؅ཧ
    • Ray.Aop
    • ΞεϖΫτࢦ޲ϑϨʔϜϫʔΫ

    View Slide

  8. DI?
    • Dependency Injection / ґଘੑͷ஫ೖ
    • ίϯϙʔωϯτʢΫϥεʣؒͷؔ܎ੑΛૄʹ͠ɺར༻
    ͢ΔαʔϏεͷ࣮૷ґଘΛऔΓআ͜͏ͱ͢Δٕज़

    View Slide

  9. DI?
    • Dependency Injection / ґଘੑͷ஫ೖ
    • ίϯϙʔωϯτʢΫϥεʣؒͷؔ܎ੑΛૄʹ͠ɺར༻
    ͢ΔαʔϏεͷ࣮૷ґଘΛऔΓআ͜͏ͱ͢Δٕज़
    ͳͥʁ

    View Slide

  10. ૝૾ͯ͠ΈΑ͏

    View Slide

  11. ૝૾ͯ͠ΈΑ͏
    ϑΝΠϧʹ͍ͨ࣌͠͸ʁ

    View Slide

  12. ૝૾ͯ͠ΈΑ͏
    ϑΝΠϧʹ͍ͨ࣌͠͸ʁ
    MongoDBΛ࢖͍͍ͨͱ͖͸ʁ

    View Slide

  13. ૝૾ͯ͠ΈΑ͏

    View Slide

  14. ૝૾ͯ͠ΈΑ͏

    View Slide

  15. ૝૾ͯ͠ΈΑ͏

    View Slide

  16. ૝૾ͯ͠ΈΑ͏
    มߋ͕೉͍͠

    View Slide

  17. ૝૾ͯ͠ΈΑ͏
    มߋ͕೉͍͠
    WikiModel Λܧঝͯ͠ MongoWikiModel Λ࡞Δʁ

    View Slide

  18. ૝૾ͯ͠ΈΑ͏
    มߋ͕೉͍͠
    WikiModel Λܧঝͯ͠ MongoWikiModel Λ࡞Δʁ
    ͳΜ͔ɺͦΕ͓͔͘͠ͳ͍ʁ

    View Slide

  19. վળͯ͠ΈΔ

    View Slide

  20. վળͯ͠ΈΔ
    ΠϯλʔϑΣʔεΛ༻ҙ

    View Slide

  21. վળͯ͠ΈΔ
    ΠϯλʔϑΣʔεΛ༻ҙ
    ΠϯλʔϑΣʔεͷ࣮૷Λ༻ҙ

    View Slide

  22. վળͯ͠ΈΔ

    View Slide

  23. վળͯ͠ΈΔ

    View Slide

  24. վળͯ͠ΈΔ
    ΠϯλʔϑΣʔεͷΈʹґଘ

    View Slide

  25. վળͯ͠ΈΔ
    ΠϯλʔϑΣʔεͷΈʹґଘ

    View Slide

  26. վળͯ͠ΈΔ
    ΠϯλʔϑΣʔεͷΈʹґଘ
    มߋ͕༰қʹ
    ͨͩ͠ɺར༻͸গ͠໘౗ʹ

    View Slide

  27. ґଘੑͷ஫ೖ

    View Slide

  28. ґଘੑͷ஫ೖ

    View Slide

  29. ґଘੑͷ஫ೖ
    ґଘ

    View Slide

  30. ґଘੑͷ஫ೖ
    ґଘ

    View Slide

  31. ґଘੑͷ஫ೖ
    ґଘ
    ஫ೖ

    View Slide

  32. ετϨʔδΛมߋͯ͠ΈΔ
    ϑΝΠϧͷར༻
    MongoDBͷར༻

    View Slide

  33. ετϨʔδΛมߋͯ͠ΈΔ
    ϑΝΠϧͷར༻
    MongoDBͷར༻
    Ͳ
    ͪ
    Β
    ΋
    WikiModel ͸

    ߋ
    ͕
    ͳ
    ͍

    View Slide

  34. Ҏ্͕DIͷҰൠతͳઆ໌Ͱ͢
    1/2ɹ࣌ؒ֬ೝʂ

    View Slide

  35. HOW TO DI?

    View Slide

  36. HOW TO DI?

    View Slide

  37. HOW TO DI?

    View Slide

  38. SYMFONY DI COMPONENT

    View Slide

  39. SYMFONY DI COMPONENT
    Mailer ΫϥεͷҾ਺ʹ’sendmail’Λ஫ೖ

    View Slide

  40. SYMFONY DI COMPONENT
    Mailer ΫϥεͷҾ਺ʹ’sendmail’Λ஫ೖ
    NewsletterManager ΫϥεͷҾ਺ʹ
    MailerͷϦϑΝϨϯεΛ஫ೖ

    View Slide

  41. SYMFONY DI COMPONENT
    NewsletterManagerͷΠϯελϯεΛऔಘ
    Mailer ΫϥεͷҾ਺ʹ’sendmail’Λ஫ೖ
    NewsletterManager ΫϥεͷҾ਺ʹ
    MailerͷϦϑΝϨϯεΛ஫ೖ

    View Slide

  42. DIP?
    • Dependency Inversion Principle / ґଘؔ܎ٯసͷݪଇ
    • ࣮૷ʹґଘͤͣɺந৅ʹґଘ͢Δ
    • ϓϩάϥϜ͸۩ମతͳΫϥεʹґଘͯ͠͸͍͚ͳ͍
    • ந৅ͱ࣮૷ͷৄࡉ͕׬શʹ੾Γ཭͞ΕΔʢϝϯςָ͕
    ʹʣ

    View Slide

  43. SYMFONY DI COMPONENT
    ΋͏Ұ౓ݟͯΈΑ͏

    View Slide

  44. SYMFONY DI COMPONENT
    Mailer ΫϥεͷίϯετϥΫλҾ਺ʹ’sendmail‘͕͋Δ͜ͱ
    ΋͏Ұ౓ݟͯΈΑ͏

    View Slide

  45. SYMFONY DI COMPONENT
    Mailer ΫϥεͷίϯετϥΫλҾ਺ʹ’sendmail‘͕͋Δ͜ͱ
    NewsletterManager ΫϥεͷҾ਺ʹ
    Mailer͕͋Δ͜ͱ
    ΋͏Ұ౓ݟͯΈΑ͏

    View Slide

  46. SYMFONY DI COMPONENT
    Mailer ΫϥεͷίϯετϥΫλҾ਺ʹ’sendmail‘͕͋Δ͜ͱ
    NewsletterManager ΫϥεͷҾ਺ʹ
    Mailer͕͋Δ͜ͱ
    ΋͏Ұ౓ݟͯΈΑ͏
    ར༻ଆ͕஌͍ͬͯΔʂʁʹ࣮૷ʹґଘ͍ͯ͠Δ

    View Slide

  47. SYMFONY DI COMPONENT
    Mailer ΫϥεͷίϯετϥΫλҾ਺ʹ’sendmail‘͕͋Δ͜ͱ
    NewsletterManager ΫϥεͷҾ਺ʹ
    Mailer͕͋Δ͜ͱ
    ΋͏Ұ౓ݟͯΈΑ͏
    ར༻ଆ͕஌͍ͬͯΔʂʁʹ࣮૷ʹґଘ͍ͯ͠Δ
    Α
    Γ

    ͍
    ΍
    Γ

    ͸
    ʁ

    View Slide

  48. RAY.DI
    ໊લ෇͖ΠϯδΣΫγϣϯࢦఆ
    ΠϯλʔϑΣʔεΠϯδΣΫγϣϯࢦఆ

    View Slide

  49. RAY.DI
    ໊લ෇͖ΠϯδΣΫγϣϯࢦఆ
    ΠϯλʔϑΣʔεΠϯδΣΫγϣϯࢦఆ

    View Slide

  50. RAY.DI
    ໊લ෇͖ΠϯδΣΫγϣϯࢦఆ
    ΠϯλʔϑΣʔεΠϯδΣΫγϣϯࢦఆ

    View Slide

  51. RAY.DI
    ϞδϡʔϧͰઃఆΛఆٛ
    ར༻

    View Slide

  52. RAY.DI
    ϞδϡʔϧͰઃఆΛఆٛ
    ར༻
    Module::configure()ͰઃఆΛఆٛ

    View Slide

  53. RAY.DI
    ϞδϡʔϧͰઃఆΛఆٛ
    ར༻
    Module::configure()ͰઃఆΛఆٛ
    transport_typeͱ͍͏໊લ෇͖ͷՕॴʹ
    ‘sendmail’ΛόΠϯυ

    View Slide

  54. RAY.DI
    ϞδϡʔϧͰઃఆΛఆٛ
    ར༻
    Module::configure()ͰઃఆΛఆٛ
    transport_typeͱ͍͏໊લ෇͖ͷՕॴʹ
    ‘sendmail’ΛόΠϯυ
    MailerInterfaceͷ஫ೖ͕ඞཁͳՕॴʹ
    MailerΛόΠϯυ

    View Slide

  55. RAY.DI
    ϞδϡʔϧͰઃఆΛఆٛ
    ར༻
    Module::configure()ͰઃఆΛఆٛ
    transport_typeͱ͍͏໊લ෇͖ͷՕॴʹ
    ‘sendmail’ΛόΠϯυ
    MailerInterfaceͷ஫ೖ͕ඞཁͳՕॴʹ
    MailerΛόΠϯυ
    ΠϯλʔϑΣʔεʹରͯ͠Ͳͷ࣮૷Λར༻͢Δ͔ɺͷΈఆٛ
    ஫ೖ͕ඞཁͳ෦෼ʹɺউखʹ஫ೖͯ͘͠ΕΔ
    ͲΜͳ࣮૷͔Λҙࣝ͠ͳ͍Ͱར༻Ͱ͖Δ

    View Slide

  56. RAY.DI
    • based on Aura.Di
    • ΫϦʔϯ —— ίϯςφࣗ਎ͷґଘੑ΋શͯ֎෦஫ೖʹ಺෦Ͱ new ͞Ε͍ͯΔݻఆΫϥε͕ͳ
    ͘ೖΕସ͑Մೳ
    • ίϯετϥΫλ/ηολʔΠϯδΣΫγϣϯ
    • ܧঝ͕༗ޮͳωʔϜυύϥϝʔλࢦఆ
    • JSR-250(Common Annotations for Java)/330(DI for Java)ελΠϧΞϊςʔγϣϯͷҰ෦Λ
    ࣮૷
    • Doctrine\Common\Annotations ʹΑΔΞϊςʔγϣϯ࣮૷
    • Ray.AopʹΑΔΞεϖΫτΛ৫ΓࠐΜͩΦϒδΣΫτͷऔಘ

    View Slide

  57. OBJECT GRAPH

    View Slide

  58. OBJECT FRAMEWORK?
    • Ray.Di
    • ΦϒδΣΫτੜ੒ͷͨΊͷϑϨʔϜϫʔΫ
    • Ϟδϡʔϧ͕͍࣋ͬͯΔ஌ࣝΛར༻ͯ͠ɺDiͱΞεϖΫτΛߏ੒͠ɺΦϒδΣΫτάϥϑΛߏஙʢʹ
    ίϯύΠϧʣ
    • ૣظଋറͷߏ੒ʢܾ·ͬͯΔ΋ͷɺมߋ͕ͳ͍΋ͷʣ
    • Ray.Aop
    • ΦϒδΣΫτར༻ͷͨΊͷϑϨʔϜϫʔΫ
    • ϥϯλΠϜ
    • ஗Ԇଋറͷߏ੒ʢ࣮ߦ࣌ʹܾఆ͢ΔDBͷ઀ଓઌͳͲʣ͸ܾఆͨ࣌͠ʹόΠϯυ
    ʢϥϯλΠϜΠϯδΣΫλʣ

    View Slide

  59. OBJECT FRAMEWORK?
    • ੜ੒ͱར༻ͷ෼཭
    • RayʢBEARʣͰ͸ੜ੒ͱར༻͕෼཭͞Ε͍ͯΔ
    • ੜ੒ͱར༻Λಉ࣌ʹߦΘͳ͍
    • ੜ੒ͷ࠶ར༻͕Մೳ
    • ଞͷϑϨʔϜϫʔΫͱҰઢΛը͢ϨϕϧͰΩϟογϡΛߦ͑Δ
    • PHPɺΞϊςʔγϣϯͷύʔεɺΠϯδΣΫγϣϯͷίετ͕ݪཧతʹ0ʹͳΔ
    • Ray = ΦϒδΣΫτͷʮੜ੒ɺར༻ɺফ໓ʯΛ໘౗ΈΔΦϒδΣΫτϑϨʔϜϫʔΫ

    View Slide

  60. ·ͱΊ
    • BEAR.Sunday Λ৮ͬͯΈΑ͏
    • Ray.Di / Ray.Aop / BEAR.Resource ͋ͨΓ͔Β࢝ΊΔͷ͕Φεεϝ
    • Ray.Aop Λ΍ͬͯΈΔ৔߹͸Ray.DiΛ௨ͯ͠৮Δͷָ͕
    • Ray ʹؔͯ͠͸ɺϒϩάʢhttp://blog.madapaja.net/ʣʹ΋
    ॻ͍ͨͷͰɺࢀߟʹͳΔ͔΋ʁ
    • Have fun!

    View Slide

  61. ࢀߟ
    • BEAR.Sunday Manual:
    http://code.google.com/p/bearsunday/wiki/manual?tm=6
    • Ray PHP User Guide:
    http://code.google.com/p/rayphp/wiki/Motivation?tm=6
    • BEAR.Sunday github:
    https://github.com/koriym/BEAR.Sunday
    • BEAR Blog:
    http://www.bear-project.net/blog/
    • ܊ࢁ͞Μ Slideshare:
    http://www.slideshare.net/akihito.koriyama/

    View Slide

  62. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ

    View Slide