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

9541b31c963d9dc06901dab9d3049049?s=128

madapaja

July 30, 2012
Tweet

Transcript

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

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

  3. • ؠ࡚ߊ࢘ @madapaja • blog.madapaja.net • Symfony Ϣʔβʔձ • גࣜձࣾΤεɾΤϜɾΤε

    • հޢॅ୐ࣄۀ෦ • ΋͏͙͢ 0x1F ࡀ WHO AM I?
  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) • ...
  5. AGENDA • BEAR.Sunday • Ray • DI • Ray.Di

  6. BEAR.SUNDAY 2ͭͷப • Ray • DI / AOP support •

    BEAR.Resource • Ϧιʔεࢦ޲ΞʔΩςΫνϟʢROAʣʹΑΔίϯϙ ʔωϯτ઀ଓͷͨΊͷαʔϏεϨΠϠϑϨʔϜϫʔ Ϋ
  7. RAY • Google Guice ͔ΒΠϯεύΠΞ • 2ͭͷύοέʔδ • Ray.Di •

    Ξϊςʔγϣϯϕʔεͷ Dependency Injection ϑϨʔϜϫʔΫ • ґଘੑͷ஫ೖΛ൐͏ΦϒδΣΫτͷੜ੒ͱ؅ཧ • Ray.Aop • ΞεϖΫτࢦ޲ϑϨʔϜϫʔΫ
  8. DI? • Dependency Injection / ґଘੑͷ஫ೖ • ίϯϙʔωϯτʢΫϥεʣؒͷؔ܎ੑΛૄʹ͠ɺར༻ ͢ΔαʔϏεͷ࣮૷ґଘΛऔΓআ͜͏ͱ͢Δٕज़

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

  10. ૝૾ͯ͠ΈΑ͏

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

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

  13. ૝૾ͯ͠ΈΑ͏

  14. ૝૾ͯ͠ΈΑ͏

  15. ૝૾ͯ͠ΈΑ͏

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

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

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

  19. վળͯ͠ΈΔ

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

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

  22. վળͯ͠ΈΔ

  23. վળͯ͠ΈΔ

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

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

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

  27. ґଘੑͷ஫ೖ

  28. ґଘੑͷ஫ೖ

  29. ґଘੑͷ஫ೖ ґଘ

  30. ґଘੑͷ஫ೖ ґଘ

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

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

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

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

  35. HOW TO DI?

  36. HOW TO DI?

  37. HOW TO DI?

  38. SYMFONY DI COMPONENT

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

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

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

  42. DIP? • Dependency Inversion Principle / ґଘؔ܎ٯసͷݪଇ • ࣮૷ʹґଘͤͣɺந৅ʹґଘ͢Δ •

    ϓϩάϥϜ͸۩ମతͳΫϥεʹґଘͯ͠͸͍͚ͳ͍ • ந৅ͱ࣮૷ͷৄࡉ͕׬શʹ੾Γ཭͞ΕΔʢϝϯςָ͕ ʹʣ
  43. SYMFONY DI COMPONENT ΋͏Ұ౓ݟͯΈΑ͏

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

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

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

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

    Α Γ ྑ ͍ ΍ Γ ํ ͸ ʁ
  48. RAY.DI ໊લ෇͖ΠϯδΣΫγϣϯࢦఆ ΠϯλʔϑΣʔεΠϯδΣΫγϣϯࢦఆ

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

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

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

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

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

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

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

    ͲΜͳ࣮૷͔Λҙࣝ͠ͳ͍Ͱར༻Ͱ͖Δ
  56. RAY.DI • based on Aura.Di • ΫϦʔϯ —— ίϯςφࣗ਎ͷґଘੑ΋શͯ֎෦஫ೖʹ಺෦Ͱ new

    ͞Ε͍ͯΔݻఆΫϥε͕ͳ ͘ೖΕସ͑Մೳ • ίϯετϥΫλ/ηολʔΠϯδΣΫγϣϯ • ܧঝ͕༗ޮͳωʔϜυύϥϝʔλࢦఆ • JSR-250(Common Annotations for Java)/330(DI for Java)ελΠϧΞϊςʔγϣϯͷҰ෦Λ ࣮૷ • Doctrine\Common\Annotations ʹΑΔΞϊςʔγϣϯ࣮૷ • Ray.AopʹΑΔΞεϖΫτΛ৫ΓࠐΜͩΦϒδΣΫτͷऔಘ
  57. OBJECT GRAPH

  58. OBJECT FRAMEWORK? • Ray.Di • ΦϒδΣΫτੜ੒ͷͨΊͷϑϨʔϜϫʔΫ • Ϟδϡʔϧ͕͍࣋ͬͯΔ஌ࣝΛར༻ͯ͠ɺDiͱΞεϖΫτΛߏ੒͠ɺΦϒδΣΫτάϥϑΛߏஙʢʹ ίϯύΠϧʣ •

    ૣظଋറͷߏ੒ʢܾ·ͬͯΔ΋ͷɺมߋ͕ͳ͍΋ͷʣ • Ray.Aop • ΦϒδΣΫτར༻ͷͨΊͷϑϨʔϜϫʔΫ • ϥϯλΠϜ • ஗Ԇଋറͷߏ੒ʢ࣮ߦ࣌ʹܾఆ͢ΔDBͷ઀ଓઌͳͲʣ͸ܾఆͨ࣌͠ʹόΠϯυ ʢϥϯλΠϜΠϯδΣΫλʣ
  59. OBJECT FRAMEWORK? • ੜ੒ͱར༻ͷ෼཭ • RayʢBEARʣͰ͸ੜ੒ͱར༻͕෼཭͞Ε͍ͯΔ • ੜ੒ͱར༻Λಉ࣌ʹߦΘͳ͍ • ੜ੒ͷ࠶ར༻͕Մೳ

    • ଞͷϑϨʔϜϫʔΫͱҰઢΛը͢ϨϕϧͰΩϟογϡΛߦ͑Δ • PHPɺΞϊςʔγϣϯͷύʔεɺΠϯδΣΫγϣϯͷίετ͕ݪཧతʹ0ʹͳΔ • Ray = ΦϒδΣΫτͷʮੜ੒ɺར༻ɺফ໓ʯΛ໘౗ΈΔΦϒδΣΫτϑϨʔϜϫʔΫ
  60. ·ͱΊ • BEAR.Sunday Λ৮ͬͯΈΑ͏ • Ray.Di / Ray.Aop / BEAR.Resource

    ͋ͨΓ͔Β࢝ΊΔͷ͕Φεεϝ • Ray.Aop Λ΍ͬͯΈΔ৔߹͸Ray.DiΛ௨ͯ͠৮Δͷָ͕ • Ray ʹؔͯ͠͸ɺϒϩάʢhttp://blog.madapaja.net/ʣʹ΋ ॻ͍ͨͷͰɺࢀߟʹͳΔ͔΋ʁ • Have fun!
  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/
  62. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ