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

Comparing Composer

Comparing Composer

This talk I did for PHPBenelux meetup in February 2015, at MCS in Wilrijk, Belgium.

This talk compares composer with npm, bower, bundler, pip, berkshelf,… and their ecosystems of packages. Compared to these, composer is excelling with some pretty awesome features. I will focus on the great advantages of composer. Things like virtual packages, custom scripts, calling static methods straight from composer.json, the replaces keyword, … Stuff that most people don’t know about because they don’t always have to use it, but it could help them if they would know about it. At last I will tell about what the packagist ecosystem can learn from other ecosystems, and what package developers can do to further improve it to become a more healthy ecosystem.

https://joind.in/13680

39eb3f3d313b13f05534e496285040b8?s=128

Hannes Van De Vreken

February 24, 2015
Tweet

Transcript

  1. Comparing Composer Things you might not know about composer

  2. Hi, my name is Hannes.

  3. madewithlove

  4. MongoDB Belgium

  5. None
  6. • Developer • madewithlove • MongoDB Belgium • php.gent ABOUT

    ME
  7. Comparing composer

  8. 1. Dependency managers 2. Composer 3. Improve ecosystem

  9. 1. Dependency
 managers

  10. DEPENDENCY MANAGERS

  11. DEPENDENCY MANAGERS - PACKAGE.XML <dependencies> <required> <php> <min>5.1.0</min> <max>6.0.0</max> <exclude>6.0.0</exclude>

    </php> <pearinstaller> <min>1.4.0b1</min> …
  12. DEPENDENCY MANAGERS - PECL “platform requirements”

  13. DEPENDENCY MANAGERS apt

  14. DEPENDENCY MANAGERS - APT PACKAGES <mongodb.org/dist/binary-amd64/Packages> … Package: mongodb-org-server Version:

    2.6.7 Installed-Size: 23291 Depends: libc6 (>= 2.3.2), libgcc1 (>= 1:4.1 …
  15. DEPENDENCY MANAGERS - APT (Peer) Dependencies

  16. DEPENDENCY MANAGERS - APT The following packages have unmet dependencies:

    package1 : Depends: package2 (>= 1.8) but 1.7.5-1ubuntu1 is to be installed
  17. DEPENDENCY MANAGERS pip

  18. DEPENDENCY MANAGERS - PIP pip freeze > requirements.txt

  19. DEPENDENCY MANAGERS - PIP No dependency resolver

  20. DEPENDENCY MANAGERS Bundler

  21. DEPENDENCY MANAGERS - BUNDLER Gemfile Gemfile.lock

  22. DEPENDENCY MANAGERS - BUNDLER Dependency tree resolving

  23. DEPENDENCY MANAGERS - BUNDLER Separate Lock file

  24. DEPENDENCY MANAGERS npm

  25. DEPENDENCY MANAGERS - NPM node_modules/gulp/node_modules/…

  26. DEPENDENCY MANAGERS - NPM Hierarchical installation

  27. DEPENDENCY MANAGERS - NPM require.js

  28. DEPENDENCY MANAGERS - NPM No locking needed

  29. DEPENDENCY MANAGERS - NPM v3.0: only hierarchical when conflicts

  30. DEPENDENCY MANAGERS - RECAP Platform requirements Dependencies Resolving + Separate

    Lock files Hierarchical
  31. 2. Composer

  32. COMPOSER Too basic: Version constraints Semver(.org)

  33. COMPOSER --(no-)dev

  34. COMPOSER - DEV { "require-dev": {} "autoload-dev": {} }

  35. COMPOSER - DEV Not for my production Not for other

    people’s production
  36. COMPOSER - GLOBAL composer global require

  37. COMPOSER - SCRIPTS { "scripts": {…} }

  38. COMPOSER - SCRIPTS pre-install-cmd post-install-cmd pre-update-cmd post-update-cmd post-create-project-cmd

  39. COMPOSER - SCRIPTS php-cs-fixer src/ --level=symfony --fixers=short_array_syntax

  40. COMPOSER - SCRIPTS { "scripts": { "fix-cs": "php-cs-fixer src/ —

    } }
  41. COMPOSER - SCRIPTS { "scripts": { "fix-cs": "php-cs-fixer src/ —

    "misc": "MyClass::method" } }
  42. COMPOSER - SCRIPTS { "config": { "bin-dir": "vendor/bin" }, "scripts":

    {…} }
  43. COMPOSER Virtual packages

  44. None
  45. COMPOSER - VIRTUAL PACKAGES “Depend on abstractions”

  46. COMPOSER - VIRTUAL PACKAGES "require": "psr/log-implementation" "provide": "psr/log-implementation"

  47. COMPOSER - VIRTUAL PACKAGES "psr/cache-implementation" "psr/http-message"

  48. COMPOSER - VIRTUAL PACKAGES container-interop

  49. COMPOSER - VIRTUAL PACKAGES Would be useful streams store/repository event

    dispatcher
  50. COMPOSER More keywords: replace conflict suggest

  51. COMPOSER - REPLACE Replace subsplit packages: symfony/symfony zendframework/zendframework laravel/framework

  52. COMPOSER - CONFLICTS conflict means: “Do not install together with”

  53. COMPOSER - SUGGEST Suggest used for: PHP extensions (eg: for

    extra speed) Adapter packages
  54. COMPOSER - OTHER STUFF --prefer-lowest --ignore-platform-reqs --prefer-source --prefer-dist .gitattributes

  55. COMPOSER - RECAP dev scripts virtual packages subsplits conflict suggest

  56. 3. Improve ecosystem

  57. SemVer IMPROVE ECOSYSTEM - SEMVER

  58. None
  59. ~1.4: >=1.4.0 and < 2.0.0 ~1.4.3: >=1.4.3 and < 1.5.0

    ^1.4.3: >=1.4.3 and < 2.0.0 IMPROVE ECOSYSTEM - SEMVER
  60. If all packages - Use Semver - Correctly define version

    constraints IMPROVE ECOSYSTEM - SEMVER
  61. “Depend on abstractions” IMPROVE ECOSYSTEM - ABSTRACTIONS

  62. PSR interface packages Virtual packages IMPROVE ECOSYSTEM - ABSTRACTIONS

  63. Adapter packages IMPROVE ECOSYSTEM - ABSTRACTIONS

  64. Looking at Flysystem IMPROVE ECOSYSTEM - ABSTRACTIONS

  65. None
  66. None
  67. None
  68. Flysystem contains AdapterInterface IMPROVE ECOSYSTEM - ABSTRACTIONS

  69. class AwsS3Adapter implements AdapterInterface IMPROVE ECOSYSTEM - ABSTRACTIONS

  70. Flysystem Gaufrette Omnipay … IMPROVE ECOSYSTEM - ABSTRACTIONS

  71. “Depend on High level package, Let others decide the adapter”

    IMPROVE ECOSYSTEM - ABSTRACTIONS
  72. None
  73. http:/ /php-and-symfony.matthiasnoback.nl/2014/10/ composer-provide-and-dependency-inversion/ http:/ /php-and-symfony.matthiasnoback.nl/2014/04/ theres-no-such-thing-as-an-optional-dependency/ IMPROVE ECOSYSTEM - ABSTRACTIONS

  74. Follow Semver “Depend on abstractions” IMPROVE ECOSYSTEM - RECAP

  75. RECAP 1. Dependency managers 2. Composer 3. Improve ecosystem

  76. None
  77. Questions?

  78. Thank you! https:/ /joind.in/13680 @hannesvdvreken

  79. • http:/ /mwl.be • http:/ /getcomposer.org/doc • http:/ /slides.seld.be/?file=2015-02-19+Composer+... •

    https:/ /hannesvdvreken.com/2015/01/14/gitattr... • https:/ /hannesvdvreken.com/2015/01/18/comp... • https:/ /hannesvdvreken.com/2015/01/28/autol... • https:/ /packagist.org/search/?q=psr%2Flog • https:/ /leanpub.com/principles-of-package-design • http:/ /php-and-symfony.matthiasnoback.nl/2014/... • http:/ /php-and-symfony.matthiasnoback.nl/2014/... REFERENCES