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

Composerって何?
どう動くの?
読んでみました!  / lets-read-composer!

Composerって何?
どう動くの?
読んでみました!  / lets-read-composer!

 PHP Conference Japan 2019での発表資料(25分発表エディション)です

https://fortee.jp/phpcon-2019/proposal/80fe2e57-a35d-48cd-9c78-4af5000cbeac

hideki kinjyo

December 01, 2019
Tweet

More Decks by hideki kinjyo

Other Decks in Programming

Transcript

  1. © - BASE, Inc.
    Composerって何?

    どう動くの?

    読んでみました!
    . . - PHP Conference Japan

    View full-size slide

  2. © - BASE, Inc.
    ⾃⼰紹介
    • ۚ৓लथ / ͖Μ͡ΐ͏ͻͰ͖
    • GitHub: @o0h / Twitter: @o0h_
    • BASE, Inc. (2019.10) / ج൫νʔϜ
    • ex Connehito Inc.(2015.04-)
    • ޷͖ͳFW͸CakePHP
    • ΞΠίϯ͸

    ඒຯ͍͠ࡪ਌ࢠကͷࣸਅͰ͢

    View full-size slide

  3. © - BASE, Inc.
    本⽇は

    Composerのお話です!
    Composer\Console\Application::$logo

    View full-size slide

  4. © - BASE, Inc.
    Composer、

    使った事ありますか?

    View full-size slide

  5. © - BASE, Inc.
    では、

    Composerで

    困った事ありませんか?

    View full-size slide

  6. • install͕஗͍
    • ίϯϑϦΫτʁʁͳΜౖ͔ΒΕͨʂ
    • Φϓγϣϯ͕Α͘෼͔ΒΜ
    • ίϯϑΟά΋ΑʔΘ͔ΒΜ
    • .lockߋ৽ͰPR౤͛ΒΕͯ΋www

    View full-size slide

  7. © - BASE, Inc.
    いつもあんなにお世話になってるのに、
    彼(⼥)が困っている時に
    何もしてあげられない。

    View full-size slide

  8. © - BASE, Inc.
    それって、

    とても切なくないですか?

    View full-size slide

  9. © - BASE, Inc.
    よし、

    じゃあ腹割って話をしてみよう!

    View full-size slide

  10. © - BASE, Inc.
    Composerって何?

    どう動くの?

    読んでみました!
    . . - PHP Conference Japan

    View full-size slide

  11. © - BASE, Inc.
    Composerって

    どういう仕組みで

    動いているのかな?

    みたいな話をします
    お話すること
    composer installΛྫʹ

    View full-size slide

  12. © - BASE, Inc.
    Composerの

    「使い⽅」については

    触れません!
    お話しないこと

    View full-size slide

  13. © - BASE, Inc.
    この発表を機に、
    「Composer怖くないよ!」と

    感じてくれる⼈を増やしたい
    今回のゴール

    View full-size slide

  14. © - BASE, Inc.
    Composerはあくまで⼀例。
    「普段使っているツール」について、

    その中⾝に興味を持ってみるのは楽しいよ!
    というのを感じてもらえたら幸いです。
    今回の(裏)ゴール

    View full-size slide

  15. © - BASE, Inc.
    ΑΖ͓͘͠Ͷ͕͍͠·͢ʂ
    ͱ͍͏͜ͱͰʂ

    View full-size slide

  16. © - BASE, Inc.
    おしながき
    Installコマンドの全体感‧概要の整理
    初めてのComposer
    Installコマンドの中⾝を⾒てみる

    View full-size slide

  17. © - BASE, Inc.
    おしながき
    Installコマンドの全体感‧概要の整理
    初めてのComposer
    Installコマンドの中⾝を⾒てみる

    View full-size slide

  18. © - BASE, Inc.
    Composerͱ͸Կ͔ʁ

    View full-size slide

  19. © - BASE, Inc.
    Composerͱ͸Կ͔ʁ
    =>Composer͸ύοέʔδ؅ཧγεςϜ
    ※ެࣜαΠτͰ͸ʮComposer is a tool for dependency management in PHP.ʯͱઆ໌͍ͯ͠·͢ɻ

    Introduction - Composer https://getcomposer.org/doc/00-intro.md

    View full-size slide

  20. パッケージ管理システム?
    © - BASE, Inc.
    • ϨϙδτϦͷߪಡ
    • ύοέʔδͷΠϯετʔϧɾ࡟আ
    • ґଘؔ܎ͷղܾ
    • ઃఆ؅ཧ
    https://ja.wikipedia.org/wiki/ύοέʔδ؅ཧγεςϜ

    View full-size slide

  21. パッケージ管理とComposer
    © - BASE, Inc.
    • Packagistͱ΍ΓͱΓͨ͠Γ

    <= ϨϙδτϦͷߪಡ
    • GitHub͔Βguzzlehttp/clientΛऔಘͯ͠഑ஔͨ͠Γ

    <= ύοέʔδͷΠϯετʔϧɾ࡟আ
    • ^1.2ͱ~1.2ʹର͠1.3.0Ͱ͸ͳ͘1.2.9ΛऔͬͨΓ

    <= ґଘؔ܎ͷղܾ
    • composer.jsonͷத਎Λղऍͨ͠Γ

    <= ઃఆ؅ཧ


    View full-size slide

  22. パッケージ管理の「PHP実装」
    © - BASE, Inc.
    ґଘ؅ཧͷେม͞Αʂ
    ύοέʔδ؅ཧͩʂ
    Composerര஀ʂ
    ՝୊
    ղ๏
    ࣮૷

    View full-size slide

  23. 抽象の解釈としての実装
    © - BASE, Inc.
    • ϨϙδτϦͷߪಡ
    • ύοέʔδͷΠϯετʔϧɾ࡟আ
    • ґଘؔ܎ͷղܾ
    • ઃఆ؅ཧ
    ݱ࣮ɾந৅ ιϑτ΢ΣΞɾ࣮૷
    • \Composer\Repository\
    • \Composer\Installer\
    • \Composer\Package\
    • \Composer\DependencyResolver\

    View full-size slide

  24. \Composer\Repository\
    © - BASE, Inc.
    • ϨϙδτϦ৘ใͷ؅ཧ
    –repositories[].typeͷ෦෼ʹରԠ͢ΔΠϝʔδ
    • ex:
    –ComposerRepository: packagistϨϙ
    –VcsRepository: GitHub΍SVNͳͲͷϨϙ
    –PathRepository: ϩʔΧϧϑΝΠϧ
    Repositories - Composer https://getcomposer.org/doc/05-repositories.md

    View full-size slide

  25. \Composer\Installer\
    © - BASE, Inc.
    • Πϯετʔϧͷ؅ཧ
    –ύοέʔδDLͷىಈͱ͔औಘϑΝΠϧͷ഑ஔͱ͔
    • ex:
    –LibraryInstaller: packageͷΠϯετʔϧ
    –ProjectInstaller: root projectͷΠϯετʔϧ
    –PluginInstaller: plugin packageͷΠϯετʔϧ
    –PearInstaller: pear packageͷΠϯετʔϧ

    View full-size slide

  26. \Composer\Package\
    © - BASE, Inc.
    • ύοέʔδ৘ใͷ؅ཧ
    –composer.jsonΛղऍͨ͠Γ
    • ex:
    –RootPackage: root projectͷ؅ཧ
    –Locker: composer.lockͷ؅ཧ
    –Link: packageؒͷ(ґଘ)ؔ܎

    View full-size slide

  27. \Composer\DependencyResolver\
    © - BASE, Inc.
    • ґଘؔ܎ͷ؅ཧ
    –ෳ਺Ϩϙ͔Βύοέʔδ৘ใΛ౷߹ͨ͠Γ
    –install͢Δ͔ʁupdate͢Δ͔?ͦͷ··͔?ΛܾΊͨΓ
    • ex:
    –Solver: ґଘؔ܎Λ੔ཧ͠ύοέʔδͷѻ͍ΛܾΊΔ
    –Pool: ϨϙδτϦ΍ύοέʔδ৘ใͷू໿
    –Operation: install,update,removeͳͲͷૢ࡞Λࣔ͢

    View full-size slide

  28. © - BASE, Inc.
    ίί·Ͱୈ1ষʂ

    View full-size slide

  29. 初めてのComposer: まとめ
    © - BASE, Inc.
    • ύοέʔδ؅ཧʹඞཁͳཁૉ
    –ϨϙδτϦ,Πϯετʔϥ,ґଘղܾ,ઃఆ؅ཧ
    • Composer΋ύοέʔδ؅ཧͷʮ࣮૷ʯ
    –্هͷ4֓೦ʹ͍ͭͯ΋ɺ

    ͦΕͧΕରԠ͢Δnamespace͕ଘࡏ͢Δ

    View full-size slide

  30. © - BASE, Inc.
    おしながき
    Installコマンドの全体感‧概要の整理
    初めてのComposer
    Installコマンドの中⾝を⾒てみる

    View full-size slide

  31. © - BASE, Inc.
    おしながき
    Installコマンドの全体感‧概要の整理
    初めてのComposer
    Installコマンドの中⾝を⾒てみる

    View full-size slide

  32. $ composer instal -vvv

    View full-size slide

  33. ͜ͷը໘ͷҙຯ͕෼͔ΔΑ͏ʹ͢Δͧʂ

    View full-size slide

  34. © - BASE, Inc.
    コードの「⼊り⼝」を捉える
    installίϚϯυͷىಈ·ͰͷྲྀΕΛ஌Δ
    ·ͣ͸

    View full-size slide

  35. ApplicationとしてのComposer
    © - BASE, Inc.
    Composerͷຊମͱ͍͑͹ίΠπͰ͕͢

    View full-size slide

  36. ApplicationとしてのComposer
    © - BASE, Inc.
    த਎ΛݟͯΔͱɺ࣮ଶ͸Console\Application

    View full-size slide

  37. symfony/console
    © - BASE, Inc.
    • Composer͸symfony/
    consoleΛར༻
    • CLIπʔϧΛ؆୯ʹ࡞Ε
    Δύοέʔδ
    • CommandΫϥεͱ͍͏
    ୯ҐΛ࡞Γ
    • Applicationͷதʹొ࿥
    ͢Δ
    ※ symfony/consoleʹ͍ͭͯ͸ίνϥͷهࣄͳͲΛͲ͏ͦ

    Container(PSR-11)ͱsymfony/consoleͰ؆୯ͳίϚϯυϥΠϯΞϓϦέʔγϣϯΛ࡞ͬͯΈΑ͏ - istyle Tech Blog

    https://techblog.istyle.co.jp/archives/97

    View full-size slide

  38. Composer\Command
    © - BASE, Inc.
    $composer about
    $composer config
    $composer check-platform-

    View full-size slide

  39. installってどこにあるの?
    © - BASE, Inc.
    InstallCommandΫϥε

    View full-size slide

  40. © - BASE, Inc.
    InstallCommand::execute()ͷେ·͔ͳΠϝʔδ

    View full-size slide

  41. © - BASE, Inc.
    InstallCommand::execute()ͷେ·͔ͳΠϝʔδ
    factoryͯ͠

    View full-size slide

  42. © - BASE, Inc.
    InstallCommand::execute()ͷେ·͔ͳΠϝʔδ
    ઃఆͯ͠

    View full-size slide

  43. © - BASE, Inc.
    InstallCommand::execute()ͷେ·͔ͳΠϝʔδ
    ࣮ߦʂ

    View full-size slide

  44. © - BASE, Inc.
    (༨ஊ)
    ΫϥεʮComposer\Installerʯͱ
    ໊લۭؒʮComposer\Installer\*ʯ͕͋Γ·͕͢
    ผ෺Ͱ͢ɻ
    Class namespace

    View full-size slide

  45. © - BASE, Inc.
    ֓؍

    View full-size slide

  46. © - BASE, Inc.
    ΊͬͪΌ؆୯΍Μ͚ʂʂ

    View full-size slide

  47. © - BASE, Inc.
    ຊ౰ʹͦ͏͔ʂʁ

    View full-size slide

  48. © - BASE, Inc.
    メインとなる仕事の中⾝を追う
    InstallCommandͷ࢓ࣄ ≒ Installerͷ࢓ࣄ
    =>͡Ό͋InstallerಡΊ͹ྑ͍͔

    View full-size slide

  49. Installerを開くと‧‧
    © - BASE, Inc.
    ίϯετϥΫλ͔Βͯ͠طʹେมͦ͏…

    View full-size slide

  50. © - BASE, Inc.
    ෳࡶͦ͏ͳίʔυ͸ɺ
    ۩ମతʹಡΈ࢝ΊΔલʹ

    ࢓ࣄ಺༰ͷΠϝʔδͱ

    ʮίίͲ͏ͳͬͯΔΜͩʁʯΛ੔ཧ͓ͯ͘͠
    ஍ਤΛඳ͘

    View full-size slide

  51. installの⼤まかな流れ
    © - BASE, Inc.
    1.PJ৘ใ(RootPackage)ͷಡΈࠐΈ
    2.ϨϙδτϦ৘ใͷಡΈࠐΈ
    3.ߋ৽಺༰ͷࢉग़(ґଘੑͷ੔ཧ)
    4.ύοέʔδͷऔಘɾ഑ஔ
    5..lockϑΝΠϧͷߋ৽
    6.autoloadϑΝΠϧͷੜ੒
    ࣄલॲཧ
    ґଘղܾ
    ࣄޙॲཧ

    View full-size slide

  52. © - BASE, Inc.
    ͜ͷลΓΛ೦಄ʹஔ͖ͭͭ

    ࣮ࡍͷྲྀΕΛݟͯΈΔʂʂ

    View full-size slide

  53. Installer::run()の全体像
    © - BASE, Inc.
    functionͷத਎͸

    ͜Μͳײ͡

    View full-size slide

  54. Installer::run()の全体像
    © - BASE, Inc.
    ΠϯετʔϧࡁΈͷ
    ύοέʔδ৘ใΛ

    औಘͯ͠

    View full-size slide

  55. Installer::run()の全体像
    © - BASE, Inc.
    ґଘੑͷղܾ΍

    ύοέʔδͷऔಘ

    &഑ஔΛͯ͠

    View full-size slide

  56. Installer::run()の全体像
    © - BASE, Inc.
    .lockϑΝΠϧΛ

    ߋ৽ͯ͠

    View full-size slide

  57. Installer::run()の全体像
    © - BASE, Inc.
    autoloadϑΝΠϧͷ

    ग़ྗʂ

    View full-size slide

  58. © - BASE, Inc.
    ͜Ε͕installͷਖ਼ମʂʂ
    ʙୈ2ষɾfinʙ


    View full-size slide

  59. Installコマンドの全体感‧概要の整理: まとめ
    © - BASE, Inc.
    • جຊతͳίϚϯυ͸

    src/Composer/Commandʹ

    Ϋϥεͱ࣮ͯ͠૷͞Ε͍ͯΔ
    • Installॲཧͷ࣮ଶ͸ɺ

    InstallCommand->Installer::run()ʹ͋Δ

    View full-size slide

  60. © - BASE, Inc.
    おしながき
    Installコマンドの全体感‧概要の整理
    初めてのComposer
    Installコマンドの中⾝を⾒てみる

    View full-size slide

  61. © - BASE, Inc.
    おしながき
    Installコマンドの全体感‧概要の整理
    初めてのComposer
    Installコマンドの中⾝を⾒てみる

    View full-size slide

  62. installの⼤まかな流れ
    © - BASE, Inc.
    1.PJ৘ใ(RootPackage)ͷಡΈࠐΈ
    2.ϨϙδτϦ৘ใͷಡΈࠐΈ
    3.ߋ৽಺༰ͷࢉग़(ґଘੑͷ੔ཧ)
    4.ύοέʔδͷऔಘɾ഑ஔ
    5..lockϑΝΠϧͷߋ৽
    6.autoloadϑΝΠϧͷੜ੒
    ࣄલॲཧ
    ґଘղܾ
    ࣄޙॲཧ
    ࠶ܝ

    View full-size slide

  63. © - BASE, Inc.
    PJ情報の読み込み
    事前処理①

    View full-size slide

  64. PJの読み込み?
    © - BASE, Inc.
    • ϓϩδΣΫτ(PJ)͸ύοέʔδͷҰܗଶ
    • ύοέʔδ͸

    ࣗ෼͕ґଘ͍ͯ͠ΔϞϊͷ৘ใΛ࣋ͭ
    • ͳͷͰґଘղܾͷ࠷ॳͷҰา͸

    ʮPJͷ৘ใΛಡΈࠐΉʯ͜ͱ

    View full-size slide

  65. RootPackage
    © - BASE, Inc.
    • ComposerͷੈքͰ͸ɺ

    1ͭͷcomposer.jsonʹରԠͯ͠

    1ͭͷPackageΠϯελϯε͕࡞ΕΔ
    • ͦͷதͰɺ

    PJࣗ਎ = rootͱͳΔPackage͸

    RootPackageΠϯελϯε͕࡞ΒΕΔ

    View full-size slide

  66. Package
    © - BASE, Inc.
    • ͭ·Γ `composer install` ࣮ߦͱ͸

    RootPackageͷґଘੑͷղܾͱݴ͑Δ
    • Packageͷதʹ͸ɺࣗ਎ͷόʔδϣϯ৘
    ใ΍ґଘ͢Δύοέʔδͷ৘ใetcؚ͕
    ·Ε͍ͯΔ

    View full-size slide

  67. RootPackageの取得
    © - BASE, Inc.
    Installer::create()
    Composer::getPackage()

    View full-size slide

  68. © - BASE, Inc.
    レポジトリ情報の読み込み
    事前処理②

    View full-size slide

  69. [定義]レポジトリってなんだ?
    © - BASE, Inc.
    • (ར༻Մೳͳ)ύοέʔδ৘ใΛ؅ཧ͢Δ
    –໊લ
    –όʔδϣϯ
    –औಘઌ

    View full-size slide

  70. レポジトリ情報の読み込み
    © - BASE, Inc.
    • ࢦఆ͞Εͨ΋ͷ͕ଘࡏ͢Δ͔ʁ

    Ͳ͜ʹ͋Δ͔ʁΛ஌Βͳ͍ͱ

    ύοέʔδͷDL͕Ͱ͖ͳ͍
    • ϨϙδτϦ͕ͦΕΛ؅ཧ͢Δɻ

    ʮԿͷύοέʔδ͕༗Δ͔ʯͷ৘ใΛ

    ೺Ѳ͠ɺϢʔβʔʹఏڙ͢Δ

    View full-size slide

  71. Repository(Interface)
    © - BASE, Inc.
    • ComposerͷੈքͰ͸ɺ

    ϨϙδτϦ͸RepositoryInterfaceͷ࣮૷
    Ͱදݱ͞ΕΔ
    • Repository͸ʮύοέʔδ৘ใͷҰཡʯ
    ΛಡΈࠐΈɺ؅ཧ͢Δ
    • ʮऔಘʯ΍ʮݕࡧʯͷػೳΛఏڙ͢Δ

    View full-size slide

  72. composer installͰ͸ɺ

    ϩʔΧϧٴͼϦϞʔτͷ৘ใ͕ؔΘΔ
    基本的なレポジトリ3つ
    © - BASE, Inc.
    ϩʔΧϧ
    InstalledFilesystemRepo
    PlatformRepo
    (΄΅)

    vendorσΟϨΫτϦ
    PHPͷγεςϜ৘ใ
    ϦϞʔτ ComposerRepo Packagist

    View full-size slide

  73. InstalledFilesystemRepo
    © - BASE, Inc.
    • ΠϯετʔϧࡁΈύοέʔδͷ؅ཧ
    –಺༰͸ `vendor/composer/installed.json`
    • ʮطʹ͋ΔPackageʯͷղܾ͸

    ͜ͷϨϙδτϦΛૢ࡞͢Δ͜ͱͰ࣮ݱ

    View full-size slide

  74. InstalledFilesystemRepoの様⼦
    © - BASE, Inc.
    $composer show —tree

    View full-size slide

  75. • γεςϜཁ݅ͷ؅ཧ
    –phpͷόʔδϣϯ΍༗ޮͳ֦ுͳͲ
    • requireʹ'php”΍”ext-XXX”͕هड़͞Εͨ
    ࣌ʹར༻͞ΕΔ
    PlatformRepository
    © - BASE, Inc.
    composer.json

    View full-size slide

  76. PlatformRepositoryの様⼦
    © - BASE, Inc.
    $composer show —platform

    View full-size slide

  77. ComposerRepository
    © - BASE, Inc.
    • Packagist্ͷύοέʔδͷ؅ཧ
    –಺༰͸ `https://packagist.org/packages.json`
    • indexϑΝΠϧ
    –͜͜ʹه͞Ε͍ͯΔιʔεΛϑΣον͢Δ
    • ࠷ॳ͸ʮύοέʔδ໊ͷҰཡʯͷΈ
    –ͨͩ͠ɺͦΕࣗମ΋஗Ԇॲཧ͞ΕΔ
    –ղܾ͕ඞཁͳύοέʔδ͕ग़͖ͯͨ࣌ʹ

    ύοέʔδݸผͷ৘ใΛऔΓʹߦ͘

    View full-size slide

  78. ComposerRepositoryのリスト更新
    © - BASE, Inc.
    ϦετΛऔಘ͍ͯ͠Δ༷ࢠ
    $ composer install

    View full-size slide

  79. © - BASE, Inc.
    isntallʹ͓͍ͯɺ͜ΕΒ͸Ͳ͏ѻΘΕΔ͔ʁ

    View full-size slide

  80. Poolの作成とRepoの登録
    © - BASE, Inc.
    • Pool
    –ϨϙδτϦ΍ύοέʔδΛ؅ཧ͢Δ
    –ҎޙɺϨϙδτϦʹର͢Δύοέʔδͷ໰͍߹
    Θͤ͸(جຊతʹ)PoolΛհͯ͠ߦΘΕΔ
    • ґଘੑͷղܾʹਐΉલʹɺ

    ࡞੒͞Ε͍ͯΔ3ͭͷRepositoryΠϯελ
    ϯεΛPoolʹొ࿥͢Δ

    View full-size slide

  81. Poolの作成とRepoの登録
    © - BASE, Inc.
    Installer::doInstall

    View full-size slide

  82. Poolの作成とRepoの登録
    © - BASE, Inc.
    Poolͷ࡞੒

    View full-size slide

  83. Poolの作成とRepoの登録
    © - BASE, Inc.
    ϩʔΧϧRepoͷొ࿥

    View full-size slide

  84. Poolの作成とRepoの登録
    © - BASE, Inc.
    ଞͷRepoͷొ࿥

    View full-size slide

  85. © - BASE, Inc.
    ίί·Ͱࣄલॲཧ

    View full-size slide

  86. installの事前処理: まとめ
    © - BASE, Inc.
    • PJ৘ใ͸RootPackageͱͯ͠ΠϯελϯεԽ
    ͞ΕΔ
    • installʹ͓͍ͯ͸ϩʔΧϧͱϦϞʔτͷ
    Repository͕ಡΈࠐ·ΕΔ
    –InstalledFilesystem, Platform, Composer
    • ಡΈࠐ·ΕͨRepository͸Poolʹ௥Ճ͞Εɺ
    ౷߹తʹղܾ͢Δͷʹར༻͞ΕΔ

    View full-size slide

  87. © - BASE, Inc.
    更新内容の算出(依存性の整理)
    依存解決①

    View full-size slide

  88. 更新内容の算出(依存性の整理)?
    © - BASE, Inc.
    • (rootΛؚΉ)ෳ਺ͷύοέʔδ͕ɺ

    ͦΕͧΕʹෳ਺ͷύοέʔδʹґଘ͍ͯ͠Δ
    • ͦΕΒͷ৘ใΛ౷߹͢Δඞཁ͕͋Δ
    –֤ύοέʔδ͕Կʹґଘ͍ͯ͠Δ͔Λ࠶ؼతʹ೺Ѳ
    ͢Δ
    –ચ͍ग़͞Εͨґଘʹ͍ͭͯɺڞ༗Ͱ͖Δ΋ͷ΍িಥ
    ͕ͳ͍͔Λௐ΂Δ
    • ࠷ऴతʹʮԿ͕΄͍͔͠ʯΛ೺Ѳ͢Δ

    View full-size slide

  89. © - BASE, Inc.
    ߟ͑ͳ͚Ε͹͍͚ͳ͍ͷ͸ɺ

    Packageͷrequire৘ใ͔Βελʔτͯ͠

    ґଘઌͷґଘ΋͋ΔதͰ

    શͯͷ৚݅(ࢦఆver.)Λຬͨ͢ʹ͸

    ԿΛऔಘ͢Ε͹ྑ͍ͷ͔ʁͷ

    ʮਖ਼ղʯΛݟ͚ͭΔɺͱ͍͏͜ͱ

    View full-size slide

  90. © - BASE, Inc.
    ߟ͑ͳ͚Ε͹͍͚ͳ͍ͷ͸ɺ

    Packageͷrequire৘ใ͔Βελʔτͯ͠

    ґଘઌͷґଘ΋͋ΔதͰ

    શͯͷ৚݅(ࢦఆver.)Λຬͨ͢ʹ͸

    ԿΛऔಘ͢Ε͹ྑ͍ͷ͔ʁͷ

    ʮਖ਼ղʯΛݟ͚ͭΔɺͱ͍͏͜ͱ
    ͬ͘͟ΓͱॲཧखॱͷΠϝʔδ͚ͩઆ໌
    ෳࡶͩͶʂ

    View full-size slide

  91. PackageとRequest
    © - BASE, Inc.
    • Package->requiresͷ৘ใ
    Λ࿈Ͷ͍ͯ͘ʮཉ͍͠
    ෺ʯͷΩϡʔΛଋͶΔΫ
    ϥε͕ཉ͍͠
    • ͦΕ͕RequestΫϥε
    • require1ߦ͝ͱʹjob͕1
    ݸͰ͖ΔΠϝʔδ(=job)
    Package
    phpunit/phpunit:^8.4
    Request
    jobs

    View full-size slide

  92. RequestとJob
    © - BASE, Inc.
    Request
    jobs
    job͸୯७ͳ࿈૝഑ྻ
    • jobͷ࣋ͭ৘ใ
    –cmd
    • install|update|remove
    –packageName
    –constraint
    • ver.ࢦఆ

    View full-size slide

  93. RequestとSolver
    © - BASE, Inc.
    • Solver::solve()ʹ

    RequestΛ౉͢
    • ͜ͷதͰڝ߹৚݅ɾڞ௨
    ෦෼͕ߟྀ͞ΕΔ
    • jobsΛݩʹɺ

    ʮԿΛ͢Ε͹͍͍͔ʯΛ
    Installerʹฦͯ͘͠ΕΔ
    Solver
    Request
    Operation[]

    View full-size slide

  94. Operation
    © - BASE, Inc.
    • job͕ղܾ͞Εɺ࠷ऴ
    తʹߋ৽ૢ࡞͕ඞཁͳ
    ΋ͷ͚͕ͩฦ͞ΕΔ
    • ྫ͑͹”Nothing to
    install or update”ͳ
    Βɺ`solve()`ͷฦΓ஋
    ͸ۭ഑ྻ
    Solver
    Operation
    jobs
    Operation
    jobs
    Operation

    View full-size slide

  95. © - BASE, Inc.
    パッケージの取得‧配置
    依存解決②

    View full-size slide

  96. パッケージの取得‧配置?
    © - BASE, Inc.
    • ʮͲͷύοέʔδΛऔಘ(ߋ৽ɺ࡟আ)͢Ε
    ͹ྑ͍͔ʯͱ͍͏৘ใΛಘͨ
    • ͦΕͧΕʹ͍ͭͯɺద੾ͳ৔ॴ͔Βऔಘ
    ͢Δ
    • ඞཁʹԠͯ͡ղౚ΍मਖ਼ͳͲͷॲཧ΋͸
    ͞Έͭͭɺ࠷ऴతʹنଇతͳ৔ॴ΁഑ஔ
    ͢Δ

    View full-size slide

  97. 実際にパッケージをDLしてくる
    © - BASE, Inc.
    • ύοέʔδͷΠϯετʔϧ͸ɺ
    InstallationManager::execute()ʹΑͬͯ
    ߦΘΕΔ
    • औಘݩ͸Package͕஌͍ͬͯΔ
    • DLઌΛܾఆ͢Δͷ͸Installerͷ࢓ࣄ
    • DLΛ͢Δͷ͸Downloaderͷ࢓ࣄ

    View full-size slide

  98. © - BASE, Inc.
    Operation[]ΛInstallationManagerʹ౉͢৔໘
    Installer::doInstall()

    View full-size slide

  99. 流れ
    © - BASE, Inc.

    View full-size slide

  100. 流れ
    © - BASE, Inc.
    ݟ͑ͳ͍ͷͰૡ͍ఠΉ
    ߏ଄͕ਂ͍ͥʂ

    View full-size slide

  101. 流れ(ざっくり)①
    © - BASE, Inc.
    Installer
    InstallationManager
    operation͔ΒpackageΛरͬͯ
    packageͷtypeʹԠͨ͡installerΛ༻ҙ
    LibraryInstaller
    locaRepo, operation
    locaRepo, operation

    View full-size slide

  102. 流れ(ざっくり)②
    © - BASE, Inc.
    DownloadManager
    package͔ΒtypeʹԠͨ͡

    downloaderΛऔಘ
    package, downloadPath
    package, downloadPath
    LibraryInstaller
    Downloader
    packageͷ৘ใΛಡΈऔͬͯ

    downloadPathʹల։

    View full-size slide

  103. 流れ(ざっくり)③
    © - BASE, Inc.
    localRepo
    ΠϯετʔϧࡁΈύοέʔδͷ

    ৘ใ(ΦϯϝϞϦ)Λߋ৽
    package
    LibraryInstaller
    Installer
    installed.jsonͷߋ৽

    View full-size slide

  104. © - BASE, Inc.
    ίί·Ͱґଘղܾ

    View full-size slide

  105. installの依存解決: まとめ
    © - BASE, Inc.
    • RootΛؚΉؔ࿈PackageͷrequireΛશͯ
    ྻڍ͠(Request/job)ɺSolverʹΑ࣮ͬͯ
    ߦ͢΂͖ૢ࡞ΛߜΓࠐΜͰ͍Δ
    • Package͝ͱʹInstallerɾDownloaderΛ
    ىಈ͠ɺવΔ΂͖ιʔείʔυΛDL͢Δ

    View full-size slide

  106. © - BASE, Inc.
    .lockファイルの更新
    事後処理①

    View full-size slide

  107. .lockファイルに載せる情報は?
    © - BASE, Inc.
    • .lockϑΝΠϧ͸ɺʮίί·ͰʹΠϯε
    τʔϧͨ͠΋ͷʯͷࣸ૾
    –औಘ͞ΕͨPackage: localRepoͷσʔλ
    –ϓϥοτϑΥʔϜͷ৘ใ: composer.json +
    PlatformReqRepoͷσʔλ
    –ͦͷଞɺstabilityϑϥάͳͲ: RootPackageͷ
    σʔλ

    View full-size slide

  108. 必要な情報を合成してdumpする
    © - BASE, Inc.
    • Composer\Package\Locker
    –ʮ.lockϑΝΠϧͷΠϯελϯεʯͳΠϝʔδ
    • Locker::setLockData()ʹ

    ඞཁͳ৘ใΛ౉ͨ͠Βɺ

    jsonσʔλΛ૊ΈཱͯͯϑΝΠϧʹग़ྗ
    ͜͜·ͰͷRepo/PackageͷΠϝʔδΛ௫Ί͍ͯΕ͹ɺ

    .lockσʔλͷࢉग़͸γϯϓϧͰ͢Ͷʂ

    View full-size slide

  109. © - BASE, Inc.
    autoloadファイルの更新
    事後処理②

    View full-size slide

  110. autoloadファイルに載せる情報は?
    © - BASE, Inc.
    • ಺༰͸localRepoʹྻڍ͞Ε͍ͯΔ΋ͷ
    • ઃఆ৘ใͱͯ͠ɺ
    –RootPackageͷ಺༰
    –Composer\Configͷ಺༰
    –etc

    View full-size slide

  111. 各ファイルの出⼒
    © - BASE, Inc.
    • autoloadϑΝΠϧ͸ෳ਺ͷ಺༰͔Β੒Δ
    –ΫϥεϚοϓ
    –includeϑΝΠϧ
    –Composer\Autoload\ClassLoader
    –etc.
    • ͜ΕΒΛ`vendor/composer`ҎԼʹग़ྗ
    –※ઃఆʹΑͬͯҟͳΔ

    View full-size slide

  112. © - BASE, Inc.
    おしながき
    Composerのcommandとは何か
    実装からみる「Composerとは何か」
    `install`を深堀りしてみる

    View full-size slide

  113. © - BASE, Inc.
    まとめ

    View full-size slide

  114. まとめ
    © - BASE, Inc.
    • install͸Ұݟ

    ෳࡶͦ͏͚ͩͲෳࡶͩͥʂ
    • ෳࡶͳϞϊ͸ɺʮԿΛղܾ͢Δͷ͔ʁʯ
    Λҙࣝ͢ΔͱྲྀΕ͕௫Έ΍ͦ͢͏˕

    View full-size slide

  115. © - BASE, Inc.
    ※આ໌͠΍͢͞ॏࢹͰɺ

    ͍ͩͿ؆ུԽͯ͠࿩͠·ͨ͠ɻ
    ൃදͷதͰ৮Ε͍ͯͳ͍෦෼΋ଟʑ͋ΔͷͰɺ

    ͦ͜͸ੋඇίʔυΛಡΜͰΈ͍ͯͩ͘͞ʂ


    View full-size slide

  116. © - BASE, Inc.
    いつも触っているものが

    なぜ動くのか?を知れると

    楽しいです!!!

    View full-size slide

  117. © - BASE, Inc.
    、やっていきましょう!

    View full-size slide

  118. © - BASE, Inc.
    ࣭͝໰ͳͲʂ

    ※งғؾճ౴ʹͳͬͨΒ͢Έ·ͤΜʂ

    View full-size slide

  119. © - BASE, Inc.
    お付き合いいただき

    ありがとうございました!

    View full-size slide