Composerではじめるアプリケーション開発

 Composerではじめるアプリケーション開発

PHPで開発をするのに、デファクトスタンダードになったといって良いComposer。
そのComposerの使い方や使いどころなどを解説します。

想定しているターゲット:Composerをまだ使ったことがない人、Composerがうまく使いこなせていないと思う人、Composerに興味がある人、Composerが大好きな人

- PHPのDependency Managementの歴史とComposer
- Composerを使ってPSR-4アプリケーションを開発する
- よく使うコマンド
- チーム開発、バージョン管理とあわせた使い方
- その他の便利な使い方

C4c161ae9eeeed8f161197410f7a228a?s=128

Kenichiro Kishida

October 03, 2015
Tweet

Transcript

  1. “joind.in” => “twitter” => “#phpcon2015_3” https://m.joind.in/talk/ 6f314

  2. $PNQPTFSͰ͸͡ΊΔ ΞϓϦέʔγϣϯ։ൃ 1)1$POGFSFODFCZ!TJ[VIJLP Photo by A.Munich on GATAG

  3. ,FOJDIJSP,JTIJEB 5PLZP +"1"/ TJ[VIJLP!HNBJMDPN !TJ[VIJLP IUUQTHJUIVCDPNTJ[VIJLP IUUQCMPHPQFOUPLZPKQ +1POMZ

  4. None
  5. from 1999 pear2/pyrus from 2006 from 2008

  6. %FQFOEFODZ.BOBHFNFOU •Not Yum or Apt •inspired by node’s npm and

    ruby’s bundler •Manage libs on per-project
  7. https://twitter.com/s_bergmann/status/458265980150767616

  8. Photo by hbp_pix on GATAG https://github.com/sebastianbergmann/phpunit/wiki/End-of-Life-for-PEAR-Installation-Method

  9. Before Composer pear channel-discover pear.phpunit.de pear channel-discover components.ez.no pear channel-discover

    pear.symfony-project.com pear channel-discover pear.symfony.com pear install pear.symfony.com/Yaml pear update-channels pear upgrade-all pear clear-cache pear install -f -a phpunit/PHPUnit phpunit --version
  10. After Composer composer require phpunit/phpunit or composer install

  11. PHP The Right Way. http://ja.phptherightway.com/

  12. 1)1FS͕޾ͤʹͳΔͨΊͷಓඪ The way on happiness for PHPer

  13. wίʔσΟϯάελΠϧ $PEJOH4UZMF • PSR-0, PSR-1, PSR-2, PSR-4, Zend, Symfony w໊લۭؒ

    /BNFTQBDFT • PSR-0, PSR-4
  14. autoloading •require΍require_once͸ඞཁͳ͘ͳΔ No needed require / require_once •__autoload >= PHP5.0

    •spl_autoload_register >= 5.1.2
  15. Demo

  16. curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer https://getcomposer.org/doc/00-intro.md

  17. composer init

  18. composer install

  19. composer dumpautoload

  20. Α͘࢖͏ίϚϯυ commonly-used commands

  21. require composer require phpunit/phpunit composer require --dev phpunit/ph...

  22. remove composer remove phpunit/phpunit composer remove --dev phpunit/ph...

  23. update composer update phpunit/phpunit composer update --with-dependencies\ phpunit/phpunit

  24. list / help composer list composer help require

  25. config composer config --editor --global { "config": { "github-oauth": {

    "github.com": "abcd18397ef6547df" } } }
  26. ࠔͬͨΒhelp me

  27. -v | -vv | -vvv composer -vvv install

  28. νʔϜͰ࢖͏ for the team Photo by StartupStockPhotos on GATAG

  29. init composer.json require update remove /vendor/* composer.lock install /vendor/* 

  30. ߋ৽VQEBUF • όʔδϣϯΛݻఆ͢Δɺ*ͳͲΛ࢖Θͳ͍ recommend use fix version. no use *

    or dev- master • update࣌ʹύοέʔδ໊Λࢦఆ͢Δ using composer update with package and option -- with-dependencies
  31. িಥDPOqJDU 1.ϦϞʔτͷcomposer.lockΛ࠾༻ checkout remote composer.json and .lock 2.composer installͳͲΛ࠶࣮ߦ rerun

    composer install,require,update or etc.. 3.git add / git commit Photo by Seattle Municipal Archives on GATAG
  32. More Tips Photo by meridican on GATAG

  33. None
  34. None
  35. None
  36. None
  37. Repositories { "repositories": [{ "type": "vcs", "url": "git://github.com/sizuhiko/Bdd.git" },{ "type":

    "pear", "url": "https://pear2.php.net" },{ "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "source": { "url": "https://smarty-php.googlecode.com/svn/", "type": "svn", } }
  38. Script { "scripts": { "post-update-cmd": "MyVendor\\MyClass::postUpdate", "post-install-cmd": [ "MyVendor\\MyClass::warmCache", "phpunit

    -c app/" ] } }
  39. Public Library composer.json Proxy post-xxxx-cmd Project A Project B

  40. Create Project • ϑϨʔϜϫʔΫͳͲΛ࡞ͬͨͱ͖ʹ༗༻ convenience for creation framework • composer

    create-project --prefer-dist cakephp/app app • create-projectͷίʔϧόοΫΛݺͼग़͢ composer call script of create-project when defined "post-create-project-cmd": [ "php -r \"copy('config/local-example.php', 'config/local.php');\"" ]
  41. Photo by A.Munich on GATAG ·ͱΊ wΞϓϦέʔγϣϯ΍ϥΠϒϥϦͷ આ໌Λهड़ wґଘύοέʔδͷ؅ཧ wΦʔτϩʔυ

    wϦϙδτϦͷ؅ཧ wεΫϦϓτͷ࣮ߦ
  42. WJTJUNZCMPHHJUIVC https://github.com/sizuhiko 5IBOLZPV http://blog.open.tokyo.jp