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

Composer

 Composer

Dependency Management for PHP

Matthew Loberg

May 14, 2013
Tweet

More Decks by Matthew Loberg

Other Decks in Programming

Transcript

  1. W%&' I( C!"p#$r a dependency management system C!"p#$r )(: C!"p#$r

    )( *!': a package manager (it doesn’t install anything globally)
  2. U()*, C!"p#$r composer.json - dependencies - development dependencies - config

    - metadata composer.lock - locks versions of dependencies
  3. U()*, C!"p#$r composer.json - dependencies - development dependencies - config

    - metadata composer.lock - locks versions of dependencies - run the same version everywhere
  4. .!"p#$r./(!* dependencies uses “require” key version exact: 1.0.3 range: >,

    >=, <, <=, != (>=1.0,<2.0) wildcard: 2.0.* next major release: ~1.4
  5. .!"p#$r./(!* development dependencies dependencies needed in development example: phpunit uses

    “require-dev” key { “require-dev”: { “phpunit/phpunit”: “3.7.*” } }
  6. U()*, D$p$*1$*.)$( include autoloader require ‘vendor/autoload.php’; use packages $log =

    new Monolog\Logger(‘name’); $handler = new Monolog\Handler\StreamHandler(‘app.log’, ... $log->pushHandler($handler); $log->addWarning(‘Foo’);
  7. S)1$b&r: PSR-0 namespaces match path and filename example: \Acme\Foo\Bar ->

    src/Acme/Foo/Bar.php <?php namespace Acme\Foo; class Bar { ...
  8. U()*, 4$ A3'!+!&1$r isn’t just for composer packages can load

    PSR-0 compatible code { “autoload”: { “psr-0”: { “Acme”: “src/” } } }
  9. U()*, 4$ A3'!+!&1$r isn’t just for composer packages can load

    PSR-0 compatible code can also load code that doesn’t follow PSR-0
  10. U()*, 4$ A3'!+!&1$r isn’t just for composer packages can load

    PSR-0 compatible code can also load code that doesn’t follow PSR-0 { “autoload”: { “classmap”: [“src/”, “lib/”] } }
  11. U()*, 4$ A3'!+!&1$r isn’t just for composer packages can load

    PSR-0 compatible code can also load code that doesn’t follow PSR-0 or individual files (functions file)
  12. U()*, 4$ A3'!+!&1$r isn’t just for composer packages can load

    PSR-0 compatible code can also load code that doesn’t follow PSR-0 or individual files (functions file) { “autoload”: { “files”: [“src/functions.php”] } }
  13. Cr$&')*, A P&.2&,$ your application is a package not installable

    by others without metadata { “name”: “vendor/name” } needs a name
  14. Cr$&')*, A P&.2&,$ your application is a package not installable

    by others without metadata version defined in one of three places needs a name
  15. Cr$&')*, A P&.2&,$ your application is a package not installable

    by others without metadata version defined in one of three places - composer.json (“version” tag) needs a name
  16. Cr$&')*, A P&.2&,$ your application is a package not installable

    by others without metadata { “version”: “1.0.0” } version defined in one of three places - composer.json (“version” tag) needs a name
  17. Cr$&')*, A P&.2&,$ your application is a package not installable

    by others without metadata version defined in one of three places - composer.json (“version” tag) - VCS tag needs a name
  18. Cr$&')*, A P&.2&,$ your application is a package not installable

    by others without metadata version defined in one of three places - composer.json (“version” tag) - VCS tag - 1.0.0 - v1.0.0 - 1.5.0-RC1 - v1.5.0-beta2 needs a name
  19. Cr$&')*, A P&.2&,$ your application is a package not installable

    by others without metadata version defined in one of three places - composer.json (“version” tag) - VCS tag - VCS branch needs a name
  20. Cr$&')*, A P&.2&,$ your application is a package not installable

    by others without metadata version defined in one of three places - composer.json (“version” tag) - VCS tag - VCS branch - {branchname}-dev (2.0 -> 2.0.x-dev) - dev-{branchname} (dev-master) needs a name
  21. Cr$&')*, A P&.2&,$ O'%$r M$'&1&'&: - description - type (library,

    project, etc) - keywords (searching on Packagist)
  22. Cr$&')*, A P&.2&,$ O'%$r M$'&1&'&: - description - type (library,

    project, etc) - keywords (searching on Packagist) - homepage
  23. Cr$&')*, A P&.2&,$ O'%$r M$'&1&'&: - description - type (library,

    project, etc) - keywords (searching on Packagist) - homepage - license
  24. Cr$&')*, A P&.2&,$ O'%$r M$'&1&'&: - description - type (library,

    project, etc) - keywords (searching on Packagist) - homepage - license - authors
  25. Cr$&')*, A P&.2&,$ O'%$r M$'&1&'&: - description - type (library,

    project, etc) - keywords (searching on Packagist) - homepage - license - authors - more at http:/ /getcomposer.org/doc/04-schema.md
  26. U()*, C3('!" P&.2&,$( define repository in composer.json { “repositories”: [

    { “type”: “vcs”, “url”: “repository-url” } ] }
  27. U()*, C3('!" P&.2&,$( define repository in composer.json { “require”: {

    “vendor/name”: “dev-master” } } require package
  28. A1v&*.$ C!"p#$r include binaries in composer B)*&r)$( installs in vendor/bin

    S.r)p'( called during composer events php callback or binary
  29. A1v&*.$ C!"p#$r include binaries in composer B)*&r)$( installs in vendor/bin

    S.r)p'( called during composer events php callback or binary http:/ /getcomposer.org/doc/articles/scripts.md