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

Hannes Van De Vreken

February 24, 2015
Tweet

More Decks by Hannes Van De Vreken

Other Decks in Programming

Transcript

  1. Comparing Composer
    Things you might not know about
    composer

    View full-size slide

  2. Hi, my name is Hannes.

    View full-size slide

  3. madewithlove

    View full-size slide

  4. MongoDB Belgium

    View full-size slide

  5. • Developer
    • madewithlove
    • MongoDB Belgium
    • php.gent
    ABOUT ME

    View full-size slide

  6. Comparing composer

    View full-size slide

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

    View full-size slide

  8. 1. Dependency

    managers

    View full-size slide

  9. DEPENDENCY MANAGERS

    View full-size slide

  10. DEPENDENCY MANAGERS - PACKAGE.XML



    5.1.0
    6.0.0
    6.0.0


    1.4.0b1

    View full-size slide

  11. DEPENDENCY MANAGERS - PECL
    “platform requirements”

    View full-size slide

  12. DEPENDENCY MANAGERS
    apt

    View full-size slide

  13. DEPENDENCY MANAGERS - APT PACKAGES


    Package: mongodb-org-server
    Version: 2.6.7
    Installed-Size: 23291
    Depends: libc6 (>= 2.3.2), libgcc1 (>= 1:4.1

    View full-size slide

  14. DEPENDENCY MANAGERS - APT
    (Peer) Dependencies

    View full-size slide

  15. DEPENDENCY MANAGERS - APT
    The following packages have
    unmet dependencies:
    package1 : Depends: package2 (>= 1.8)
    but 1.7.5-1ubuntu1 is to be installed

    View full-size slide

  16. DEPENDENCY MANAGERS
    pip

    View full-size slide

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

    View full-size slide

  18. DEPENDENCY MANAGERS - PIP
    No dependency resolver

    View full-size slide

  19. DEPENDENCY MANAGERS
    Bundler

    View full-size slide

  20. DEPENDENCY MANAGERS - BUNDLER
    Gemfile
    Gemfile.lock

    View full-size slide

  21. DEPENDENCY MANAGERS - BUNDLER
    Dependency tree resolving

    View full-size slide

  22. DEPENDENCY MANAGERS - BUNDLER
    Separate Lock file

    View full-size slide

  23. DEPENDENCY MANAGERS
    npm

    View full-size slide

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

    View full-size slide

  25. DEPENDENCY MANAGERS - NPM
    Hierarchical installation

    View full-size slide

  26. DEPENDENCY MANAGERS - NPM
    require.js

    View full-size slide

  27. DEPENDENCY MANAGERS - NPM
    No locking needed

    View full-size slide

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

    View full-size slide

  29. DEPENDENCY MANAGERS - RECAP
    Platform requirements
    Dependencies
    Resolving + Separate Lock files
    Hierarchical

    View full-size slide

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

    View full-size slide

  31. COMPOSER
    --(no-)dev

    View full-size slide

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

    View full-size slide

  33. COMPOSER - DEV
    Not for my production
    Not for other people’s production

    View full-size slide

  34. COMPOSER - GLOBAL
    composer global require

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  39. COMPOSER - SCRIPTS
    {
    "scripts": {
    "fix-cs": "php-cs-fixer src/ —
    "misc": "MyClass::method"
    }
    }

    View full-size slide

  40. COMPOSER - SCRIPTS
    {
    "config": {
    "bin-dir": "vendor/bin"
    },
    "scripts": {…}
    }

    View full-size slide

  41. COMPOSER
    Virtual packages

    View full-size slide

  42. COMPOSER - VIRTUAL PACKAGES
    “Depend on abstractions”

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  45. COMPOSER - VIRTUAL PACKAGES
    container-interop

    View full-size slide

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

    View full-size slide

  47. COMPOSER
    More keywords:
    replace
    conflict
    suggest

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  50. COMPOSER - SUGGEST
    Suggest used for:
    PHP extensions (eg: for extra speed)
    Adapter packages

    View full-size slide

  51. COMPOSER - OTHER STUFF
    --prefer-lowest
    --ignore-platform-reqs
    --prefer-source
    --prefer-dist
    .gitattributes

    View full-size slide

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

    View full-size slide

  53. 3. Improve ecosystem

    View full-size slide

  54. SemVer
    IMPROVE ECOSYSTEM - SEMVER

    View full-size slide

  55. ~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

    View full-size slide

  56. If all packages
    - Use Semver
    - Correctly define version constraints
    IMPROVE ECOSYSTEM - SEMVER

    View full-size slide

  57. “Depend on abstractions”
    IMPROVE ECOSYSTEM - ABSTRACTIONS

    View full-size slide

  58. PSR interface packages
    Virtual packages
    IMPROVE ECOSYSTEM - ABSTRACTIONS

    View full-size slide

  59. Adapter packages
    IMPROVE ECOSYSTEM - ABSTRACTIONS

    View full-size slide

  60. Looking at Flysystem
    IMPROVE ECOSYSTEM - ABSTRACTIONS

    View full-size slide

  61. Flysystem contains AdapterInterface
    IMPROVE ECOSYSTEM - ABSTRACTIONS

    View full-size slide

  62. class AwsS3Adapter
    implements AdapterInterface
    IMPROVE ECOSYSTEM - ABSTRACTIONS

    View full-size slide

  63. Flysystem
    Gaufrette
    Omnipay

    IMPROVE ECOSYSTEM - ABSTRACTIONS

    View full-size slide

  64. “Depend on High level package,
    Let others decide the adapter”
    IMPROVE ECOSYSTEM - ABSTRACTIONS

    View full-size slide

  65. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  69. • 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

    View full-size slide