Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Composer the right way [SweetlakePHP]

2,216 views

Published on

Composer has triggered a renaissance in the PHP community, it has changed the way we deal with other people’s code and it has changed the way we share our code. We are all slowly moving to using Composer, from Wordpress to Joomla and Drupal and frameworks in between. But many of us mistreat composer, follow outdated practices or simply lack a few tricks. In this session i’ll get you the low down on how to use composer the right way.

Published in: Technology

Composer the right way [SweetlakePHP]

  1. 1. Composer the right way Rafael Dohms @rdohms
  2. 2. photo: smileymanwithahat
  3. 3. photo: Rob Allen
  4. 4. www.kickstarter.com/projects/rdohms/the-amsterdamphp-elephpant
  5. 5. photo: 18millionpixels
  6. 6. Library Publisher photo: 18millionpixels
  7. 7. Library Publisher Library Consumer photo: 18millionpixels
  8. 8. Library Publisher Library Library Consumer photo: 18millionpixels
  9. 9. Library Publisher Library Packagist Library Consumer photo: 18millionpixels
  10. 10. photo: 18millionpixels
  11. 11. { "require": { "monolog/monolog": “2.0” } } photo: 18millionpixels
  12. 12. { "require": { "monolog/monolog": “2.0” } } { "name": “monolog/monolog” ... } photo: 18millionpixels
  13. 13. { "require": { "monolog/monolog": “2.0” } } { "name": “monolog/monolog” ... } ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. ! Problem 1 - The requested package monolog/monolog could not be found in any version, there may be a typo in the package name. ! Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details. ! Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems. ! Installation failed, reverting ./composer.json to its original content. photo: 18millionpixels
  14. 14. { "require": { ___ ~1.1 "monolog/monolog": “2.0” } } { "name": “monolog/monolog” ... } ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. ! Problem 1 - The requested package monolog/monolog could not be found in any version, there may be a typo in the package name. ! Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details. ! Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems. ! Installation failed, reverting ./composer.json to its original content. photo: 18millionpixels
  15. 15. { "require": { ___ ~1.1 "monolog/monolog": “2.0” } } { "name": “monolog/monolog” ... } ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. ! Problem 1 - Installing psr/log (1.0.0) Loading from cache ! - Installing monolog/monolog (1.11.0) - The requested package monolog/monolog could not be found in any version, there may be a typo in the package name. ! Downloading: 100% Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting ! monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server) [...] monolog/see <https://monolog groups.suggests google.installing com/d/ext-topic/mongo composer-(Allow dev/_sending g3ASeIFlrc/log messages discussion> to a for MongoDB more server) details. monolog/! monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB) monolog/Read <http://monolog getcomposer.suggests org/installing doc/articles/rollbar/troubleshooting.rollbar (Allow md> sending for further log messages common to problems. Rollbar) ! Writing lock file Installation Generating autoload failed, files reverting ./composer.json to its original content. photo: 18millionpixels
  16. 16. composer
  17. 17. ! composer.json composer
  18. 18. ! composer.json composer ! composer.lock
  19. 19. ! composer.json composer ! composer.lock
  20. 20. discovery Packagist " ! composer.json composer ! composer.lock
  21. 21. discovery Packagist source " Repository # ! composer.json composer ! composer.lock
  22. 22. discovery source installation Packagist " Vendor Folder $ Repository # ! composer.json composer ! composer.lock
  23. 23. Library Publisher $ composer init
  24. 24. Library Publisher $ composer init Library Consumer $ composer require <vendor>/<package>
  25. 25. Tip $ composer require monolog/monolog Using version ~1.11 for monolog/monolog
  26. 26. Composer for Library Publishers
  27. 27. vendor / package Library Publisher Unique vendor names
  28. 28. pick your own unique vendor Library Publisher Unique vendor names
  29. 29. or join a collective Library Publisher Unique vendor names
  30. 30. ! README % CHANGELOG & LICENSE Library Publisher What’s in your library?
  31. 31. ! README % CHANGELOG & LICENSE ' What problem does it solve? ' Usage examples ' Install instructions ' How can I contribute? Library Publisher What’s in your library?
  32. 32. ! README % CHANGELOG & LICENSE ' What problem does it solve? ' Usage examples ' Install instructions ' How can I contribute? ' List relevant changes ' Make BC breaks prominent ' Show examples of how to upgrade Library Publisher What’s in your library?
  33. 33. ! README % CHANGELOG & LICENSE ' What problem does it solve? ' Usage examples ' Install instructions ' How can I contribute? ' List relevant changes ' Make BC breaks prominent ' Show examples of how to upgrade ' Pick one that reflects your values ' choosealicense.com can help Library Publisher What’s in your library?
  34. 34. 1 . 2 . 3 major minor patch Library Publisher Semantic Versioning
  35. 35. 1 . 2 . 3 major minor patch Library Publisher Semantic Versioning Bug Fixes
  36. 36. New Features Bug Fixes 1 . 2 . 3 major minor patch Library Publisher Semantic Versioning
  37. 37. API / BC Breaks New Features Bug Fixes 1 . 2 . 3 major minor patch Library Publisher Semantic Versioning
  38. 38. Tag it and Bag it Library Publisher Tagging
  39. 39. # Simple Tag $ git tag v1.2.3 ! ! ! # Annotated Tag $ git tag -a v1.2.3 -m “Description of Release" Library Publisher Tagging
  40. 40. Library Publisher “I'm out" photo: jilliancorinne
  41. 41. Library Publisher “I'm out"
  42. 42. Click here and provide another Library Publisher “I'm out"
  43. 43. Library Publisher “I'm out"
  44. 44. Library Publisher “I'm out"
  45. 45. Pick the correct version Library Publisher Pick a Version
  46. 46. * the asterisk Library Publisher Pick a Version
  47. 47. * the asterisk ○ Library Publisher Pick a Version
  48. 48. ~ the tilde Library Publisher Pick a Version
  49. 49. ~1.2 >=1.2.0, <2.0.0 Library Publisher Pick a Version
  50. 50. ~1.2 >=1.2.0, <2.0.0 Library Publisher Pick a Version )
  51. 51. ~1.2.3 >=1.2.3, <1.3 Library Publisher Pick a Version
  52. 52. ~1.2.3 >=1.2.3, <1.3 Library Publisher Pick a Version )
  53. 53. 3rd party library "require": { "zendframework/zend-stdlib": “2.1.*”, "zendframework/zend-servicemanager": "2.1.*", }, ! “require-dev": { “phpunit/phpunit": “~3.7” } Your application "require": { "zendframework/zend-stdlib": “~2.3”, "zendframework/zend-servicemanager": “~2.3", }, ! “require-dev": { “phpunit/phpunit": “~4” } Library Publisher Pick a Version
  54. 54. 3rd party library "require": { "zendframework/zend-stdlib": “2.1.*”, "zendframework/zend-servicemanager": "2.1.*", }, ! “require-dev": { * “phpunit/phpunit": “~3.7” } Your application "require": { "zendframework/zend-stdlib": “~2.3”, "zendframework/zend-servicemanager": “~2.3", }, ! “require-dev": { “phpunit/phpunit": “~4” } Library Publisher Pick a Version
  55. 55. 3rd party library "require": { "zendframework/zend-stdlib": “2.1.*”, "zendframework/zend-servicemanager": "2.1.*", }, ! “require-dev": { * “phpunit/phpunit": “~3.7” } Your application "require": { "zendframework/zend-stdlib": “~2.3”, "zendframework/zend-servicemanager": “~2.3", }, ! “require-dev": { “phpunit/phpunit": “~4” } Library Publisher Pick a Version
  56. 56. 3rd party library "require": { "zendframework/zend-stdlib": “2.1.*”, "zendframework/zend-servicemanager": "2.1.*", }, ! “require-dev": { * “phpunit/phpunit": “~3.7” } Your application "require": { "zendframework/zend-stdlib": “~2.3”, "zendframework/zend-servicemanager": “~2.3", }, ! “require-dev": { “phpunit/phpunit": “~4” } Library Publisher Pick a Version ~2.1
  57. 57. Composer for Library Consumers
  58. 58. install or update? Library Consumer Install or update?
  59. 59. Make sure you have installed the last updates from other developers. ? install or update Library Consumer Install or update?
  60. 60. Make sure you have installed the last updates from other developers. ? install or update Library Consumer Install or update?
  61. 61. Deploying a new release of your application to production. ? install or update Library Consumer Install or update?
  62. 62. Deploying a new release of your application to production. ? install or update Library Consumer Install or update?
  63. 63. Checked out a new project and want to start coding. ? install or update Library Consumer Install or update?
  64. 64. Checked out a new project and want to start coding. ? install or update Library Consumer Install or update?
  65. 65. Grab new versions for the dependencies of your project. ? install or update Library Consumer Install or update?
  66. 66. Grab new versions for the dependencies of your project. ? install or update Library Consumer Install or update?
  67. 67. Your application $ Public Repository # ! composer.lock composer install composer update Library Consumer Install or update?
  68. 68. Your application $ Public Repository # ! composer.lock read composer install composer update Library Consumer Install or update?
  69. 69. Your application $ read grab version Public Repository # ! composer.lock composer install composer update Library Consumer Install or update?
  70. 70. Your application $ read grab version Public Repository # ! composer.lock check latest compatible release composer install composer update Library Consumer Install or update?
  71. 71. Your application $ read grab version Public Repository # ! composer.lock check latest compatible release Library Consumer Install or update? update composer install composer update
  72. 72. commit your lock file Library Consumer Install or update?
  73. 73. Tip $ composer update --lock Library Consumer Install or update?
  74. 74. Pick the correct version Library Consumer Version Selection
  75. 75. dev-master Library Consumer Version Selection
  76. 76. Library Consumer Version Selection
  77. 77. Library Consumer Version Selection
  78. 78. found a bug? Library Consumer Using forks
  79. 79. Tip $ composer install --prefer-source Library Consumer Using forks
  80. 80. Library Consumer Using forks
  81. 81. patch it, Library Consumer Using forks
  82. 82. patch it, fork it, Library Consumer Using forks
  83. 83. patch it, fork it, push it… Library Consumer Using forks
  84. 84. patch it, fork it, push it… wait for it. Library Consumer Using forks
  85. 85. patch it, fork it, push it… wait for it. Library Consumer Using forks
  86. 86. symfony/symfony Library Consumer Using forks
  87. 87. symfony/symfony Library Consumer Using forks rdohms/symfony
  88. 88. symfony/symfony Library Consumer Using forks rdohms/symfony "repositories": [ { "type": "vcs", "url": "https://github.com/rdohms/symfony" } ]
  89. 89. symfony/symfony Library Consumer Using forks rdohms/symfony "repositories": [ { "type": "vcs", "url": "https://github.com/rdohms/symfony" } ] +
  90. 90. Tip $ composer show -v symfony/symfony Library Consumer Using forks
  91. 91. Do not put forked repositories on packagist , Library Consumer Using forks
  92. 92. Tip "require": { "symfony/symfony": "dev-my-patch as 2.5.0" } Library Consumer Using forks
  93. 93. Composer and production Library Consumer Composer and deployments
  94. 94. Packagist . Production Server - Library Consumer Composer and deployments
  95. 95. Packagist . / Man in the middle Production Server - Library Consumer Composer and deployments
  96. 96. Build Server 0 Library Consumer Composer and deployments Production Server - " Packagist . / Man in the middle
  97. 97. , $ composer install --prefer-dist --no-dev —optimize-autoloader Library Consumer Composer and deployments
  98. 98. , $ composer install --prefer-dist --no-dev —optimize-autoloader Library Consumer Composer and deployments
  99. 99. , $ composer install --prefer-dist --no-dev —optimize-autoloader 1 Install same versions 1 Uses information defined in the composer.lock file Library Consumer Composer and deployments
  100. 100. , $ composer install --prefer-dist --no-dev —optimize-autoloader Library Consumer Composer and deployments
  101. 101. , $ composer install --prefer-dist --no-dev —optimize-autoloader 1 Downloads distribution packages 1 Can use local cache for previously downloaded 1 No git required Library Consumer Composer and deployments
  102. 102. , $ composer install --prefer-dist --no-dev —optimize-autoloader Library Consumer Composer and deployments
  103. 103. , $ composer install --prefer-dist --no-dev —optimize-autoloader 1 Avoids download unnecessary developer libraries Library Consumer Composer and deployments
  104. 104. , $ composer install --prefer-dist --no-dev —optimize-autoloader Library Consumer Composer and deployments
  105. 105. , $ composer install --prefer-dist --no-dev —optimize-autoloader 1 Generates classmap from PSR-0/4 autoloaders 1 Speeds up autoloading Library Consumer Composer and deployments
  106. 106. Tip $ composer licenses ! Name: __root__ Version: 1.0.0 Licenses: none Dependencies: ! doctrine/annotations v1.2.1 MIT doctrine/cache v1.3.1 MIT doctrine/collections v1.2 MIT doctrine/common v2.4.2 MIT doctrine/inflector v1.0 MIT doctrine/lexer v1.0 MIT psr/log 1.0.0 MIT symfony/symfony v2.5.6 MIT twig/twig v1.16.2 BSD-3-Clause Library Consumer Licensing
  107. 107. Satis and Toran Library Consumer Private Packages and Proxy
  108. 108. composer Packagist " Your application $ Public Repository # Library Consumer Private Packages and Proxy
  109. 109. composer Packagist " Your application $ Public Repository # Satis / Toran " Private Repository 2 proxy Library Consumer Private Packages and Proxy
  110. 110. toranproxy.com private repos, automatic packagist proxy and support composer development Library Consumer Private Packages and Proxy
  111. 111. How many of you? $ composer require jquery/jquery Library Consumer Tooling
  112. 112. Library Consumer Tooling
  113. 113. Library Consumer Tooling
  114. 114. Javascript only Developer 3 my-js-library 4 Library Consumer Tooling
  115. 115. Javascript only Developer 3 my-js-library Library Consumer Tooling ! package.json 4
  116. 116. Javascript only Developer 3 my-js-library Library Consumer Tooling ! package.json ! bower.json 4
  117. 117. Javascript only Developer 3 my-js-library Library Consumer Tooling ! package.json ! bower.json ! composer.json 4
  118. 118. Javascript only Developer 3 my-js-library Library Consumer Tooling ! package.json ! bower.json ! composer.json ! .gemspec 4
  119. 119. Javascript only Developer 3 my-js-library Library Consumer Tooling ! package.json ! bower.json ! composer.json ! .gemspec 4 / /
  120. 120. Library Consumer Tooling
  121. 121. Right tool. Right job. Library Consumer Tooling
  122. 122. One last thing… Library Consumer One last thing
  123. 123. Library Consumer pickle!
  124. 124. $ pickle install memcache https://wiki.php.net/rfc/pickle https://github.com/FriendsOfPHP/pickle Library Consumer pickle!
  125. 125. The Composer Cookbook https://leanpub.com/composer-cookbook
  126. 126. https://joind.in/12995 Thank you.
  127. 127. https://joind.in/12995 Thank you. any questions? 7 @rdohms 6 http://doh.ms 5 http://slides.doh.ms

×