Rafael Dohms / @rdohmsC!"p#$r   Putting your dependencies on the score
Rafael Dohms                           photo credit: Eli White        @rdohms Evangelist, Speaker and      Contributor.Dev...
%$ E&$v(!r P)(*+     a general introduction to Composer     Ev$r,-, *!"p#)./      the basic stuff you need to know  Up/r-)...
%$ E&$v(!r P)(*+
per project          system widecentral repository   spread out channelsopen acceptance        strict standards
Pr!b&$":I need my team and my deployments to use consistent      versions of the dependencies of my project
Pr!b&$":I need my team and my deployments to use consistent      versions of the dependencies of my projectS!&2()!.:
Pr!b&$":I need my team and my deployments to use consistent      versions of the dependencies of my projectS!&2()!.:      ...
Pr!b&$":I need my team and my deployments to use consistent      versions of the dependencies of my projectS!&2()!.:      ...
Pr!b&$":I need my team and my deployments to use consistent      versions of the dependencies of my projectS!&2()!.:      ...
Pr!b&$":I need my team and my deployments to use consistent      versions of the dependencies of my projectS!&2()!.:      ...
Pr!b&$":I need my team and my deployments to use consistent      versions of the dependencies of my projectS!&2()!.:      ...
A per-project dependency  manager that allows you to  declare a consistent list ofdependencies and versions for your appli...
Ev$r,-, C!"p#)./
I.0(&&)./ C!"p#$rLocal (embed)$ curl -s http://getcomposer.org/installer | phpGlobal$ curl -s http://getcomposer.org/insta...
I.0(&&)./ C!"p#$rLocal (embed)$ curl -s http://getcomposer.org/installer | phpGlobal$ curl -s http://getcomposer.org/insta...
I.0(&&)./ C!"p#$r
I.0(&&)./ C!"p#$r  $ composer.phar --version  Composer version 6573fd3
I.0(&&)./ C!"p#$r     php  $ composer.phar --version  Composer version 6573fd3
K$$p )( 2p-($-!
K$$p )( 2p-($-!$ composer.phar self-updateUpdating to version 65e95ed.    Downloading: 100%
C!"p#$r 101
C!"p#$r 101$ cd ~/dev/myproject
C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json    {        "require": {            "silex/silex": "1.0.*"        },   ...
C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json     note: project root    {        "require": {            "silex/silex...
C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json     note: project root                                      “require”: ...
C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json     note: project root                                      “require”: ...
C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json        note: project root                                         “requ...
Installing dependencies  - Installing pimple/pimple (dev-master)    Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be  - In...
Installing dependencies  - Installing pimple/pimple (dev-master)                  your    Cloning d2cfa2f02f50abef65c23874...
Installing dependencies  - Installing pimple/pimple (dev-master)                  your    Cloning d2cfa2f02f50abef65c23874...
Installing dependencies  - Installing pimple/pimple (dev-master)                  your    Cloning d2cfa2f02f50abef65c23874...
P)*42p (+$ ($"p!!Let Composer bootstrap you development
B!!(0(rpp)./ Pr!5$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myproject
B!!(0(rpp)./ Pr!5$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myprojectInstalling fabpot/silex-skeleton ...
B!!(0(rpp)./ Pr!5$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myprojectInstalling fabpot/silex-skeleton ...
I w.( (! *!.(r)b2($  pr!5$*(  Composer can set that up for you.
B!!(0(rpp)./ C!.(r)b2()!.0$ composer.phar create-project dms/dms --dev ~/dev/oss/dms
B!!(0(rpp)./ C!.(r)b2()!.0                                        gimme dev packages$ composer.phar create-project dms/dms...
B!!(0(rpp)./ C!.(r)b2()!.0                                        gimme dev packages$ composer.phar create-project dms/dms...
B!!(0(rpp)./ C!.(r)b2()!.0                                                  gimme dev packages$ composer.phar create-proje...
H!w -! I 6.-/&!- (+$ 6&$0?  PSR-0 and the modern autoloader
Composer generates anautoload file for all your     dependencies
Composer generates anautoload file for all your     dependencies   vendor/autoload.php
"autoload": {    "psr-0": { "MyNamespace": "<root>" },     "classmap": ["src/", "lib/", "Something.php"],     "files": ["s...
“autoload”: describes the autoloading needed for                        your library"autoload": {    "psr-0": { "MyNamespa...
“autoload”: describes the autoloading needed for                        your library"autoload": {    "psr-0": { "MyNamespa...
“autoload”: describes the autoloading needed for                        your library"autoload": {    "psr-0": { "MyNamespa...
“autoload”: describes the autoloading needed for                        your library"autoload": {    "psr-0": { "MyNamespa...
I.0(&&)./, 2p-()./ .- "!v)./ !.  how does Composer guarantee consistency
composer.json
“composer.json”: metadata and    list of your dependencies.composer.json
“composer.json”: metadata and    list of your dependencies.composer.jsoncomposer.lock
“composer.json”: metadata and    list of your dependencies.composer.jsoncomposer.lock    “composer.lock”: existing    depe...
composer.jsoncomposer.lock
update         composer.json         composer.lock
update                   install         composer.json         composer.lock
update                           install         reads                 composer.json                 composer.lock
update                             install         reads                   composer.json                   composer.lock  ...
update                                    install         reads                          composer.json                 wri...
update                                       install         reads                            reads                       ...
update                                         install         reads                             reads                    ...
update                                              install         reads                                  reads          ...
D$v$&!p)./ . App ).  ($"? Commit you composer.lock file  into the repository, and use        composer install.
D$v$&!p)./ . App ).  ($"? Commit you composer.lock file  into the repository, and use        composer install.            ...
I’" -$v$&!p)./  &)brr,, +$&p!here are some fields you should care about
{    "name": "vendor-namespace/package-name",    "type": "symfony-bundle",    "description": "A sample package for example...
“name”: this should be unique, pick a good one!{    "name": "vendor-namespace/package-name",    "type": "symfony-bundle", ...
“name”: this should be unique, pick a good one!{    "name": "vendor-namespace/package-name",                              ...
“name”: this should be unique, pick a good one!{    "name": "vendor-namespace/package-name",                              ...
“name”: this should be unique, pick a good one!{    "name": "vendor-namespace/package-name",                              ...
“name”: this should be unique, pick a good one!{    "name": "vendor-namespace/package-name",                              ...
M, *!-$ )0 PHP 5.4 !.&,! managing system dependencies
{    "require": {        "php": ">=5.3.3",        "ext-ldap": "*"    }}
{                    “php”: PHP version.    "require": {        "php": ">=5.3.3",        "ext-ldap": "*"    }}
{                     “php”: PHP version.    "require": {        "php": ">=5.3.3",        "ext-ldap": "*"    }            ...
Up/r-)./ (!  M$0(r!
B2( I .$$-  0p$*)6* v$r0)!.  version modifiers to the rescue!
"acme/foo": "1.0.x-dev#3ebbe75"
“#<ref>”: Get this specific               commit"acme/foo": "1.0.x-dev#3ebbe75"
“#<ref>”: Get this specific               commit"acme/foo": "1.0.x-dev#3ebbe75"      "acme/foo": "@dev"   "acme/foo": "1.0...
“#<ref>”: Get this specific               commit"acme/foo": "1.0.x-dev#3ebbe75"      "acme/foo": "@dev"   "acme/foo": "1.0...
I .$$- (! 7$*2($  f$w 0*r)p(0 how to automate tasks with Composer
    "scripts": {        "post-install-cmd": [            "SensioBundleDistributionBundleComposerScriptHandler::buildBootst...
“scripts”: allows you to run scripts at given moments    "scripts": {        "post-install-cmd": [            "SensioBundl...
C20(!" R$p#)(!r)$0 !r .! C!"p#$r, w+( .!w?Injecting Composer into wild packages
“hero/superpackage”: “dev-master”
“hero/superpackage”: “dev-master”
“hero/superpackage”: “dev-master”
“hero/superpackage”: “dev-master”
“hero/superpackage”: “dev-master”    "repositories": [        {            "type": "vcs",            "url": "https://githu...
“hero/superpackage”: “dev-master”         “repositories”: point to non-indexed, override existing or on-                  ...
N!.-C!"p#$r P*4/${    "repositories": [        {            "type": "package",            "package": {                "nam...
N!.-C!"p#$r P*4/${    "repositories": [                     “package”: on-the-fly package, injecting a        {           ...
N!.-C!"p#$r P*4/${    "repositories": [                     “package”: on-the-fly package, injecting a        {           ...
I .$$- (+)0 PEAR p*4/$...         No Problem!
{    "repositories": [        {            "type": "pear",            "url": "http://pear2.php.net"        }    ],    "req...
{                        “pear”: official PEAR and custom PEAR    "repositories": [                                       ...
{                        “pear”: official PEAR and custom PEAR    "repositories": [                                       ...
{                        “pear”: official PEAR and custom PEAR    "repositories": [                                       ...
aliasreplace   provide
alias{    "extra": {        "branch-alias": {            "dev-master": "1.0.x-dev"        }    },    "require": {        "...
alias{    "extra": {        "branch-alias": {            "dev-master": "1.0.x-dev"        }    },    "require": {        "...
alias{    "extra": {        "branch-alias": {            "dev-master": "1.0.x-dev"        }    },    "require": {        "...
1.-)./ ,!2r (2.$
I .$$-  &)brr, (+( -!$0..     Let me get that for you
http://packagist.org/
usage info                        package infoversions
$ composer.phar search filter
$ composer.phar search filterdms/dms-filter-bundle             : DMS Filter Bundle, makes Annotation based ...lexik/form-f...
$ composer.phar show dms/dms-filter-bundle
$ composer.phar show dms/dms-filter-bundlename     : dms/dms-filter-bundledescrip. : DMS Filter Bundle, makes Annotation b...
B2( ", r$p#)(!r, )0 pr)v($!  Get your own package repository
S()0!
R!&&!2( ,!2r !w. S()0$ composer.phar create-project composer/satis
R!&&!2( ,!2r !w. S()0$ composer.phar create-project composer/satis$ vi packages.json  {      "name": "My Repository",     ...
R!&&!2( ,!2r !w. S()0$ composer.phar create-project composer/satis$ vi packages.json  {      "name": "My Repository",     ...
U0)./ ,!2r !w. S()0{    "repositories": [        {            "type": "composer",            "url": "http://packages.yourd...
U0)./ ,!2r !w. S()0{    "repositories": [     “composer”: use this just like it was Packagist        {            "type": ...
W+$r$ 0+!2&- I /$( +$&p?    http://getcomposer.org #composer on irc.freenode.org
%$ E&$v(!r P)(*+     Dependency Manager, consistent versions, per-project               Ev$r,-, *!"p#)./               ins...
%.4 ,!2!                  https://joind.in/7051@rdohmshttp://doh.mshttp://slides.doh.ms
Composer, putting dependencies on the score
Composer, putting dependencies on the score
Upcoming SlideShare
Loading in...5
×

Composer, putting dependencies on the score

10,764

Published on

As PHP projects grow and mature so does their list of dependencies and third party code. Managing all these external packages during development and especially deploy is not an easy task and can be very error prone. Enter Composer, a tool that allows you to keep a consistent list of dependencies and versions across your whole team and all your environments, managing and making discovery of new libraries a breeze. Let's see how Composer can solve all your problems with a simple command line interface and a json configuration file.

Published in: Technology, Spiritual

Composer, putting dependencies on the score

  1. 1. Rafael Dohms / @rdohmsC!"p#$r Putting your dependencies on the score
  2. 2. Rafael Dohms photo credit: Eli White @rdohms Evangelist, Speaker and Contributor.Developer at WEBclusive.Enabler at AmsterdamPHP.
  3. 3. %$ E&$v(!r P)(*+ a general introduction to Composer Ev$r,-, *!"p#)./ the basic stuff you need to know Up/r-)./ (! M$0(r!advanced features for more complex scenarios 1.-)./ ,!2r (2.$ discovering and sharing libraries
  4. 4. %$ E&$v(!r P)(*+
  5. 5. per project system widecentral repository spread out channelsopen acceptance strict standards
  6. 6. Pr!b&$":I need my team and my deployments to use consistent versions of the dependencies of my project
  7. 7. Pr!b&$":I need my team and my deployments to use consistent versions of the dependencies of my projectS!&2()!.:
  8. 8. Pr!b&$":I need my team and my deployments to use consistent versions of the dependencies of my projectS!&2()!.: PEAR
  9. 9. Pr!b&$":I need my team and my deployments to use consistent versions of the dependencies of my projectS!&2()!.: PEAR SVN Externals
  10. 10. Pr!b&$":I need my team and my deployments to use consistent versions of the dependencies of my projectS!&2()!.: PEAR SVN Externals Git Submodules
  11. 11. Pr!b&$":I need my team and my deployments to use consistent versions of the dependencies of my projectS!&2()!.: PEAR SVN Externals Git Submodules vendor management script
  12. 12. Pr!b&$":I need my team and my deployments to use consistent versions of the dependencies of my projectS!&2()!.: PEAR SVN Externals Git Submodules vendor management script C!"p#$r!
  13. 13. A per-project dependency manager that allows you to declare a consistent list ofdependencies and versions for your application, as well as aconsistent way of sharing your libraries and making them discoverable using packagist.org
  14. 14. Ev$r,-, C!"p#)./
  15. 15. I.0(&&)./ C!"p#$rLocal (embed)$ curl -s http://getcomposer.org/installer | phpGlobal$ curl -s http://getcomposer.org/installer | php -- --install-dir=bin
  16. 16. I.0(&&)./ C!"p#$rLocal (embed)$ curl -s http://getcomposer.org/installer | phpGlobal$ curl -s http://getcomposer.org/installer | php -- --install-dir=bin 3p: $ ln -s /usr/bin/composer.phar /usr/bin/composer
  17. 17. I.0(&&)./ C!"p#$r
  18. 18. I.0(&&)./ C!"p#$r $ composer.phar --version Composer version 6573fd3
  19. 19. I.0(&&)./ C!"p#$r php $ composer.phar --version Composer version 6573fd3
  20. 20. K$$p )( 2p-($-!
  21. 21. K$$p )( 2p-($-!$ composer.phar self-updateUpdating to version 65e95ed. Downloading: 100%
  22. 22. C!"p#$r 101
  23. 23. C!"p#$r 101$ cd ~/dev/myproject
  24. 24. C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json { "require": { "silex/silex": "1.0.*" }, "minimum-stability": "dev" }
  25. 25. C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json note: project root { "require": { "silex/silex": "1.0.*" }, "minimum-stability": "dev" }
  26. 26. C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json note: project root “require”: required packages and { versions "require": { "silex/silex": "1.0.*" adv. ex.: >=1.0.0,<1.2-dev }, "minimum-stability": "dev" }
  27. 27. C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json note: project root “require”: required packages and { versions "require": { "silex/silex": "1.0.*" adv. ex.: >=1.0.0,<1.2-dev }, "minimum-stability": "dev" “minimum-stability”: if you only } want stable packages default: stable
  28. 28. C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json note: project root “require”: required packages and { versions "require": { "silex/silex": "1.0.*" adv. ex.: >=1.0.0,<1.2-dev }, "minimum-stability": "dev" “minimum-stability”: if you only } want stable packages default: stable$ composer.phar install
  29. 29. Installing dependencies - Installing pimple/pimple (dev-master) Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be - Installing symfony/routing (dev-master) Cloning 6bca82c3ea0d42d750de4f49b22020dfd047dc0f [...] - Installing silex/silex (dev-master) Cloning 18e248a277adb061602d2bcabe96011db1c76ec0symfony/routing suggests installing symfony/config (dev-master)symfony/routing suggests installing symfony/yaml (dev-master)symfony/routing suggests installing doctrine/common (>=2.2,<2.3)[...]silex/silex suggests installing symfony/browser-kit (2.1.*)silex/silex suggests installing symfony/css-selector (2.1.*)silex/silex suggests installing symfony/dom-crawler (2.1.*)Writing lock fileGenerating autoload files
  30. 30. Installing dependencies - Installing pimple/pimple (dev-master) your Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be dependency’s - Installing symfony/routing (dev-master) dependencies Cloning 6bca82c3ea0d42d750de4f49b22020dfd047dc0f [...] - Installing silex/silex (dev-master) Cloning 18e248a277adb061602d2bcabe96011db1c76ec0symfony/routing suggests installing symfony/config (dev-master)symfony/routing suggests installing symfony/yaml (dev-master)symfony/routing suggests installing doctrine/common (>=2.2,<2.3)[...]silex/silex suggests installing symfony/browser-kit (2.1.*)silex/silex suggests installing symfony/css-selector (2.1.*)silex/silex suggests installing symfony/dom-crawler (2.1.*)Writing lock fileGenerating autoload files
  31. 31. Installing dependencies - Installing pimple/pimple (dev-master) your Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be dependency’s - Installing symfony/routing (dev-master) dependencies Cloning 6bca82c3ea0d42d750de4f49b22020dfd047dc0f [...] - Installing silex/silex (dev-master) your dependency Cloning 18e248a277adb061602d2bcabe96011db1c76ec0symfony/routing suggests installing symfony/config (dev-master)symfony/routing suggests installing symfony/yaml (dev-master)symfony/routing suggests installing doctrine/common (>=2.2,<2.3)[...]silex/silex suggests installing symfony/browser-kit (2.1.*)silex/silex suggests installing symfony/css-selector (2.1.*)silex/silex suggests installing symfony/dom-crawler (2.1.*)Writing lock fileGenerating autoload files
  32. 32. Installing dependencies - Installing pimple/pimple (dev-master) your Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be dependency’s - Installing symfony/routing (dev-master) dependencies Cloning 6bca82c3ea0d42d750de4f49b22020dfd047dc0f [...] - Installing silex/silex (dev-master) your dependency Cloning 18e248a277adb061602d2bcabe96011db1c76ec0symfony/routing suggests installing symfony/config (dev-master)symfony/routing suggests installing symfony/yaml (dev-master)symfony/routing suggests installing doctrine/common (>=2.2,<2.3)[...]silex/silex suggests installing symfony/browser-kit (2.1.*)silex/silex suggests installing symfony/css-selector (2.1.*)silex/silex suggests installing symfony/dom-crawler (2.1.*)Writing lock fileGenerating autoload files suggestions of other packages, for further features
  33. 33. P)*42p (+$ ($"p!!Let Composer bootstrap you development
  34. 34. B!!(0(rpp)./ Pr!5$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myproject
  35. 35. B!!(0(rpp)./ Pr!5$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myprojectInstalling fabpot/silex-skeleton (dev-mastercc19d406cf3cac253715db92d400992d4f3e1b52) - Installing fabpot/silex-skeleton (dev-master) Cloning masterCreated project in one-liner/Installing dependencies - Installing pimple/pimple (dev-master) Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be [...]symfony/routing suggests installing symfony/yaml (dev-master)[...]Writing lock fileGenerating autoload files
  36. 36. B!!(0(rpp)./ Pr!5$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myprojectInstalling fabpot/silex-skeleton (dev-mastercc19d406cf3cac253715db92d400992d4f3e1b52) - Installing fabpot/silex-skeleton (dev-master) Cloning masterCreated project in one-liner/ myprojeInstalling dependencies ct/ - Installing pimple/pimple (dev-master) compose r.json Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be compose r.lock config/ [...] console / src/ templatsymfony/routing suggests installing symfony/yaml (dev-master) es/ vendor/[...] web/Writing lock fileGenerating autoload files
  37. 37. I w.( (! *!.(r)b2($ pr!5$*( Composer can set that up for you.
  38. 38. B!!(0(rpp)./ C!.(r)b2()!.0$ composer.phar create-project dms/dms --dev ~/dev/oss/dms
  39. 39. B!!(0(rpp)./ C!.(r)b2()!.0 gimme dev packages$ composer.phar create-project dms/dms --dev ~/dev/oss/dms
  40. 40. B!!(0(rpp)./ C!.(r)b2()!.0 gimme dev packages$ composer.phar create-project dms/dms --dev ~/dev/oss/dms     "require-dev": {         "symfony/symfony": ">=2.1-dev",         "doctrine/orm": "dev-master"     },
  41. 41. B!!(0(rpp)./ C!.(r)b2()!.0 gimme dev packages$ composer.phar create-project dms/dms --dev ~/dev/oss/dms     "require-dev": {         "symfony/symfony": ">=2.1-dev",         "doctrine/orm": "dev-master"     }, “require-dev”: only needed if you are going to contribute
  42. 42. H!w -! I 6.-/&!- (+$ 6&$0? PSR-0 and the modern autoloader
  43. 43. Composer generates anautoload file for all your dependencies
  44. 44. Composer generates anautoload file for all your dependencies vendor/autoload.php
  45. 45. "autoload": {    "psr-0": { "MyNamespace": "<root>" }, "classmap": ["src/", "lib/", "Something.php"], "files": ["src/MyLibrary/functions.php"]},
  46. 46. “autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" }, "classmap": ["src/", "lib/", "Something.php"], "files": ["src/MyLibrary/functions.php"]},
  47. 47. “autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" “psr-0”: PSR-0 Compatible libraries }, "classmap": ["src/", "lib/", "Something.php"], "files": ["src/MyLibrary/functions.php"]},
  48. 48. “autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" “psr-0”: PSR-0 Compatible libraries }, "classmap": ["src/", "lib/", "Something.php"], PEAR packages and “classmap”: Old other libraries "files": ["src/MyLibrary/functions.php"]},
  49. 49. “autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" “psr-0”: PSR-0 Compatible libraries }, "classmap": ["src/", "lib/", "Something.php"], PEAR packages and “classmap”: Old other libraries "files": ["src/MyLibrary/functions.php"] “files”: for php functions or initializations},
  50. 50. I.0(&&)./, 2p-()./ .- "!v)./ !. how does Composer guarantee consistency
  51. 51. composer.json
  52. 52. “composer.json”: metadata and list of your dependencies.composer.json
  53. 53. “composer.json”: metadata and list of your dependencies.composer.jsoncomposer.lock
  54. 54. “composer.json”: metadata and list of your dependencies.composer.jsoncomposer.lock “composer.lock”: existing dependencies and current commit hashes.
  55. 55. composer.jsoncomposer.lock
  56. 56. update composer.json composer.lock
  57. 57. update install composer.json composer.lock
  58. 58. update install reads composer.json composer.lock
  59. 59. update install reads composer.json composer.lock gets latest
  60. 60. update install reads composer.json writes composer.lock gets latest
  61. 61. update install reads reads composer.json writes composer.lock gets latest
  62. 62. update install reads reads composer.json compares writes composer.lock gets latest
  63. 63. update install reads reads composer.json compares writes composer.lock gets latest gets locked version
  64. 64. D$v$&!p)./ . App ). ($"? Commit you composer.lock file into the repository, and use composer install.
  65. 65. D$v$&!p)./ . App ). ($"? Commit you composer.lock file into the repository, and use composer install. will ensure everyone is on the same “page”
  66. 66. I’" -$v$&!p)./ &)brr,, +$&p!here are some fields you should care about
  67. 67. { "name": "vendor-namespace/package-name", "type": "symfony-bundle", "description": "A sample package for examples", "keywords": ["php", "package"], "homepage": "http://doh.ms", "license": "MIT", "support": { "email": "support@mylib.com", "issues": "http://issues.lib.com" } "target-dir": "/folder/to/install",}
  68. 68. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", "type": "symfony-bundle", "description": "A sample package for examples", "keywords": ["php", "package"], "homepage": "http://doh.ms", "license": "MIT", "support": { "email": "support@mylib.com", "issues": "http://issues.lib.com" } "target-dir": "/folder/to/install",}
  69. 69. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", “type”: will be used for more "type": "symfony-bundle", advanced “custom”installs "description": "A sample package for examples", "keywords": ["php", "package"], "homepage": "http://doh.ms", "license": "MIT", "support": { "email": "support@mylib.com", "issues": "http://issues.lib.com" } "target-dir": "/folder/to/install",}
  70. 70. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", “type”: will be used for more "type": "symfony-bundle", advanced “custom”installs "description": "A sample package for examples", "keywords": ["php", "package"], "homepage": "http://doh.ms", "license": "MIT", “license”: very important! "support": { "email": "support@mylib.com", "issues": "http://issues.lib.com" } "target-dir": "/folder/to/install",}
  71. 71. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", “type”: will be used for more "type": "symfony-bundle", advanced “custom”installs "description": "A sample package for examples", "keywords": ["php", "package"], "homepage": "http://doh.ms", "license": "MIT", “license”: very important! "support": { “support”: point people the right "email": "support@mylib.com", "issues": "http://issues.lib.com" way. } "target-dir": "/folder/to/install",}
  72. 72. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", “type”: will be used for more "type": "symfony-bundle", advanced “custom”installs "description": "A sample package for examples", "keywords": ["php", "package"], "homepage": "http://doh.ms", "license": "MIT", “license”: very important! "support": { “support”: point people the right "email": "support@mylib.com", "issues": "http://issues.lib.com" way. } "target-dir": "/folder/to/install",} “target-dir”: great for installing sub-dir splits repositories ex: Symfony Bundles: /Acme/Bundle/MyBundle
  73. 73. M, *!-$ )0 PHP 5.4 !.&,! managing system dependencies
  74. 74. { "require": { "php": ">=5.3.3", "ext-ldap": "*" }}
  75. 75. { “php”: PHP version. "require": { "php": ">=5.3.3", "ext-ldap": "*" }}
  76. 76. { “php”: PHP version. "require": { "php": ">=5.3.3", "ext-ldap": "*" } “ext-*”: Presence of selected} extension
  77. 77. Up/r-)./ (! M$0(r!
  78. 78. B2( I .$$- 0p$*)6* v$r0)!. version modifiers to the rescue!
  79. 79. "acme/foo": "1.0.x-dev#3ebbe75"
  80. 80. “#<ref>”: Get this specific commit"acme/foo": "1.0.x-dev#3ebbe75"
  81. 81. “#<ref>”: Get this specific commit"acme/foo": "1.0.x-dev#3ebbe75" "acme/foo": "@dev" "acme/foo": "1.0.*@beta"
  82. 82. “#<ref>”: Get this specific commit"acme/foo": "1.0.x-dev#3ebbe75" "acme/foo": "@dev" "acme/foo": "1.0.*@beta" “@<state>”: Get a version outside your default stability
  83. 83. I .$$- (! 7$*2($ f$w 0*r)p(0 how to automate tasks with Composer
  84. 84.     "scripts": {        "post-install-cmd": [            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"        ],        "post-update-cmd": [            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"        ]    },
  85. 85. “scripts”: allows you to run scripts at given moments    "scripts": {        "post-install-cmd": [            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"        ],        "post-update-cmd": [            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"        ]    },
  86. 86. C20(!" R$p#)(!r)$0 !r .! C!"p#$r, w+( .!w?Injecting Composer into wild packages
  87. 87. “hero/superpackage”: “dev-master”
  88. 88. “hero/superpackage”: “dev-master”
  89. 89. “hero/superpackage”: “dev-master”
  90. 90. “hero/superpackage”: “dev-master”
  91. 91. “hero/superpackage”: “dev-master”    "repositories": [ { "type": "vcs", "url": "https://github.com/rdohms/hero-superpackage" }        ]
  92. 92. “hero/superpackage”: “dev-master” “repositories”: point to non-indexed, override existing or on- the-fly packages    "repositories": [ { "type": "vcs", "url": "https://github.com/rdohms/hero-superpackage" }        ]
  93. 93. N!.-C!"p#$r P*4/${ "repositories": [ { "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/" } } } ]}
  94. 94. N!.-C!"p#$r P*4/${ "repositories": [ “package”: on-the-fly package, injecting a { composer.json "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/" } } } ]}
  95. 95. N!.-C!"p#$r P*4/${ "repositories": [ “package”: on-the-fly package, injecting a { composer.json "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" SVN / Git }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/" } } } ]}
  96. 96. I .$$- (+)0 PEAR p*4/$... No Problem!
  97. 97. { "repositories": [ { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }}
  98. 98. { “pear”: official PEAR and custom PEAR "repositories": [ channels { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }}
  99. 99. { “pear”: official PEAR and custom PEAR "repositories": [ channels { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }} Remember the prefix!
  100. 100. { “pear”: official PEAR and custom PEAR "repositories": [ channels { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }} Remember the prefix! !! Warning: PEAR causes a overhead of requests
  101. 101. aliasreplace provide
  102. 102. alias{ "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } }, "require": { "monolog/monolog": "dev-bugfix as 1.0.x-dev" }}replace provide
  103. 103. alias{ "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } }, "require": { "monolog/monolog": "dev-bugfix as 1.0.x-dev" }}replace provide “replace”: allows you toreplace other packages, andbe used them in their place.
  104. 104. alias{ "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } }, "require": { "monolog/monolog": "dev-bugfix as 1.0.x-dev" }}replace provide “replace”: allows you to “provide”: allows you to sayreplace other packages, and a package provides abe used them in their place. expectation.
  105. 105. 1.-)./ ,!2r (2.$
  106. 106. I .$$- &)brr, (+( -!$0.. Let me get that for you
  107. 107. http://packagist.org/
  108. 108. usage info package infoversions
  109. 109. $ composer.phar search filter
  110. 110. $ composer.phar search filterdms/dms-filter-bundle : DMS Filter Bundle, makes Annotation based ...lexik/form-filter-bundle : This bundle aim to provide classes tobuild...rollerworks/recordfilter-bundle : Record search-filtering bundle for Symfonybrikou/zend_filter : Zend Framework Filter Libraryext-filter : The filter PHP extensiondms/dms-filter : DMS Library, includes various bundles and ...shtumi/useful-bundle : Symfony ShtumiUsefulBundle
  111. 111. $ composer.phar show dms/dms-filter-bundle
  112. 112. $ composer.phar show dms/dms-filter-bundlename : dms/dms-filter-bundledescrip. : DMS Filter Bundle, makes Annotation based entity filteringavailable in Symfonykeywords : symfony, bundle, filter, dmsversions : dev-master, v1.1.1, v1.1, 1.0.2, 1.0.1, 1.0.0type : symfony-bundlelicense : MITsource : [git] https://github.com/rdohms/DMSFilterBundle v1.1.1dist : [zip] https://github.com/rdohms/DMSFilterBundle/zipball/v1.1.1 v1.1.1names : dms/dms-filter-bundleautoloadpsr-0DMSBundleFilterBundle => .requiresphp >=5.3.2dms/dms-filter >=1.0.2
  113. 113. B2( ", r$p#)(!r, )0 pr)v($! Get your own package repository
  114. 114. S()0!
  115. 115. R!&&!2( ,!2r !w. S()0$ composer.phar create-project composer/satis
  116. 116. R!&&!2( ,!2r !w. S()0$ composer.phar create-project composer/satis$ vi packages.json { "name": "My Repository", "homepage": "http://packages.example.org", "repositories": [ { "type": "vcs", "url": "http://github.com/mycompany/privaterepo" }, { "type": "vcs", "url": "http://svn.example.org/private/repo" }, { "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" } ], "require-all": true }
  117. 117. R!&&!2( ,!2r !w. S()0$ composer.phar create-project composer/satis$ vi packages.json { "name": "My Repository", "homepage": "http://packages.example.org", "repositories": [ { "type": "vcs", "url": "http://github.com/mycompany/privaterepo" }, { "type": "vcs", "url": "http://svn.example.org/private/repo" }, { "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" } ], "require-all": true }$ php bin/satis build config.json web/
  118. 118. U0)./ ,!2r !w. S()0{ "repositories": [ { "type": "composer", "url": "http://packages.yourdomain.net" } ], “require”: { “myvendor/mypackage”: “dev-master” }}
  119. 119. U0)./ ,!2r !w. S()0{ "repositories": [ “composer”: use this just like it was Packagist { "type": "composer", "url": "http://packages.yourdomain.net" } ], “require”: { “myvendor/mypackage”: “dev-master” }}
  120. 120. W+$r$ 0+!2&- I /$( +$&p? http://getcomposer.org #composer on irc.freenode.org
  121. 121. %$ E&$v(!r P)(*+ Dependency Manager, consistent versions, per-project Ev$r,-, *!"p#)./ install, update, lock and autoload Up/r-)./ (! M$0(r!post-install, overriding, PEAR integration, developer environment 1.-)./ ,!2r (2.$ Satis and Packagist
  122. 122. %.4 ,!2! https://joind.in/7051@rdohmshttp://doh.mshttp://slides.doh.ms
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×