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 --versionComposer version 6573fd3
I.0(&&)./ C!"p#$r   php$ composer.phar --versionComposer 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/sil...
C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json       note: project root                                         “requi...
C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json       note: project root                                         “requi...
C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json        note: project root                                          “req...
Installing dependencies  - Installing pimple/pimple (dev-master)    Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be  - In...
Installing dependencies  - Installing pimple/pimple (dev-master)    Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be  - In...
Installing dependencies  - Installing pimple/pimple (dev-master)    Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be  - In...
Installing dependencies  - Installing pimple/pimple (dev-master)    Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be  - In...
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...
A--)./ .$w R$q2)r$"$.(0$ composer.phar require symfony/yaml=~2.1.0
A--)./ .$w R$q2)r$"$.(0$ composer.phar require symfony/yaml=~2.1.0composer.json has been updatedLoading composer repositor...
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": { "MyNamespace": "<root>" },     "c...
“autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" },       ...
“autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" },       ...
“autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" },       ...
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 ...
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",                              ...
T/ ,!2r r$&$0$0!use semver and always make tags for releases
T/ ,!2r r$&$0$0!use semver and always make tags for releases                  X.Y.Z      Also allows the use of ~1.1 which...
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.*@beta"
“#<ref>”: Get this specific commit"acme/foo": "1.0.x-dev#3ebbe75"      "acme/foo": "@dev"   "acme/foo": "1.0.*@beta"    “@...
I .$$- (! 7$*2($  f$w 0*r)p(0 how to automate tasks with Composer
    "scripts": {        "post-install-cmd": [            "Sensio...ComposerScriptHandler::buildBootstrap",            "Sen...
“scripts”: allows you to run scripts at given moments    "scripts": {        "post-install-cmd": [            "Sensio...Co...
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": [        {            "type": "vcs",            "url": "https://githu...
“hero/superpackage”: “dev-master”       “repositories”: point to non-indexed, override existing or on-the-                ...
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 composer.json                     [      ...
N!.-C!"p#$r P*4/${    "repositories": “package”: on-the-fly package, injecting a composer.json                     [      ...
I .$$- (+)0 PEAR p*4/$...         No Problem!
{    "repositories": [        {            "type": "pear",            "url": "http://pear2.php.net"        }    ],    "req...
{    "repositories": [   “pear”: official PEAR and custom PEAR channels        {            "type": "pear",            "ur...
{    "repositories": [   “pear”: official PEAR and custom PEAR channels        {            "type": "pear",            "ur...
{    "repositories": [   “pear”: official PEAR and custom PEAR channels        {            "type": "pear",            "ur...
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 Annotationbased ...lexik/form-fi...
$ 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...
Q2$0()!.0?                       https://joind.in/7980@rdohmshttp://doh.mshttp://slides.doh.ms
Composer for busy developers - ConFoo 2013
Composer for busy developers - ConFoo 2013
Upcoming SlideShare
Loading in...5
×

Composer for busy developers - ConFoo 2013

3,215

Published on

Managing dependencies and third-party code in PHP applications is a daily challenge, keeping everyone on the same versions during development and at deploy time a struggle. Meet Composer a tool designed to help you maintain a consistent set of dependencies as well as share and discover new libraries. Let's see how you can use this tool in your Applications and Libraries to wrangle your dependencies with a simple json configuration file and a command line interface.

Published in: Technology

Composer for busy developers - ConFoo 2013

  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 --versionComposer version 6573fd3
  19. 19. I.0(&&)./ C!"p#$r php$ composer.phar --versionComposer 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": { adv. ex.: >=1.0.0,<1.2-dev or ~1.1 "silex/silex": "1.0.*" }, "minimum-stability": "dev" }
  27. 27. C!"p#$r 101$ cd ~/dev/myproject$ vim composer.json note: project root “require”: required packages and versions { "require": { adv. ex.: >=1.0.0,<1.2-dev or ~1.1 "silex/silex": "1.0.*" }, "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": { adv. ex.: >=1.0.0,<1.2-dev or ~1.1 "silex/silex": "1.0.*" }, "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 symfony/http-foundation (dev-master) Cloning 498c2da9c3fecefc7e3b0add73621f3feb337ddd - Installing symfony/event-dispatcher (dev-master) Cloning b99b49760016467099f010aff7a5098861d49e09 - Installing symfony/http-kernel (dev-master) Cloning 7f671472f009231f9c1f5ec9b81fc6fbfcd9a955 - 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.4-dev)symfony/event-dispatcher suggests installing symfony/dependency-injection (dev-master)symfony/http-kernel suggests installing symfony/browser-kit (dev-master)symfony/http-kernel suggests installing symfony/class-loader (dev-master)symfony/http-kernel suggests installing symfony/config (dev-master)symfony/http-kernel suggests installing symfony/console (dev-master)symfony/http-kernel suggests installing symfony/dependency-injection (dev-master)symfony/http-kernel suggests installing symfony/finder (dev-master)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) Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be - Installing symfony/routing (dev-master) Cloning 6bca82c3ea0d42d750de4f49b22020dfd047dc0f - Installing symfony/http-foundation (dev-master) your dependency’s dependencies Cloning 498c2da9c3fecefc7e3b0add73621f3feb337ddd - Installing symfony/event-dispatcher (dev-master) Cloning b99b49760016467099f010aff7a5098861d49e09 - Installing symfony/http-kernel (dev-master) Cloning 7f671472f009231f9c1f5ec9b81fc6fbfcd9a955 - 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.4-dev)symfony/event-dispatcher suggests installing symfony/dependency-injection (dev-master)symfony/http-kernel suggests installing symfony/browser-kit (dev-master)symfony/http-kernel suggests installing symfony/class-loader (dev-master)symfony/http-kernel suggests installing symfony/config (dev-master)symfony/http-kernel suggests installing symfony/console (dev-master)symfony/http-kernel suggests installing symfony/dependency-injection (dev-master)symfony/http-kernel suggests installing symfony/finder (dev-master)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) Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be - Installing symfony/routing (dev-master) Cloning 6bca82c3ea0d42d750de4f49b22020dfd047dc0f - Installing symfony/http-foundation (dev-master) your dependency’s dependencies Cloning 498c2da9c3fecefc7e3b0add73621f3feb337ddd - Installing symfony/event-dispatcher (dev-master) Cloning b99b49760016467099f010aff7a5098861d49e09 - Installing symfony/http-kernel (dev-master) Cloning 7f671472f009231f9c1f5ec9b81fc6fbfcd9a955 - Installing silex/silex (dev-master) Cloning 18e248a277adb061602d2bcabe96011db1c76ec0 your dependencysymfony/routing suggests installing symfony/config (dev-master)symfony/routing suggests installing symfony/yaml (dev-master)symfony/routing suggests installing doctrine/common (>=2.2,<2.4-dev)symfony/event-dispatcher suggests installing symfony/dependency-injection (dev-master)symfony/http-kernel suggests installing symfony/browser-kit (dev-master)symfony/http-kernel suggests installing symfony/class-loader (dev-master)symfony/http-kernel suggests installing symfony/config (dev-master)symfony/http-kernel suggests installing symfony/console (dev-master)symfony/http-kernel suggests installing symfony/dependency-injection (dev-master)symfony/http-kernel suggests installing symfony/finder (dev-master)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) Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be - Installing symfony/routing (dev-master) Cloning 6bca82c3ea0d42d750de4f49b22020dfd047dc0f - Installing symfony/http-foundation (dev-master) your dependency’s dependencies Cloning 498c2da9c3fecefc7e3b0add73621f3feb337ddd - Installing symfony/event-dispatcher (dev-master) Cloning b99b49760016467099f010aff7a5098861d49e09 - Installing symfony/http-kernel (dev-master) Cloning 7f671472f009231f9c1f5ec9b81fc6fbfcd9a955 - Installing silex/silex (dev-master) Cloning 18e248a277adb061602d2bcabe96011db1c76ec0 your dependencysymfony/routing suggests installing symfony/config (dev-master)symfony/routing suggests installing symfony/yaml (dev-master)symfony/routing suggests installing doctrine/common (>=2.2,<2.4-dev)symfony/event-dispatcher suggests installing symfony/dependency-injection (dev-master)symfony/http-kernel suggests installing symfony/browser-kit (dev-master)symfony/http-kernel suggests installing symfony/class-loader (dev-master)symfony/http-kernel suggests installing symfony/config (dev-master)symfony/http-kernel suggests installing symfony/console (dev-master)symfony/http-kernel suggests installing symfony/dependency-injection (dev-master)symfony/http-kernel suggests installing symfony/finder (dev-master)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.*) suggestions of other packages,Writing lock fileGenerating autoload files 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/Installing dependencies myproje ct/ - Installing pimple/pimple (dev-master) compose Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be r.json compose r.lock config/ [...] console / src/symfony/routing suggests installing symfony/yaml (dev-master) templat[...] 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. A--)./ .$w R$q2)r$"$.(0$ composer.phar require symfony/yaml=~2.1.0
  43. 43. A--)./ .$w R$q2)r$"$.(0$ composer.phar require symfony/yaml=~2.1.0composer.json has been updatedLoading composer repositories with package informationUpdating dependencies - Installing symfony/yaml (v2.1.8) Downloading: 100%Writing lock fileGenerating autoload files
  44. 44. H!w -! I 6.-/&!- (+$ 6&$0? PSR-0 and the modern autoloader
  45. 45. Composer generates anautoload file for all your dependencies
  46. 46. Composer generates anautoload file for all your dependencies vendor/autoload.php
  47. 47. "autoload": {    "psr-0": { "MyNamespace": "<root>" }, "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>" }, "classmap": ["src/", "lib/", "Something.php"], "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"], "files": ["src/MyLibrary/functions.php"]},
  50. 50. “autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" }, “psr-0”: PSR-0 Compatible libraries “classmap”: Old PEAR packages and other "classmap": ["src/", "lib/", "Something.php"], libraries "files": ["src/MyLibrary/functions.php"]},
  51. 51. “autoload”: describes the autoloading needed for your library"autoload": {    "psr-0": { "MyNamespace": "<root>" }, “psr-0”: PSR-0 Compatible libraries “classmap”: Old PEAR packages and other "classmap": ["src/", "lib/", "Something.php"], libraries "files": ["src/MyLibrary/functions.php"] “files”: for php functions or initializations},
  52. 52. I.0(&&)./, 2p-()./ .- "!v)./ !. how does Composer guarantee consistency
  53. 53. composer.json
  54. 54. “composer.json”: metadata and list of your dependencies.composer.json
  55. 55. “composer.json”: metadata and list of your dependencies.composer.jsoncomposer.lock
  56. 56. “composer.json”: metadata and list of your dependencies.composer.jsoncomposer.lock “composer.lock”: existing dependencies and current commit hashes.
  57. 57. composer.jsoncomposer.lock
  58. 58. update composer.json composer.lock
  59. 59. update install composer.json composer.lock
  60. 60. update install reads composer.json composer.lock
  61. 61. update install reads composer.json composer.lock gets latest
  62. 62. update install reads composer.json writes composer.lock gets latest
  63. 63. update install reads reads composer.json writes composer.lock gets latest
  64. 64. update install reads reads composer.json compares writes composer.lock gets latest
  65. 65. update install reads reads composer.json compares writes composer.lock gets latest gets locked version
  66. 66. D$v$&!p)./ . App ). ($"? Commit you composer.lock file into the repository, and use composer install.
  67. 67. D$v$&!p)./ . App ). ($"? Commit you composer.lock file into the repository, and use composer install. will ensure everyone is on the same “page”
  68. 68. I’" -$v$&!p)./ &)brr,, +$&p!here are some fields you should care about
  69. 69. { "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",}
  70. 70. “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",}
  71. 71. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", “type”: will be used for more advanced "type": "symfony-bundle", “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",}
  72. 72. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", “type”: will be used for more advanced "type": "symfony-bundle", “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",}
  73. 73. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", “type”: will be used for more advanced "type": "symfony-bundle", “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", “support”: point people the right way. "issues": "http://issues.lib.com" } "target-dir": "/folder/to/install",}
  74. 74. “name”: this should be unique, pick a good one!{ "name": "vendor-namespace/package-name", “type”: will be used for more advanced "type": "symfony-bundle", “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", “support”: point people the right way. "issues": "http://issues.lib.com" } "target-dir": "/folder/to/install",} “target-dir”: great for installing sub-dir splits repositories ex: Symfony Bundles: /Acme/Bundle/MyBundle
  75. 75. T/ ,!2r r$&$0$0!use semver and always make tags for releases
  76. 76. T/ ,!2r r$&$0$0!use semver and always make tags for releases X.Y.Z Also allows the use of ~1.1 which leads to >=1.1,<2.0
  77. 77. M, *!-$ )0 PHP 5.4 !.&,! managing system dependencies
  78. 78. { "require": { "php": ">=5.3.3", "ext-ldap": "*" }}
  79. 79. { “php”: PHP version. "require": { "php": ">=5.3.3", "ext-ldap": "*" }}
  80. 80. { “php”: PHP version. "require": { "php": ">=5.3.3", "ext-ldap": "*" }} “ext-*”: Presence of selected extension
  81. 81. Up/r-)./ (! M$0(r!
  82. 82. B2( I .$$- 0p$*)6* v$r0)!. version modifiers to the rescue!
  83. 83. "acme/foo": "1.0.x-dev#3ebbe75"
  84. 84. “#<ref>”: Get this specific commit"acme/foo": "1.0.x-dev#3ebbe75"
  85. 85. “#<ref>”: Get this specific commit"acme/foo": "1.0.x-dev#3ebbe75" "acme/foo": "@dev" "acme/foo": "1.0.*@beta"
  86. 86. “#<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
  87. 87. I .$$- (! 7$*2($ f$w 0*r)p(0 how to automate tasks with Composer
  88. 88.     "scripts": {        "post-install-cmd": [            "Sensio...ComposerScriptHandler::buildBootstrap",            "Sensio...ComposerScriptHandler::clearCache",            "Sensio...ComposerScriptHandler::installAssets",            "Sensio...ComposerScriptHandler::installRequirementsFile"        ],        "post-update-cmd": [            "Sensio...ComposerScriptHandler::buildBootstrap",            "Sensio...ComposerScriptHandler::clearCache",            "Sensio...ComposerScriptHandler::installAssets",            "Sensio...ComposerScriptHandler::installRequirementsFile"        ]    },
  89. 89. “scripts”: allows you to run scripts at given moments    "scripts": {        "post-install-cmd": [            "Sensio...ComposerScriptHandler::buildBootstrap",            "Sensio...ComposerScriptHandler::clearCache",            "Sensio...ComposerScriptHandler::installAssets",            "Sensio...ComposerScriptHandler::installRequirementsFile"        ],        "post-update-cmd": [            "Sensio...ComposerScriptHandler::buildBootstrap",            "Sensio...ComposerScriptHandler::clearCache",            "Sensio...ComposerScriptHandler::installAssets",            "Sensio...ComposerScriptHandler::installRequirementsFile"        ]    },
  90. 90. C20(!" R$p#)(!r)$0 !r .! C!"p#$r, w+( .!w?Injecting Composer into wild packages
  91. 91. “hero/superpackage”: “dev-master”
  92. 92. “hero/superpackage”: “dev-master”
  93. 93. “hero/superpackage”: “dev-master”
  94. 94. “hero/superpackage”: “dev-master”
  95. 95. “hero/superpackage”: “dev-master”    "repositories": [ { "type": "vcs", "url": "https://github.com/rdohms/hero-superpackage" }        ]
  96. 96. “hero/superpackage”: “dev-master”    "repositories": [ { "type": "vcs", "url": "https://github.com/rdohms/hero-superpackage" }        ] my fork
  97. 97. “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" }        ] my fork
  98. 98. 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/" } } } ]}
  99. 99. 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/" } } } ]}
  100. 100. 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/" } } } ]}
  101. 101. I .$$- (+)0 PEAR p*4/$... No Problem!
  102. 102. { "repositories": [ { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }}
  103. 103. { "repositories": [ “pear”: official PEAR and custom PEAR channels { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }}
  104. 104. { "repositories": [ “pear”: official PEAR and custom PEAR channels { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }} Remember the prefix!
  105. 105. { "repositories": [ “pear”: official PEAR and custom PEAR 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
  106. 106. aliasreplace provide
  107. 107. alias{ "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } }, "require": { "monolog/monolog": "dev-bugfix as 1.0.x-dev" }}replace provide
  108. 108. 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.
  109. 109. 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.
  110. 110. 1.-)./ ,!2r (2.$
  111. 111. I .$$- &)brr, (+( -!$0.. Let me get that for you
  112. 112. http://packagist.org/
  113. 113. usage info package infoversions
  114. 114. $ composer.phar search filter
  115. 115. $ composer.phar search filterdms/dms-filter-bundle : DMS Filter Bundle, makes Annotationbased ...lexik/form-filter-bundle : This bundle aim to provide classes tobuild...rollerworks/recordfilter-bundle : Record search-filtering bundle forSymfonybrikou/zend_filter : Zend Framework Filter Libraryext-filter : The filter PHP extensiondms/dms-filter : DMS Library, includes various bundlesand ...shtumi/useful-bundle : Symfony ShtumiUsefulBundle
  116. 116. $ composer.phar show dms/dms-filter-bundle
  117. 117. $ 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
  118. 118. B2( ", r$p#)(!r, )0 pr)v($! Get your own package repository
  119. 119. S()0!
  120. 120. R!&&!2( ,!2r !w. S()0$ composer.phar create-project composer/satis
  121. 121. 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 }
  122. 122. 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/
  123. 123. U0)./ ,!2r !w. S()0{ "repositories": [ { "type": "composer", "url": "http://packages.yourdomain.net" } ], “require”: { “myvendor/mypackage”: “dev-master” }}
  124. 124. 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” }}
  125. 125. W+$r$ 0+!2&- I /$( +$&p? http://getcomposer.org #composer on irc.freenode.org
  126. 126. %$ 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
  127. 127. Q2$0()!.0? https://joind.in/7980@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.

×