Mastering composer

9,970 views
9,559 views

Published on

0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
9,970
On SlideShare
0
From Embeds
0
Number of Embeds
37
Actions
Shares
0
Downloads
22
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Mastering composer

  1. 1. Mastering Composer Adán Lobato
  2. 2. What’s up! • Soy Adán Lobato • Soy de Barcelona • Soy software developer • Backend Developer en SocialPoint • Mi twitter es @adanlobato
  3. 3. Agenda • Minimum stability • Branch aliases • Semantic versioning • Private Repositories • Installers • Embedded Composer • Useful links
  4. 4. Parental Advisory
  5. 5. Minimum stability
  6. 6. Minimum stability, the problem
  7. 7. Minimum stability exposed Stable! RC “minimum-stability”: Beta Alpha Dev @stable @rc @beta @alpha @dev
  8. 8. minimum-stability, the global solution { "require": { "php": ">=5.3.3", "symfony/icu": "~1.0", "doctrine/common": "~2.2", "twig/twig": "~1.11", "psr/log": "~1.0" }, “minimum-stability”: “dev” }
  9. 9. @stability flags, the specific solution { "require": { "php": ">=5.3.3", "symfony/icu": "~1.0", "doctrine/common": “~2.2@dev", "twig/twig": "~1.11", "psr/log": "~1.0" } }
  10. 10. @stability flags, recursive stability { "require": { "php": ">=5.3.3", "symfony/icu": "~1.0", "doctrine/orm": “~2.2", "doctrine/dbal": “@dev", "twig/twig": "~1.11", "psr/log": "~1.0" } }
  11. 11. prefer-stable, the “magic” solution { "require": { "php": ">=5.3.3", "symfony/icu": "~1.0", "doctrine/common": "~2.2", "twig/twig": "~1.11", "psr/log": "~1.0" }, “prefer-stable”: true }
  12. 12. Branch aliases
  13. 13. Branch aliases, the problem
  14. 14. Branch aliases, the bad practice { "require": { “welovephp/foobar”: “dev-master” } }
  15. 15. Branch aliases, the solution { “name”: “welovephp/foobar” "extra": { "branch-alias": { "dev-master": "2.5-dev" } } }
  16. 16. Branch aliases & stability flags { "require": { “welovephp/foobar”: “2.5.*@dev” } }
  17. 17. Branch aliases, inline aliases { "require": { “welovephp/foobar”: “my-branch as 2.5-dev” } }
  18. 18. Semantic Versioning
  19. 19. Semantic versioning X.Y.Z
  20. 20. Semantic versioning X.Y.Z
  21. 21. Semantic versioning X.Y.Z
  22. 22. Semantic versioning X.Y.Z
  23. 23. Semantic versioning 1.*
  24. 24. Semantic versioning >=1.1,<2.0
  25. 25. Semantic versioning ~1.1
  26. 26. Private Repositories
  27. 27. Private Repositories, the basics { “repositories”: [ { “type”: “git”, “url”: “git@github.com/welovephp/foobar.git” } ] }
  28. 28. Private Repositories, the basics { “repositories”: [ { “type”: “git”, “url”: “git@github.com/welovephp/foobar.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/foobar-bundle.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/fizz.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/buzz.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/fizzbuzz-bundle.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/qwerty.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/doe.git” } ] }
  29. 29. Private Repositories, the basics
  30. 30. Private Repositories, the basics
  31. 31. Private Repositories: Satis
  32. 32. Private Repositories, Satis $ composer create-project composer/satis
  33. 33. Private Repositories, Satis // config.json { "name": "WelovePhp", "homepage": "http://packages.welovephp.es", "require-all": true, “repositories”: [ { “type”: “git”, “url”: “git@github.com/welovephp/foobar.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/foobar-bundle.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/fizz.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/buzz.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/fizzbuzz-bundle.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/qwerty.git” } ] }
  34. 34. Private Repositories, Satis $ php bin/satis build config.json web/
  35. 35. Private Repositories, Satis
  36. 36. Private Repositories, Satis { "repositories": [ { "type": "composer", "url": “http://packages.welovephp.es/“ } ] }
  37. 37. Private Repositories, Satis Security: • Basic HTTP Authentication • SSH • Private network ! Updates • CRON job
  38. 38. Private Repositories: Packagist
  39. 39. Private Repositories, Packagist • Packagist is an Open Source project • It is built as a Symfony application • You can have your own private Packagist • Supports Github Webhooks
  40. 40. Private Repositories, Packagist Requirements: • MySQL • Redis • Solr • git / svn / hg
  41. 41. Private Repositories: Bottlenecks
  42. 42. Private Repositories, the bottlenecks
  43. 43. Installers
  44. 44. Installers, the official ones • Wordpress • Drupal • CakePHP • CodeIgniter • Laravel • Tons more! http://github.com/composer/installers
  45. 45. Installers, building your own installer { "name": "welovephp/blog-module", "type": “welovephp-module", "require": { “welovephp/module-installer-plugin“: "*" } }
  46. 46. Installers, building your own installer { "name": “welovephp/module-installer-plugin", "type": "composer-plugin", "autoload": { "psr-0": {"WeLovePhpComposer": "src/"} }, "extra": { "class": "WeLovePhpComposerModuleInstallerPlugin" }, "require": { "composer-plugin-api": “1.0.0" } }
  47. 47. Installers, building your own installer namespace WeLovePhpComposer; class ModuleInstallerPlugin implements PluginInterface { public function activate(Composer $composer, IOInterface $io) { $installer = new ModuleInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($installer); } }
  48. 48. Installers, building your own installer namespace phpDocumentorComposer; ! class ModuleInstaller extends LibraryInstaller { public function getPackageBasePath(PackageInterface $package) { return 'welovephp/modules/'.$package->getPrettyName(); } ! public function supports($packageType) { return ‘welovephp-module' === $packageType; } }
  49. 49. Embedded Composer By Beau Simensen
  50. 50. Embedded Composer, the problem • You have an application • Your application has dependencies • Your application can be extended via third-party plugins • Those plugins depend on your app, but can have other extra dependencies • Both, app & plugins dependencies, must be installed once and be compatible between them
  51. 51. Embedded Composer, the solution We need to be able to run Composer on runtime
  52. 52. Embedded Composer & Sculpin.io
  53. 53. Commands you must know
  54. 54. diagnose $ composer diagnose Checks common errors to help debugging problems.
  55. 55. —verbose $ composer command […] -v|vv|vvv Increase output verbosity. Useful for debugging.
  56. 56. config —global $ composer config —global […] Read/Write Composer global settings.
  57. 57. global $ composer global require phpunit/phpunit Add COMPOSER_HOME/vendor/bin to PATH ! Run Composer operations globally. Useful for CLI tools.
  58. 58. status $ composer status Displays a list of dependencies that have been modified locally.
  59. 59. show $ composer show package/name Displays detailed information about a package.
  60. 60. dump-autoload —optimize $ composer dump-autoload — optimize Dumps a classmap for PSR-0 vendors.
  61. 61. Useful links
  62. 62. Useful links Composer • http://getcomposer.org/doc/ • https://github.com/composer/composer • https://packagist.org/ • #composerphp at twitter ! Composer Basics • http://www.slideshare.net/adanlobato/composer-gestor-de-dependencias-para-php • http://www.youtube.com/watch?v=U1dTiDlUUmU • http://adanlobato.github.io/composer-2013
  63. 63. Useful links Minimum stability • http://getcomposer.org/doc/04-schema.md#minimum-stability • http://getcomposer.org/doc/04-schema.md#package-links • https://igor.io/2013/02/07/composer-stability-flags.html ! Branch alias • http://getcomposer.org/doc/articles/aliases.md • https://igor.io/2013/01/07/composer-versioning.html ! Semantic versioning • http://semver.org/
  64. 64. Useful links Private Repositories • https://github.com/composer/satis • https://github.com/composer/packagist • https://help.github.com/articles/post-receive-hooks ! Installers • http://getcomposer.org/doc/articles/custom-installers.md • https://github.com/composer/installers !
  65. 65. Useful links Embedded Composer • https://speakerdeck.com/simensen/embedded-composer-sflive-portland-2013 • https://github.com/dflydev/dflydev-embedded-composer • https://github.com/sculpin !
  66. 66. That’s all folks! Questions?

×