EC-CUBE3コードリーディング #1

637291c2197269c32f757d93a2a41b85?s=47 amidaike
February 03, 2016

EC-CUBE3コードリーディング #1

637291c2197269c32f757d93a2a41b85?s=128

amidaike

February 03, 2016
Tweet

Transcript

  1. EC-CUBE3ίʔυϦʔσΟϯά #1 EC-CUBEؔ੢Ϣʔβάϧʔϓ 2016-01-20

  2. ࣗݾ঺հ גࣜձࣾΩϡʔϧ ࢁଜ ਗ਼࢙ EC-CUBE3ͷίϛολʔͯ͠·͢ @k-yamamura

  3. ໨࣍ 1. EC-CUBE3ͷ঺հ 2. ࢖༻͍ͯ͠ΔϑϨʔϜϫʔΫ 3. EC-CUBE3ͷσΟϨΫτϦߏ଄ 4. σʔλϕʔεߏ଄ʹ͍ͭͯ 5.

    ։ൃ࣌ͷ஫ҙ఺
  4. 1.EC-CUBE3ͷ঺հ

  5. EC-CUBE3ͷ঺հ • 2015೥7݄1೔ʹ7೥ͿΓͷϝδϟʔόʔδϣϯΞοϓ • γεςϜ಺෦ͷେ෯ͳݟ௚͠
 Symfony2ίϯϙʔωϯτͰ͋ΔSilexͷ࠾༻
 Bootstrap3ͷ࠾༻
 Smarty͔ΒTwig΁ͷPHPςϯϓϨʔτมߋ
 Doctrineͱ͍͏ORϚούʔͷ࠾༻ •

    ϨεϙϯγϒσβΠϯରԠ • ϓϥάΠϯػߏͷ࡮৽
  6. EC-CUBE3ͷ঺հ • GitHubΛ࢖ͬͨࠓ࣌ͷ։ൃ
 https://github.com/EC-CUBE/ec-cube • TravisCIɺAppVeyorɺScrutinizerͷ֎෦αʔϏεΛ࢖͍ίʔ υ඼࣭Λ୲อ
 ˠPullRequest͞ΕΔͱͦΕͧΕࣗಈతʹ࣮ߦ͞Ε·͢ɻ·ͩ ·ͩςετέʔε͸଍Γ͍ͯ·ͤΜ͕ɾɾɾ •

    PSRʹ΄΅४ڌͨ͠ίʔυ։ൃ ͍ͭͰ΋Pull Request͓଴͓ͪͯ͠Γ·͢ʂ
  7. 2.࢖༻͍ͯ͠ΔϑϨʔϜϫʔΫ

  8. ࢖༻͍ͯ͠ΔϑϨʔϜϫʔΫ • Symfony2ʹ͍ͭͯ
 Symfony2ͱ͸MVCελΠϧͷྲྀΕΛ౿ऻͨ͠ϑϨʔϜ ϫʔΫͰ͢ɻ • ҰൠతͳWebΞϓϦέʔγϣϯͷಈ࡞ ᶃϦΫΤετ ᶅϨεϙϯε ᶄॲཧ

  9. ࢖༻͍ͯ͠ΔϑϨʔϜϫʔΫ • Symfony2ͷಈ࡞ ᶃϦΫΤετ ᶅϨεϙϯε ᶄॲཧ ϦΫΤετ ΦϒδΣΫτ )551 Χʔωϧ

    Ϩεϙϯε ΦϒδΣΫτ
  10. ࢖༻͍ͯ͠ΔϑϨʔϜϫʔΫ • Symfony2ͷߏ੒ཁૉ @see https://speakerdeck.com/hidenorigoto/symfonywoxuan-buli-you-tosymfonyben-shao-jie

  11. ࢖༻͍ͯ͠ΔϑϨʔϜϫʔΫ • Twigʹ͍ͭͯ
 PHPςϯϓϨʔτΤϯδϯͰ͋ΓɺSymfony2Λߏ੒͢Δඪ४ύο έʔδͷҰ෦Ͱ͢ɻ(EC-CUBE2ܥͰ͸SmartyΛ࠾༻) • Twigͷಛ௃ 1. ߴ଎ :

    ࠷దԽ͞ΕͨPHPίʔυͰςϯϓϨʔτΛίφϐϧ͠ɺ ௨ৗͷPHPίʔυʹൺ΂ͯΦʔόʔϔουΛ࠷খݶʹݮগ 2. ηΩϡΞ : ࣗಈΤεέʔϓػೳ΍৴པ͞Ε͍ͯͳ͍ςϯϓϨʔ υίʔυΛධՁ͢ΔͨΊͷsandboxϞʔυΛඋ͑Δ 3. ॊೈੑ : ಠࣗͷΧελϜλά΍ϑΟϧλΛఆٛ͢Δ͜ͱ͕Մೳ
  12. ࢖༻͍ͯ͠ΔϑϨʔϜϫʔΫ • Doctrineʹ͍ͭͯ
 Doctrine͸ORMπʔϧͰ͋Γɺσʔλϕʔεͷந৅Խ΍ૢ࡞͢ΔͨΊͷPHPϥΠϒϥ ϦʔͰ͢ɻ
 Symfony2Ͱ͸σʔλϕʔεͱσʔλΛ΍ΓऔΓ͢ΔͷʹɺDoctrine ORMΛ࢖͍·͢ɻ ORMͱ͸DBͷσʔλͱPHPͷΫϥεΛϚοϐϯάͯ͠ม׵͢Δٕ๏ͷ͜ͱͰ͢ɻ
 
 


    
 
 
 • ϓϥΠϚϦΩʔͱͯ͠idΛ࣋ͪɺDoctrineΛ௨ͯ͠DBͱϚοϐϯά͢ΔPHPΦϒδΣ ΫτΛΤϯςΟςΟͱݺͼ·͢ɻ
  13. 3.EC-CUBE3ͷσΟϨΫτϦߏ଄

  14. EC-CUBE3ͷσΟϨΫτϦߏ଄ • EC-CUBE3Ͱ͸SilexϑϨʔϜϫʔΫΛ࠾༻͍ͯ͠Δͨ Ίɺ2ܥ͔Βେ෯ʹσΟϨΫτϦߏ଄͕มԽ • Symfony2ͷσΟϨΫτϦߏ଄ΛࢀߟʹɺEC-CUBE3ಠ ࣗʹߏ੒(σΟϨΫτϦߏ੒͸ޙड़) • URLʹ.php͕ແ͘ͳΓγϯϓϧͳURLʹมߋ •

    ެ։σΟϨΫτϦʹ͍ͭͯ͸2ܥΛ΄΅౿ऻ
  15. EC-CUBE3ͷσΟϨΫτϦߏ଄ • /ECCUBEROOT/src
 ഑Լ͕ϓϩάϥϜຊମͱͳΓɺ phpϑΝΠϧ΍twigϑΝΠϧΛ ഑ஔ

  16. EC-CUBE3ͷσΟϨΫτϦߏ଄ • /ECCUBEROOT/html
 ͕ެ։σΟϨΫτϦͱͳΓɺ ϦιʔεϑΝΠϧ(css΍ը૾ ϑΝΠϧ౳ʑ)Λ഑ஔ
 (֤σΟϨΫτϦͷઆ໌͸ޙड़)

  17. EC-CUBE3ͷσΟϨΫτϦߏ଄ • /ECCUBEROOT/app
 ഑Լ͸ઃఆϑΝΠϧ΍ϩάϑΝ Πϧ౳͕഑ஔ͞Ε͓ͯΓɺϓ ϥάΠϯ͸ʮPluginʯσΟϨΫ τϦ഑ԼͰ࡞੒

  18. EC-CUBE3ͷσΟϨΫτϦߏ଄ σΟϨΫτϦ໊ ػೳ໊ Eccube௚Լ ϕʔεͱͳΔApplication.php͕ଘࡏ͠ɺඞ ͣ͜ͷΫϥε͔Β࣮ߦ͞ΕΔ Application Application.phpͷ਌ΫϥεϑΝΠϧ͕֨ೲ Command ConsoleίϚϯυ༻Ϋϥε

    Common ఆ਺ఆٛΫϥε Controller ίϯτϩʔϥʔΫϥε ControllerProvider URLϚοϐϯάఆٛؔ਺ Doctrine Doctirine֦ுΫϥε Entity DB࿈ܞ༻EntityΫϥε Event FormΠϕϯτ༻Ϋϥε EventListner ΠϕϯτϦεφʔ༻Ϋϥε
  19. EC-CUBE3ͷσΟϨΫτϦߏ଄ σΟϨΫτϦ໊ ػೳ໊ Exception ۀ຿ΤϥʔΫϥε Form FormλΠϓΫϥε Plugin ϓϥάΠϯ༻ManagerΫϥε Repository

    DBΞΫηε༻ϦϙδτϦΫϥε Resource doctrine༻dcmϑΝΠϧ΍twigϑΝΠϧ౳ Security ύεϫʔυϋογϡ༻Ϋϥε΍ݖݶνΣο ΫΫϥε Service αʔϏεΫϥε ServiceProvider DIఆٛ༻Ϋϥε Twig Twig֦ு༻Ϋϥε Util ڞ௨ؔ਺Ϋϥε
  20. EC-CUBE3ͷσΟϨΫτϦߏ଄ • ຊମଆͷ։ൃͷྲྀΕ͸ҎԼͷ௨Γ 1. Controller࡞੒ 2. ControllerProvider΍ServiceProviderʹඞཁͳఆٛ Λ௥Ճ 3. TwigϑΝΠϧ࡞੒

    4. ඞཁͰ͋Ε͹FormType࡞੒ 5. ඞཁͰ͋Ε͹ Entity౳Λ࡞੒ 6. ը໘֬ೝ
  21. 4.σʔλϕʔεߏ଄ʹ͍ͭͯ

  22. σʔλϕʔεߏ଄ʹ͍ͭͯ • EC-CUBE2͔ΒEC-CUBE3ͷDBεΩʔϚͷݟ௚͠ʹ͋ͨΓORMͰѻ͍΍͍͢ܗࣜ ʹมߋ • EC-CUBE2͔ΒҎԼͷ಺༰Λݟ௚͠(v2.13Λର৅)
 ςʔϒϧ໊͸໋໊ن໿ΛఆΊͯमਖ਼Λ࣮ࢪ
 ར༻͍ͯ͠ͳ͍ςʔϒϧ/ΧϥϜͷ࡟আ
 ֎෦Ωʔͷ௥Ճ
 ϓϥάΠϯͰར༻͢Δςʔϒϧ͸ຊମ͔Β෼཭

    • ෳ߹ओΩʔ͸ར༻ͤͣɺαϩήʔτΩʔΛར༻(ଟରଟ͸আ͘) • ͨͩ͠ɺEC-CUBE2ܥͷΧϥϜ໊শɺσʔλܕ͸ݪଇมߋ͠ͳ͍
  23. σʔλϕʔεߏ଄ʹ͍ͭͯ • ໋໊ن໿ͷϧʔϧ
 ল໊ུশͷഇࢭ : dtb_deliv → dtb_delivery
 ୯਺ܗʹมߋ :

    dtb_products → dtb_product
 εωʔΫέʔεͰ໋໊ : dtb_class_category • ςʔϒϧʹ͸छผʹΑΓϓϨϑΟΫεΛ͚ͭΔ
 Ϛελςʔϒϧ : mtb_hogehoge
 σʔλςʔϒϧ : dtb_hogehoge
 ϓϥάΠϯؔ࿈ : plg_hogehoge
  24. σʔλϕʔεߏ଄ʹ͍ͭͯ • ֎෦Ωʔͷ௥Ճ
 dtb_product_class͔Βdtb_productʹproduct_idΛ֎ ෦Ωʔͱͯ͠ઃఆ • ϓϥάΠϯ͔Βຊମͷඪ४ςʔϒϧʹରͯ͠ΧελϚΠ ζ͸ඇਪ঑
 όʔδϣϯΞοϓ͕ࠔ೉ɺଞͷϓϥάΠϯͱͷڝ߹

  25. σʔλϕʔεߏ଄ʹ͍ͭͯ • EC-CUBE3Λ։ൃ͢Δࡍʹػೳͷݟ௚͕͠ߦΘΕͨͨΊɺ2 ܥͰଘࡏ͍ͯͨ͠ෆཁͳςʔϒϧ͸࡟আ • 3ܥͰ৽ͨʹ৽ن࡞੒͞Εͨςʔϒϧ΋ଘࡏ͢Δ͕ɺػೳͷ ݟ௚͠ʹΑΓ৽ن࡞੒͞Εͨςʔϒϧ͕ຆͲͰ͋Γ2ܥ͔Β ಛʹมߋ఺ͳ͠ • 2ܥͱͷςʔϒϧൺֱ͸ҎԼͷURLΛࢀর


    http://amidaike.hatenablog.com/entry/2015/11/05/141219
  26. 5.։ൃ࣌ͷ஫ҙ఺

  27. EC-CUBE3Ͱ࢖༻͍ͯ͠Δจࣈίʔυ • phpϑΝΠϧɺtwigϑΝΠϧؚΊ͢΂ͯUTF-8(BOMແ) Ͱ࡞੒͍ͯͩ͘͠͞ɻ • σʔλϕʔε࡞੒࣌΋UTF-8Ͱ࡞੒͍ͯͩ͘͠͞ɻ
 MySQLͩͱ
 create database eccube

    character set utf8;
  28. ରԠϒϥ΢βʹ͍ͭͯ OS ϒϥ΢β Windows (Windows7Ҏ߱) Internet Explorer10 Ҏ߱ Google Chrome

    ࠷৽൛ Firefox ࠷৽൛ Mac Safari ࠷৽൛ iOS(7Ҏ߱) Safari ࠷৽൛ Android(4.1Ҏ߱) ඪ४ϒϥ΢β ࠷৽൛
  29. URLͷ֬ೝํ๏ $ php app/console router:debug +----------------------------------------+-----------------------------------------------------------+---------+ | Name | Path

    | Pattern | +----------------------------------------+-----------------------------------------------------------+---------+ | admin_logout | /admin/logout | GET | | admin_login_check | /admin/login_check | | | logout | /logout | GET | | login_check | /login_check | | | user_data | /user_data/{route} | ANY | | homepage | / | ANY | | top | / | ANY | | index | / | ANY | | cart | /cart | ANY | | cart_add | /cart/add | POST | | cart_up | /cart/up/{productClassId} | ANY | | cart_down | /cart/down/{productClassId} | ANY | | cart_set_quantity | /cart/setQuantity/{productClassId}/{quantity} | ANY | | cart_remove | /cart/remove/{productClassId} | ANY | | cart_buystep | /cart/buystep | ANY | | contact | /contact | ANY | | contact_complete | /contact/complete | ANY | | entry | /entry | ANY | | entry_complete | /entry/complete | ANY | | entry_activate | /entry/activate/{secret_key} | ANY | | forgot | /forgot | ANY | | forgot_reset | /forgot/reset/{reset_key} | ANY | | block_category | /block/category | ANY | php app/console router:debug
  30. σόοάϞʔυͷ༗ޮԽ • ௨ৗ/΍/index.phpͰΞΫηε͍ͯ͠ΔURLΛ/index_dev.phpʹมߋͯ͠ΞΫηε͢Δ͜ͱʹΑΓɺtwig ϑΝΠϧ͕Ωϟογϡ͞ΕͣʹσόοάϞʔυ͕༗ޮʹͳΓ·͢ɻ
 
 ˞EC-CUBE3.0.8͔Βdump༻ϥΠϒϥϦΛಋೖͨ͜͠ͱʹΑΓɺύοέʔδ൛ͩͱ index_dev.php ͕ͦ ͷ··ͩͱ࢖͑·ͤΜɻindex_dev.php Λ࢖͑ΔΑ͏ʹ͢ΔͨΊʹ͸EC-CUBEσΟϨΫτϦ௚ԼͰɺҎ

    ԼͷίϚϯυΛೖྗ͍ͯͩ͘͠͞ɻ
 curl -sS https://getcomposer.org/installer | php
 Λ࣮ߦޙɺ
 php composer.phar update symfony/var-dumper symfony/debug-bundle
 Λ࣮ߦ͍ͯͩ͘͠͞ɻ(3.0.9͔Β͸ؚ·ΕΔΑ͏ʹͳΓ·͢)
 http://localhost/index_dev.php • You are not allowed to access this file. Check index_dev.php for more information.ͱΤϥʔ͕දࣔ͞Ε Δ৔߹ɺindex_dev.phpΛ։͖ɺΞΫηεݩͷIPΛҎԼͷ഑ྻʹ௥Ճ͍ͯͩ͘͠͞ɻ 
 $allow = array( '127.0.0.1', 'fe80::1', '::1', );
  31. TwigΩϟογϡͷ࡟আ • ຊ൪ಋೖޙʹจݴมߋͳͲ͕ൃੜͨ͠৔߹ɺTwig Ωϟογϡ͕ޮ͍͍ͯΔͨΊTwigϑΝΠϧΛมߋͯ͠ ΋൓ө͞Ε·ͤΜɻมߋ಺༰Λ൓өͤ͞ΔͨΊʹ͸ɺ
 /ECCUBEROOTE/app/cache/twig
 σΟϨΫτϦΛ࡟আ͍ͯͩ͘͠͞ɻ·ͨ͸ɺ
 php app/console cache:clear


    ͱ࣮ߦͯ͠ΩϟογϡϑΝΠϧΛ࡟আ͍ͯͩ͘͠͞ɻ
  32. PostgreSQLͱMySQLͷҧ͍ • EC-CUBE3͸DoctrineΛ࢖͍ͬͯΔͨΊɺPostgreSQLͱ MySQLͷҧ͍͸ΞϓϦ͔Βͷ؍఺ͰݟΔͱͲͪΒΛ࢖ͬͯ΋ ҧ͍͸ແ͠
 ͨͩ͠ɺPosgreSQLͱMySQLͰ͸auto incrementͷλΠϛϯ ά͕ҟͳΔͨΊ஫ҙ͕ඞཁ
 ˠMySQL͸flushΛ͔ͯ͠ΒͰͳ͍ͱidͷऔಘෆՄ •

    ύϑΥʔϚϯεͷ؍఺ͰΈΔͱαʔό؀ڥʹґΔͱ͜Ζ͕େ ͖͍ͨΊɺࣗ෼͕ಘҙͱ͢ΔํΛ࢖͑͹ྑ͍
  33. EC-CUBE3Ξοϓσʔτ࣌ͷDB஫ҙ఺ • EC-CUBE3͔Β͸ຊମͷόʔδϣϯΞοϓʹ൐ͳ͍ɺDBͷόʔδϣϯΞοϓ΋ migrationϑΝΠϧΛ࢖ͬͯΞοϓσʔτՄೳ
 ˠsrc/Eccube/Resource/doctrine/migration௚Լʹଘࡏ͢ΔϑΝΠϧΛݩʹ migration͕࣮ߦ͞ΕΔ • ຊମΞοϓσʔτʹ൐ͳ͍DBͷมߋ͕ൃੜͨ͠৔߹ɺ
 http://υϝΠϯ/install.php/migration
 Λ࣮ߦ͢Δ͜ͱͰɺmigration͕࣮ߦ͞ΕDB͕࠷৽Խ͞ΕΔ

    • Πϯετʔϧ࣌doctrine_migraion_versionsͱ͍͏ςʔϒϧ͕࡞੒͞ΕΔ͕ɺ migration؅ཧ༻ςʔϒϧͱͯࣗ͠ಈతʹ࡞੒͞ΕΔςʔϒϧͷͨΊ৮Βͳ͍͜ͱ
  34. EC-CUBE3Ξοϓσʔτ࣌ͷDB஫ҙ఺ • ϓϥάΠϯ͔Βຊମͷςʔϒϧʹରͯ͠ͷΧελϚΠζ͸ඇਪ঑
 ˠ࣮ݱ͢ΔͨΊʹ͸ϓϥάΠϯΠϯετʔϧ࣌ʹϚΠάϨʔγϣϯ ػೳΛ࢖ͬͯϓϥάΠϯ༻ͷςʔϒϧΛ࡞੒ͯ͠ѻ͏ͷ͕๬·͍͠ • mtb_constants͕ແ͘ͳΓɺ୅ΘΓʹconstant.ymlΛ࢖༻͢Δ͜ͱ ʹͳ͕ͬͨɺݱࡏEC-CUBE3Ͱ࢖༻͞Ε͍ͯͳ͍߲໨΋ଘࡏ͢Δͨ Ίɺকདྷ࢖༻͞Ε͍ͯͳ͍߲໨͸࡟আ͞ΕΔՄೳੑ͋Γ •

    ༨ஊͰ͕͢ɺEC-CUBE2ܥ͔ΒEC-CUBE3΁ͷσʔλϕʔεҠߦ πʔϧ͸ݱঢ়ఏڙ༧ఆͳ͠
  35. ։ൃ࣌ͷࢀߟϖʔδ • GitHubWiki
 https://github.com/EC-CUBE/ec-cube/wiki • GitHubPages
 http://ec-cube.github.io • Qiitaͷهࣄ
 http://qiita.com/tags/EC-CUBE3