C!"p#$rPutting your dependencies on the scoreRafael Dohms / @rdohms
photocredit:EliWhiteEvangelist, Speaker andContributor.Developer at WEBclusive.Enabler at AmsterdamPHP.Rafael Dohms@rdohms
photocredit:EliWhiteEvangelist, Speaker andContributor.Developer at WEBclusive.Enabler at AmsterdamPHP.Rafael Dohms@rdohms
%$ E&$v(!r P)(*+a general introduction to ComposerEv$r,-, *!"p#)./the basic stuff you need to knowUp/r-)./ (!  M$0(r!advan...
%$ E&$v(!r P)(*+
per project system widecentral repositoryopen acceptancespread out channelsstrict standards
I need my team and my deployments touse consistent versions of thedependencies of my project
The Evolution of Vendor Management
copy & paste
copy & pastePEAR
copy & pasteSVN ExternalsPEAR
copy & pasteSVN ExternalsGit SubmodulesPEAR
copy & pasteSymfony2vendor scriptSVN ExternalsGit SubmodulesPEAR
copy & pasteSymfony2vendor scriptSVN ExternalsGit SubmodulesPEARComposer!
A per-project dependencymanager that allows you todeclare a consistent list ofdependencies and versions foryour applicatio...
Ev$r,-, C!"p#)./
I.0(&&)./ C!"p#$r$ curl -s http://getcomposer.org/installer | php$ curl -s http://getcomposer.org/installer | php -- --ins...
I.0(&&)./ C!"p#$r$ curl -s http://getcomposer.org/installer | php$ curl -s http://getcomposer.org/installer | php -- --ins...
I.0(&&)./ C!"p#$r
I.0(&&)./ C!"p#$r$ composer.phar --versionComposer version 7073d38
I.0(&&)./ C!"p#$r$ composer.phar --versionComposer version 7073d38php
K$$p )( 2p-($-!
K$$p )( 2p-($-!$ composer.phar self-updateUpdating to version 7073d38.Downloading: 100%
I’" b2)&-)./  Pr!4$*(How can composer manage your dependencies
C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0
C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject
C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json{"require": {"silex/silex": "~1.0"}}
C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json{"require": {"silex/silex": "~1.0"}}put this in ...
C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json{"require": {"silex/silex": "~1.0"}}put this in ...
C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json{"require": {"silex/silex": "~1.0"}}put this in ...
C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json$ composer.phar install{"require": {"silex/silex...
Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cach...
Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cach...
Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cach...
Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cach...
“~1.0”V$r0)!.)./G$( (+$ -!(0 ).  r!w“>=1.0”“>=1.0, <=1.1”“1.0.*”
“~1.0”V$r0)!.)./G$( (+$ -!(0 ).  r!w“>=1.0”“>=1.0, <=1.1”“1.0.*”>=1.0, <2.0: BC Compatible releases
V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0
V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0“minimum-stability”: “stable”
V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0“minimum-stability”: “stable”No dev versions in dependency tree
V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0“minimum-stability”: “stable”No dev versions in dependency tree“dms/dms”: “1.0...
V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0“minimum-stability”: “stable”No dev versions in dependency tree“dms/dms”: “1.0...
Q2)*5! I +v$ . )-$!B!#(rpp)./ Pr!4$*(0
Q2)*5! I +v$ . )-$!B!#(rpp)./ Pr!4$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myproject
Q2)*5! I +v$ . )-$!B!#(rpp)./ Pr!4$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myprojectInstalling fabpo...
Q2)*5! I +v$ . )-$!B!#(rpp)./ Pr!4$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myprojectInstalling fabpo...
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 yourdependencies
Composer generates anautoload file for all yourdependenciesvendor/autoload.php
"autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibra...
"autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibra...
"autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibra...
"autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibra...
"autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibra...
I .$$- ,!2r 0$rv$r (! +v$ (+$0$..C+$*5)./ 0,0($" -$p$.-$.*)$0
{"require": {"php": ">=5.3.3","ext-ldap": "*"}}I .$$- ,!2r 0$rv$r (! +v$ (+$0$..C+$*5)./ 0,0($" -$p$.-$.*)$0
{"require": {"php": ">=5.3.3","ext-ldap": "*"}}“php”: PHP version.I .$$- ,!2r 0$rv$r (! +v$ (+$0$..C+$*5)./ 0,0($" -$p$.-$...
{"require": {"php": ">=5.3.3","ext-ldap": "*"}}“php”: PHP version.“ext-*”: Presence of selectedextensionI .$$- ,!2r 0$rv$r...
I’" 0*r$- !f @/r"p7r!/r""$r.. 0! I wr)($ ($0(0
    "require-dev": {        "phpunit/phpunit": "~3.7"    },I’" 0*r$- !f @/r"p7r!/r""$r.. 0! I wr)($ ($0(0
    "require-dev": {        "phpunit/phpunit": "~3.7"    },“require-dev”: only needed if you are going tocontribute/develo...
    "require-dev": {        "phpunit/phpunit": "~3.7"    },“require-dev”: only needed if you are going tocontribute/develo...
    "require-dev": {        "phpunit/phpunit": "~3.7"    },“require-dev”: only needed if you are going tocontribute/develo...
I.0(&&)./, 2p-()./ .- "!v)./ !.how does Composer guarantee consistency
composer.json
“composer.json”: metadata and list of yourdependencies.composer.json
“composer.json”: metadata and list of yourdependencies.composer.lockcomposer.json
“composer.json”: metadata and list of yourdependencies.“composer.lock”: existing dependencies andcurrent commit hashes.com...
composer.lockcomposer.json
updatecomposer.lockcomposer.json
update installcomposer.lockcomposer.json
update installreadscomposer.lockcomposer.json
update installreadsgets latestcomposer.lockcomposer.json
update installreadsgets latestwritescomposer.lockcomposer.json
update installreadsgets latestwritesreadscomposer.lockcomposer.json
update installreadsgets latestwritesreadscomparescomposer.lockcomposer.json
update installreadsgets latestwritesreadsgets locked versioncomparescomposer.lockcomposer.json
K$$p (+$ ($" !. (+$ 0"$ p/$Commit you composer.lock fileinto the repository, and usecomposer install.
D$p&!,)./ (! Pr!-2*()!.?
D$p&!,)./ (! Pr!-2*()!.?--no-dev
D$p&!,)./ (! Pr!-2*()!.?--no-dev--prefer-dist
D$p&!,)./ (! Pr!-2*()!.?--no-dev--prefer-dist--optimize-autoloader
I’" -$v$&!p)./  &)brr,, +$&p!how can composer spread my library around?
{"name": "vendor-namespace/package-name","type": "symfony-bundle","description": "A sample package for examples","keywords...
{"name": "vendor-namespace/package-name","type": "symfony-bundle","description": "A sample package for examples","keywords...
{"name": "vendor-namespace/package-name","type": "symfony-bundle","description": "A sample package for examples","keywords...
{"name": "vendor-namespace/package-name","type": "symfony-bundle","description": "A sample package for examples","keywords...
{"name": "vendor-namespace/package-name","type": "symfony-bundle","description": "A sample package for examples","keywords...
{"name": "vendor-namespace/package-name","type": "symfony-bundle","description": "A sample package for examples","keywords...
Q2)*5! I w.. p(*+ (+)0!B!!(0(rpp)./ L)brr, C!.(r)b2()!.
$ composer.phar create-project dms/dms --dev ~/dev/oss/dmsQ2)*5! I w.. p(*+ (+)0!B!!(0(rpp)./ L)brr, C!.(r)b2()!.
$ composer.phar create-project dms/dms --dev ~/dev/oss/dmsQ2)*5! I w.. p(*+ (+)0!B!!(0(rpp)./ L)brr, C!.(r)b2()!.is now de...
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 releasesX.Y.Z
Up/r-)./ (!  M$0(r!
B2( I .$$-  0p$*)6* v$r0)!.version modifiers to the rescue!
"acme/foo": "1.0.x-dev#3ebbe75"
"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"“#<ref>”: Get this specific commit“@<state>”: Get...
I .$$- (! 8$*2($  f$w 0*r)p(0how to automate tasks with Composer
    "scripts": {        "post-install-cmd": [            "Sensio...ComposerScriptHandler::buildBootstrap",            "Sen...
    "scripts": {        "post-install-cmd": [            "Sensio...ComposerScriptHandler::buildBootstrap",            "Sen...
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://github.com/rdohms/hero-superpackage"}...
“hero/superpackage”: “dev-master”    "repositories": [{"type": "vcs","url": "https://github.com/rdohms/hero-superpackage"}...
“hero/superpackage”: “dev-master”    "repositories": [{"type": "vcs","url": "https://github.com/rdohms/hero-superpackage"}...
{"repositories": [{"type": "package","package": {"name": "smarty/smarty","version": "3.1.7","dist": {"url": "http://www.sm...
{"repositories": [{"type": "package","package": {"name": "smarty/smarty","version": "3.1.7","dist": {"url": "http://www.sm...
{"repositories": [{"type": "package","package": {"name": "smarty/smarty","version": "3.1.7","dist": {"url": "http://www.sm...
I .$$- (+)0 PEAR p*5/$...No Problem!
{"repositories": [{"type": "pear","url": "http://pear2.php.net"}],"require": {"pear-pear2.php.net/PEAR2_Text_Markdown": "*...
{"repositories": [{"type": "pear","url": "http://pear2.php.net"}],"require": {"pear-pear2.php.net/PEAR2_Text_Markdown": "*...
{"repositories": [{"type": "pear","url": "http://pear2.php.net"}],"require": {"pear-pear2.php.net/PEAR2_Text_Markdown": "*...
{"repositories": [{"type": "pear","url": "http://pear2.php.net"}],"require": {"pear-pear2.php.net/PEAR2_Text_Markdown": "*...
1.-)./ ,!2r (2.$
I .$$-  &)brr, (+( -!$0..Let me get that for you
http://packagist.org/
versionspackage infousage info
$ composer.phar search filter
dms/dms-filter-bundle : DMS Filter Bundle, makes Annotationbased ...lexik/form-filter-bundle : This bundle aim to provide ...
$ composer.phar show dms/dms-filter-bundle
name : dms/dms-filter-bundledescrip. : DMS Filter Bundle, makes Annotation based entity filteringavailable in Symfonykeywo...
B2( ", r$p#)(!r, )0 pr)v($!Get your own package repository
S()0!
$ composer.phar create-project composer/satisR!&&!2( ,!2r !w. S()0
$ composer.phar create-project composer/satis$ vi packages.json{"name": "My Repository","homepage": "http://packages.examp...
$ composer.phar create-project composer/satis$ vi packages.json$ php bin/satis build config.json web/{"name": "My Reposito...
{"repositories": [{"type": "composer","url": "http://packages.yourdomain.net"}],“require”: {“myvendor/mypackage”: “dev-mas...
{"repositories": [{"type": "composer","url": "http://packages.yourdomain.net"}],“require”: {“myvendor/mypackage”: “dev-mas...
W+$r$ 0+!2&- I /$( +$&p?http://getcomposer.org#composer on irc.freenode.org
%$ E&$v(!r P)(*+Dependency Manager, consistent versions, per-projectEv$r,-, *!"p#)./install, update, lock and autoloadUp/r...
%.5 Y!2!http://slides.doh.mshttp://doh.ms@rdohmshttps://joind.in/8464
Composer for busy developers - DPC13
Composer for busy developers - DPC13
Upcoming SlideShare
Loading in...5
×

Composer for busy developers - DPC13

3,730

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.

Composer for busy developers - DPC13

  1. 1. C!"p#$rPutting your dependencies on the scoreRafael Dohms / @rdohms
  2. 2. photocredit:EliWhiteEvangelist, Speaker andContributor.Developer at WEBclusive.Enabler at AmsterdamPHP.Rafael Dohms@rdohms
  3. 3. photocredit:EliWhiteEvangelist, Speaker andContributor.Developer at WEBclusive.Enabler at AmsterdamPHP.Rafael Dohms@rdohms
  4. 4. %$ E&$v(!r P)(*+a general introduction to ComposerEv$r,-, *!"p#)./the basic stuff you need to knowUp/r-)./ (! M$0(r!advanced features for more complex scenarios1.-)./ ,!2r (2.$discovering and sharing libraries
  5. 5. %$ E&$v(!r P)(*+
  6. 6. per project system widecentral repositoryopen acceptancespread out channelsstrict standards
  7. 7. I need my team and my deployments touse consistent versions of thedependencies of my project
  8. 8. The Evolution of Vendor Management
  9. 9. copy & paste
  10. 10. copy & pastePEAR
  11. 11. copy & pasteSVN ExternalsPEAR
  12. 12. copy & pasteSVN ExternalsGit SubmodulesPEAR
  13. 13. copy & pasteSymfony2vendor scriptSVN ExternalsGit SubmodulesPEAR
  14. 14. copy & pasteSymfony2vendor scriptSVN ExternalsGit SubmodulesPEARComposer!
  15. 15. A per-project dependencymanager that allows you todeclare a consistent list ofdependencies and versions foryour application, as well as aconsistent way of sharing yourlibraries and making themdiscoverable usingpackagist.org
  16. 16. Ev$r,-, C!"p#)./
  17. 17. I.0(&&)./ C!"p#$r$ curl -s http://getcomposer.org/installer | php$ curl -s http://getcomposer.org/installer | php -- --install-dir=binLocal (embed)Global
  18. 18. I.0(&&)./ C!"p#$r$ curl -s http://getcomposer.org/installer | php$ curl -s http://getcomposer.org/installer | php -- --install-dir=binLocal (embed)Global$ ln -s /usr/bin/composer.phar /usr/bin/composer3p:
  19. 19. I.0(&&)./ C!"p#$r
  20. 20. I.0(&&)./ C!"p#$r$ composer.phar --versionComposer version 7073d38
  21. 21. I.0(&&)./ C!"p#$r$ composer.phar --versionComposer version 7073d38php
  22. 22. K$$p )( 2p-($-!
  23. 23. K$$p )( 2p-($-!$ composer.phar self-updateUpdating to version 7073d38.Downloading: 100%
  24. 24. I’" b2)&-)./ Pr!4$*(How can composer manage your dependencies
  25. 25. C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0
  26. 26. C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject
  27. 27. C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json{"require": {"silex/silex": "~1.0"}}
  28. 28. C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json{"require": {"silex/silex": "~1.0"}}put this in your project root
  29. 29. C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json{"require": {"silex/silex": "~1.0"}}put this in your project root“require”: required packages andversionsadv. ex.: >=1.0.0,<1.2-dev or ~1.1
  30. 30. C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json{"require": {"silex/silex": "~1.0"}}put this in your project root“require”: required packages andversionsadv. ex.: >=1.0.0,<1.2-dev or ~1.1
  31. 31. C!"p#$r 101G$(()./ (+$ -$p$.-$.*)$0$ cd ~/dev/myproject$ vim composer.json$ composer.phar install{"require": {"silex/silex": "~1.0"}}put this in your project root“require”: required packages andversionsadv. ex.: >=1.0.0,<1.2-dev or ~1.1
  32. 32. Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cache- Installing symfony/routing (v2.2.1)Downloading: 100%- Installing symfony/http-foundation (v2.2.1)Downloading: 100%- Installing symfony/event-dispatcher (v2.2.1)Loading from cache- Installing symfony/http-kernel (v2.2.1)Downloading: 100%- Installing pimple/pimple (v1.0.2)Downloading: 100%- Installing silex/silex (v1.0.0)Downloading: 100%symfony/routing suggests installing symfony/config (2.2.*)symfony/routing suggests installing symfony/yaml (2.2.*)[...]silex/silex suggests installing symfony/dom-crawler (>=2.1,<2.4-dev)silex/silex suggests installing symfony/form (>= 2.1.4,<2.4-dev)Writing lock fileGenerating autoload files
  33. 33. Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cache- Installing symfony/routing (v2.2.1)Downloading: 100%- Installing symfony/http-foundation (v2.2.1)Downloading: 100%- Installing symfony/event-dispatcher (v2.2.1)Loading from cache- Installing symfony/http-kernel (v2.2.1)Downloading: 100%- Installing pimple/pimple (v1.0.2)Downloading: 100%- Installing silex/silex (v1.0.0)Downloading: 100%symfony/routing suggests installing symfony/config (2.2.*)symfony/routing suggests installing symfony/yaml (2.2.*)[...]silex/silex suggests installing symfony/dom-crawler (>=2.1,<2.4-dev)silex/silex suggests installing symfony/form (>= 2.1.4,<2.4-dev)Writing lock fileGenerating autoload filesyour dependency’sdependencies
  34. 34. Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cache- Installing symfony/routing (v2.2.1)Downloading: 100%- Installing symfony/http-foundation (v2.2.1)Downloading: 100%- Installing symfony/event-dispatcher (v2.2.1)Loading from cache- Installing symfony/http-kernel (v2.2.1)Downloading: 100%- Installing pimple/pimple (v1.0.2)Downloading: 100%- Installing silex/silex (v1.0.0)Downloading: 100%symfony/routing suggests installing symfony/config (2.2.*)symfony/routing suggests installing symfony/yaml (2.2.*)[...]silex/silex suggests installing symfony/dom-crawler (>=2.1,<2.4-dev)silex/silex suggests installing symfony/form (>= 2.1.4,<2.4-dev)Writing lock fileGenerating autoload filesyour dependencyyour dependency’sdependencies
  35. 35. Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cache- Installing symfony/routing (v2.2.1)Downloading: 100%- Installing symfony/http-foundation (v2.2.1)Downloading: 100%- Installing symfony/event-dispatcher (v2.2.1)Loading from cache- Installing symfony/http-kernel (v2.2.1)Downloading: 100%- Installing pimple/pimple (v1.0.2)Downloading: 100%- Installing silex/silex (v1.0.0)Downloading: 100%symfony/routing suggests installing symfony/config (2.2.*)symfony/routing suggests installing symfony/yaml (2.2.*)[...]silex/silex suggests installing symfony/dom-crawler (>=2.1,<2.4-dev)silex/silex suggests installing symfony/form (>= 2.1.4,<2.4-dev)Writing lock fileGenerating autoload filesyour dependencyyour dependency’sdependenciessuggestions of otherpackages, for furtherfeatures
  36. 36. “~1.0”V$r0)!.)./G$( (+$ -!(0 ). r!w“>=1.0”“>=1.0, <=1.1”“1.0.*”
  37. 37. “~1.0”V$r0)!.)./G$( (+$ -!(0 ). r!w“>=1.0”“>=1.0, <=1.1”“1.0.*”>=1.0, <2.0: BC Compatible releases
  38. 38. V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0
  39. 39. V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0“minimum-stability”: “stable”
  40. 40. V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0“minimum-stability”: “stable”No dev versions in dependency tree
  41. 41. V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0“minimum-stability”: “stable”No dev versions in dependency tree“dms/dms”: “1.0.0@dev”
  42. 42. V$r0)!.)./: D$vG$(()./ 0(b&$ !r -$v v$r0)!.0“minimum-stability”: “stable”No dev versions in dependency tree“dms/dms”: “1.0.0@dev”Allow this package to use unstable versions
  43. 43. Q2)*5! I +v$ . )-$!B!#(rpp)./ Pr!4$*(0
  44. 44. Q2)*5! I +v$ . )-$!B!#(rpp)./ Pr!4$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myproject
  45. 45. Q2)*5! I +v$ . )-$!B!#(rpp)./ Pr!4$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myprojectInstalling fabpot/silex-skeleton (v1.0.0)- Installing fabpot/silex-skeleton (v1.0.0)Downloading: 100%Created project in projectLoading composer repositories with package informationInstalling dependencies- Installing pimple/pimple (dev-master)Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be[...]symfony/routing suggests installing symfony/yaml (dev-master)[...]Writing lock fileGenerating autoload files
  46. 46. Q2)*5! I +v$ . )-$!B!#(rpp)./ Pr!4$*(0$ composer.phar create-project fabpot/silex-skeleton ~/dev/myprojectInstalling fabpot/silex-skeleton (v1.0.0)- Installing fabpot/silex-skeleton (v1.0.0)Downloading: 100%Created project in projectLoading composer repositories with package informationInstalling dependencies- Installing pimple/pimple (dev-master)Cloning d2cfa2f02f50abef65c238747c753a5f6786f6be[...]symfony/routing suggests installing symfony/yaml (dev-master)[...]Writing lock fileGenerating autoload filesmyproject/composer.jsoncomposer.lockconfig/console/src/templates/vendor/web/
  47. 47. A--)./ .$w R$q2)r$"$.(0$ composer.phar require symfony/yaml=~2.1.0
  48. 48. 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
  49. 49. H!w -! I 6.-/&!- (+$ 6&$0?PSR-0 and the modern autoloader
  50. 50. Composer generates anautoload file for all yourdependencies
  51. 51. Composer generates anautoload file for all yourdependenciesvendor/autoload.php
  52. 52. "autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibrary/functions.php"]},
  53. 53. "autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibrary/functions.php"]},“autoload”: describes the autoloading needed for your library
  54. 54. "autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibrary/functions.php"]},“autoload”: describes the autoloading needed for your library“psr-0”: PSR-0 Compatible libraries
  55. 55. "autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibrary/functions.php"]},“autoload”: describes the autoloading needed for your library“classmap”: Old PEAR packages and otherlibraries“psr-0”: PSR-0 Compatible libraries
  56. 56. "autoload": {    "psr-0": { "MyNamespace": "<root>" },"classmap": ["src/", "lib/", "Something.php"],"files": ["src/MyLibrary/functions.php"]},“autoload”: describes the autoloading needed for your library“classmap”: Old PEAR packages and otherlibraries“files”: for php functions or initializations“psr-0”: PSR-0 Compatible libraries
  57. 57. I .$$- ,!2r 0$rv$r (! +v$ (+$0$..C+$*5)./ 0,0($" -$p$.-$.*)$0
  58. 58. {"require": {"php": ">=5.3.3","ext-ldap": "*"}}I .$$- ,!2r 0$rv$r (! +v$ (+$0$..C+$*5)./ 0,0($" -$p$.-$.*)$0
  59. 59. {"require": {"php": ">=5.3.3","ext-ldap": "*"}}“php”: PHP version.I .$$- ,!2r 0$rv$r (! +v$ (+$0$..C+$*5)./ 0,0($" -$p$.-$.*)$0
  60. 60. {"require": {"php": ">=5.3.3","ext-ldap": "*"}}“php”: PHP version.“ext-*”: Presence of selectedextensionI .$$- ,!2r 0$rv$r (! +v$ (+$0$..C+$*5)./ 0,0($" -$p$.-$.*)$0
  61. 61. I’" 0*r$- !f @/r"p7r!/r""$r.. 0! I wr)($ ($0(0
  62. 62.     "require-dev": {        "phpunit/phpunit": "~3.7"    },I’" 0*r$- !f @/r"p7r!/r""$r.. 0! I wr)($ ($0(0
  63. 63.     "require-dev": {        "phpunit/phpunit": "~3.7"    },“require-dev”: only needed if you are going tocontribute/develop the library or appI’" 0*r$- !f @/r"p7r!/r""$r.. 0! I wr)($ ($0(0
  64. 64.     "require-dev": {        "phpunit/phpunit": "~3.7"    },“require-dev”: only needed if you are going tocontribute/develop the library or app$ composer.phar require --dev phpunit/phpunit: ~3.7I’" 0*r$- !f @/r"p7r!/r""$r.. 0! I wr)($ ($0(0
  65. 65.     "require-dev": {        "phpunit/phpunit": "~3.7"    },“require-dev”: only needed if you are going tocontribute/develop the library or app$ composer.phar require --dev phpunit/phpunit: ~3.7I’" 0*r$- !f @/r"p7r!/r""$r.. 0! I wr)($ ($0(0only required in development
  66. 66. I.0(&&)./, 2p-()./ .- "!v)./ !.how does Composer guarantee consistency
  67. 67. composer.json
  68. 68. “composer.json”: metadata and list of yourdependencies.composer.json
  69. 69. “composer.json”: metadata and list of yourdependencies.composer.lockcomposer.json
  70. 70. “composer.json”: metadata and list of yourdependencies.“composer.lock”: existing dependencies andcurrent commit hashes.composer.lockcomposer.json
  71. 71. composer.lockcomposer.json
  72. 72. updatecomposer.lockcomposer.json
  73. 73. update installcomposer.lockcomposer.json
  74. 74. update installreadscomposer.lockcomposer.json
  75. 75. update installreadsgets latestcomposer.lockcomposer.json
  76. 76. update installreadsgets latestwritescomposer.lockcomposer.json
  77. 77. update installreadsgets latestwritesreadscomposer.lockcomposer.json
  78. 78. update installreadsgets latestwritesreadscomparescomposer.lockcomposer.json
  79. 79. update installreadsgets latestwritesreadsgets locked versioncomparescomposer.lockcomposer.json
  80. 80. K$$p (+$ ($" !. (+$ 0"$ p/$Commit you composer.lock fileinto the repository, and usecomposer install.
  81. 81. D$p&!,)./ (! Pr!-2*()!.?
  82. 82. D$p&!,)./ (! Pr!-2*()!.?--no-dev
  83. 83. D$p&!,)./ (! Pr!-2*()!.?--no-dev--prefer-dist
  84. 84. D$p&!,)./ (! Pr!-2*()!.?--no-dev--prefer-dist--optimize-autoloader
  85. 85. I’" -$v$&!p)./ &)brr,, +$&p!how can composer spread my library around?
  86. 86. {"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",}
  87. 87. {"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",}“name”: this should be unique, pick agood one!
  88. 88. {"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",}“name”: this should be unique, pick agood one!“type”: will be used for moreadvanced “custom”installs
  89. 89. {"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",}“name”: this should be unique, pick agood one!“type”: will be used for moreadvanced “custom”installs“license”: very important!
  90. 90. {"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",}“name”: this should be unique, pick agood one!“type”: will be used for moreadvanced “custom”installs“license”: very important!“support”: point people the rightway.
  91. 91. {"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",}“name”: this should be unique, pick agood one!“type”: will be used for moreadvanced “custom”installs“license”: very important!“support”: point people the rightway.“target-dir”: great for installing sub-dir splits repositoriesex: Symfony Bundles: /Acme/Bundle/MyBundle
  92. 92. Q2)*5! I w.. p(*+ (+)0!B!!(0(rpp)./ L)brr, C!.(r)b2()!.
  93. 93. $ composer.phar create-project dms/dms --dev ~/dev/oss/dmsQ2)*5! I w.. p(*+ (+)0!B!!(0(rpp)./ L)brr, C!.(r)b2()!.
  94. 94. $ composer.phar create-project dms/dms --dev ~/dev/oss/dmsQ2)*5! I w.. p(*+ (+)0!B!!(0(rpp)./ L)brr, C!.(r)b2()!.is now default
  95. 95. T/ ,!2r r$&$0$0!use semver and always make tags for releases
  96. 96. T/ ,!2r r$&$0$0!use semver and always make tags for releasesX.Y.Z
  97. 97. Up/r-)./ (! M$0(r!
  98. 98. B2( I .$$- 0p$*)6* v$r0)!.version modifiers to the rescue!
  99. 99. "acme/foo": "1.0.x-dev#3ebbe75"
  100. 100. "acme/foo": "1.0.x-dev#3ebbe75"“#<ref>”: Get this specific commit
  101. 101. "acme/foo": "1.0.x-dev#3ebbe75""acme/foo": "@dev""acme/foo": "1.0.*@beta"“#<ref>”: Get this specific commit
  102. 102. "acme/foo": "1.0.x-dev#3ebbe75""acme/foo": "@dev""acme/foo": "1.0.*@beta"“#<ref>”: Get this specific commit“@<state>”: Get a version outsideyour default stability
  103. 103. I .$$- (! 8$*2($ f$w 0*r)p(0how to automate tasks with Composer
  104. 104.     "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"        ]    },
  105. 105.     "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"        ]    },“scripts”: allows you to run scripts at givenmoments
  106. 106. C20(!" R$p#)(!r)$0 !r .!C!"p#$r, w+( .!w?Injecting Composer into wild packages
  107. 107. “hero/superpackage”: “dev-master”
  108. 108. “hero/superpackage”: “dev-master”
  109. 109. “hero/superpackage”: “dev-master”
  110. 110. “hero/superpackage”: “dev-master”
  111. 111. “hero/superpackage”: “dev-master”    "repositories": [{"type": "vcs","url": "https://github.com/rdohms/hero-superpackage"}       ]
  112. 112. “hero/superpackage”: “dev-master”    "repositories": [{"type": "vcs","url": "https://github.com/rdohms/hero-superpackage"}       ]my fork
  113. 113. “hero/superpackage”: “dev-master”    "repositories": [{"type": "vcs","url": "https://github.com/rdohms/hero-superpackage"}       ]“repositories”: point to non-indexed,override existing or on-the-fly packagesmy fork
  114. 114. {"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/"}}}]}N!.-C!"p#$r P*5/$
  115. 115. {"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/"}}}]}“package”: on-the-fly package, injecting acomposer.jsonN!.-C!"p#$r P*5/$
  116. 116. {"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/"}}}]}SVN / Git“package”: on-the-fly package, injecting acomposer.jsonN!.-C!"p#$r P*5/$
  117. 117. I .$$- (+)0 PEAR p*5/$...No Problem!
  118. 118. {"repositories": [{"type": "pear","url": "http://pear2.php.net"}],"require": {"pear-pear2.php.net/PEAR2_Text_Markdown": "*","pear-pear2/PEAR2_HTTP_Request": "*"}}
  119. 119. {"repositories": [{"type": "pear","url": "http://pear2.php.net"}],"require": {"pear-pear2.php.net/PEAR2_Text_Markdown": "*","pear-pear2/PEAR2_HTTP_Request": "*"}}“pear”: official PEAR and custom PEARchannels
  120. 120. {"repositories": [{"type": "pear","url": "http://pear2.php.net"}],"require": {"pear-pear2.php.net/PEAR2_Text_Markdown": "*","pear-pear2/PEAR2_HTTP_Request": "*"}}“pear”: official PEAR and custom PEARchannelsRemember the prefix!
  121. 121. {"repositories": [{"type": "pear","url": "http://pear2.php.net"}],"require": {"pear-pear2.php.net/PEAR2_Text_Markdown": "*","pear-pear2/PEAR2_HTTP_Request": "*"}}“pear”: official PEAR and custom PEARchannelsRemember the prefix!Warning: PEAR causes a overhead of requests!!
  122. 122. 1.-)./ ,!2r (2.$
  123. 123. I .$$- &)brr, (+( -!$0..Let me get that for you
  124. 124. http://packagist.org/
  125. 125. versionspackage infousage info
  126. 126. $ composer.phar search filter
  127. 127. dms/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$ composer.phar search filter
  128. 128. $ composer.phar show dms/dms-filter-bundle
  129. 129. name : 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$ composer.phar show dms/dms-filter-bundle
  130. 130. B2( ", r$p#)(!r, )0 pr)v($!Get your own package repository
  131. 131. S()0!
  132. 132. $ composer.phar create-project composer/satisR!&&!2( ,!2r !w. S()0
  133. 133. $ 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}R!&&!2( ,!2r !w. S()0
  134. 134. $ composer.phar create-project composer/satis$ vi packages.json$ php bin/satis build config.json web/{"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}R!&&!2( ,!2r !w. S()0
  135. 135. {"repositories": [{"type": "composer","url": "http://packages.yourdomain.net"}],“require”: {“myvendor/mypackage”: “dev-master”}}U0)./ ,!2r !w. S()0
  136. 136. {"repositories": [{"type": "composer","url": "http://packages.yourdomain.net"}],“require”: {“myvendor/mypackage”: “dev-master”}}U0)./ ,!2r !w. S()0“composer”: use this just like it wasPackagist
  137. 137. W+$r$ 0+!2&- I /$( +$&p?http://getcomposer.org#composer on irc.freenode.org
  138. 138. %$ E&$v(!r P)(*+Dependency Manager, consistent versions, per-projectEv$r,-, *!"p#)./install, update, lock and autoloadUp/r-)./ (! M$0(r!post-install, overriding, PEAR integration, developer environment1.-)./ ,!2r (2.$Satis and Packagist
  139. 139. %.5 Y!2!http://slides.doh.mshttp://doh.ms@rdohmshttps://joind.in/8464

×