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.
4. %$ 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
15. A per-project dependency
manager that allows you to
declare a consistent list of
dependencies and versions for
your application, as well as a
consistent way of sharing your
libraries and making them
discoverable using
packagist.org
27. C!"p#$r 101
G$(()./ (+$ -$p$.-$.*)$0
$ cd ~/dev/myproject
$ vim composer.json
{
"require": {
"silex/silex": "~1.0"
}
}
28. C!"p#$r 101
G$(()./ (+$ -$p$.-$.*)$0
$ cd ~/dev/myproject
$ vim composer.json
{
"require": {
"silex/silex": "~1.0"
}
}
put this in your project root
29. C!"p#$r 101
G$(()./ (+$ -$p$.-$.*)$0
$ cd ~/dev/myproject
$ vim composer.json
{
"require": {
"silex/silex": "~1.0"
}
}
put this in your project root
“require”: required packages and
versions
adv. ex.: >=1.0.0,<1.2-dev or ~1.1
30. C!"p#$r 101
G$(()./ (+$ -$p$.-$.*)$0
$ cd ~/dev/myproject
$ vim composer.json
{
"require": {
"silex/silex": "~1.0"
}
}
put this in your project root
“require”: required packages and
versions
adv. ex.: >=1.0.0,<1.2-dev or ~1.1
31. C!"p#$r 101
G$(()./ (+$ -$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 and
versions
adv. ex.: >=1.0.0,<1.2-dev or ~1.1
41. V$r0)!.)./: D$v
G$(()./ 0('b&$ !r -$v v$r0)!.0
“minimum-stability”: “stable”
No dev versions in dependency tree
“dms/dms”: “1.0.0@dev”
42. V$r0)!.)./: D$v
G$(()./ 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
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. "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. "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 other
libraries
“psr-0”: PSR-0 Compatible libraries
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 other
libraries
“files”: for php functions or initializations
“psr-0”: PSR-0 Compatible libraries
65. "require-dev": {
"phpunit/phpunit": "~3.7"
},
“require-dev”: only needed if you are going to
contribute/develop the library or app
$ composer.phar require --dev phpunit/phpunit: ~3.7
I’" 0*'r$- !f @/r"p7r!/r'""$r
.. 0! I wr)($ ($0(0
only required in development
71. “composer.json”: metadata and list of your
dependencies.
“composer.lock”: existing dependencies and
current commit hashes.
composer.lock
composer.json
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 a
good one!
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 a
good one!
“type”: will be used for more
advanced “custom”installs
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 a
good one!
“type”: will be used for more
advanced “custom”installs
“license”: very important!
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 a
good one!
“type”: will be used for more
advanced “custom”installs
“license”: very important!
“support”: point people the right
way.
92. {
"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 a
good one!
“type”: will be used for more
advanced “custom”installs
“license”: very important!
“support”: point people the right
way.
“target-dir”: great for installing sub-dir splits repositories
ex: Symfony Bundles: /Acme/Bundle/MyBundle
93. Q2)*5! I w'..' p'(*+ (+)0!
B!!(0(r'pp)./ L)br'r, C!.(r)b2()!.
129. dms/dms-filter-bundle : DMS Filter Bundle, makes Annotation
based ...
lexik/form-filter-bundle : This bundle aim to provide classes to
build...
rollerworks/recordfilter-bundle : Record search-filtering bundle for
Symfony
brikou/zend_filter : Zend Framework Filter Library
ext-filter : The filter PHP extension
dms/dms-filter : DMS Library, includes various bundles
and ...
shtumi/useful-bundle : Symfony ShtumiUsefulBundle
$ composer.phar search filter
138. {
"repositories": [
{
"type": "composer",
"url": "http://packages.yourdomain.net"
}
],
“require”: {
“myvendor/mypackage”: “dev-master”
}
}
U0)./ ,!2r !w. S'()0
“composer”: use this just like it was
Packagist
139. W+$r$ 0+!2&- I /$( +$&p?
http://getcomposer.org
#composer on irc.freenode.org