Composer
the right way
@rdohms
Rafael Dohms
photo: smileymanwithahat
photo: Rob Allen
Library Publisher
Library
Library Consumer
Packagist
photo: 18millionpixels
{
"require": {
"monolog/monolog": “2.0”
}
}
{
"name": “monolog/monolog”
...
}
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package monolog/monolog could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing psr/log (1.0.0)
Loading from cache
- Installing monolog/monolog (1.11.0)
Downloading: 100%
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
[...]
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
Writing lock file
Generating autoload files
___

~1.1
photo: 18millionpixels
discovery source
installation
Packagist
!
Vendor

Folder
"
Repository
#
composercomposer.json$
composer.lock$
2 054 229 509two billion, fifty-four million, two hundred and
twenty-nine thousand, five hundred and nine.
+
Stable!Go tell @seldaek, @naderman and the entire
composer team, thank you for all the
amazing work!
$ composer self-update
Production
$ composer self-update --snapshot
Development
$ composer self-update --preview
CI / Build
$ composer init
Library Publisher
$ composer require <vendor>/<package>
Library Consumer
$ composer require monolog/monolog
Tip
Using version ^1.11 for monolog/monolog
$ composer require monolog/monolog --sort-packages
Tip
$ composer remove monolog/monolog
Tip
removes packages and dependencies by default 

— beta 2
Library Publishers
Composer for
Library Publisher Unique vendor names
vendor / package
Library Publisher Unique vendor names
pick your own 

unique vendor
Library Publisher Unique vendor names
or join a collective
README$
CHANGELOG%
LICENSE&
Library Publisher What’s in your library?
' List relevant changes
' Make BC breaks prominent
' Show examples of how to upgrade
' Pick one that reflects your values
' choosealicense.com can help
' What problem does it solve?
' Usage examples
' Install instructions
' How can I contribute?
Library Publisher Semantic Versioning
1 . 2 3.major minor patch
API / BC
Breaks
New Features Bug Fixes
Library Publisher Tagging
Please, tag your
releases.
often!
Library Publisher “I'm out"
photo: nickwebb
Library Publisher “I'm out"
Click here and provide an alternative
Library Publisher “I'm out"
Pick the 

correct 

version
Library Publisher Pick a Version
*the asterisk○Library Publisher Pick a Version
~the tilde
Library Publisher Pick a Version
~1.2
>=1.2.0, <2.0.0
Library Publisher Pick a Version
)
~1.2.3
>=1.2.3, <1.3
Library Publisher Pick a Version
)
Yo @rdohms, I’m
really happy for you and
I’m gonna let you finish, but
the tilde operator is
totally old news.
^the caret
Library Publisher Pick a Version
1.2.3
>=1.2.3, <2.0.0
Library Publisher Pick a Version
)
^
)
0.3.0
>=0.3.0, <0.4.0
Library Publisher Pick a Version
^
)
Major Version Zero
"require": {
"zendframework/zend-stdlib": “2.1.*”,
"zendframework/zend-servicemanager": "2.1.*",
},
“require-dev": {
“phpunit/phpunit": “~3.7”
}
Library Publisher Pick a Version
"require": {
"zendframework/zend-stdlib": “^2.3”,
"zendframework/zend-servicemanager": “^2.3",
},
“require-dev": {
“phpunit/phpunit": “~4”
}
3rd party library
Your application
*
^2.1
Library Consumers
Composer for
Library Consumer Install or update?
install or update?
Library Consumer Install or update?
Make sure you have
installed the last
updates from other
developers.
?
install updateor
Library Consumer Install or update?
Make sure you have
installed the last
updates from other
developers.
?
install updateor
Library Consumer Install or update?
Deploying a new
release of your
application to
production.
?
install updateor
Library Consumer Install or update?
Deploying a new
release of your
application to
production.
?
install updateor
Library Consumer Install or update?
Checked out a new
project and want to
start coding.
?
install updateor
Library Consumer Install or update?
Checked out a new
project and want to
start coding.
?
install updateor
Library Consumer Install or update?
Grab new versions for
the dependencies of
your project.
?
install updateor
Library Consumer Install or update?
Grab new versions for
the dependencies of
your project.
?
install updateor
Your application
"
Public
Repository
#
Library Consumer Install or update?
composer.lock$
read grab version
check latest compatible release
update
composer install
composer update
no lock file? composer update
since beta2
Library Consumer Install or update?
commit your lock file
$ composer update —interactive (-i)
Tip
since beta1
$ composer why-not <package>
doctrine/doctrine-bundle 1.6.2 requires symfony/framework-bundle (~2.3|~3.0)
doctrine/doctrine-cache-bundle 1.3.0 requires symfony/doctrine-bridge (~2.2|~3.0)
doctrine/doctrine-fixtures-bundle 2.3.0 requires symfony/doctrine-bridge (~2.3|~3.0)
doctrine/doctrine-migrations-bundle dev-master requires symfony/framework-bundle (~2.3|~3.0)
doctrine/migrations dev-master requires symfony/yaml (~2.3|~3.0)
doctrine/orm v2.5.4 requires symfony/console (~2.5|~3.0)
friendsofsymfony/rest-bundle 1.7.7 requires symfony/http-kernel (^2.3.24|~3.0)
incenteev/composer-parameter-handler v2.1.2 requires symfony/yaml (~2.3|~3.0)
jms/serializer-bundle 1.1.0 requires symfony/framework-bundle (~2.3|~3.0)
knplabs/knp-paginator-bundle 2.5.1 requires symfony/framework-bundle (~2.3|~3.0)
kriswallsmith/assetic v1.3.2 requires symfony/process (~2.1|~3.0)
Tip
since beta1
$ composer outdated
composer/composer 1.0.3 1.1.0
filp/whoops 2.1.0 2.1.2
justinrainbow/json-schema 1.6.1 2.0.3
nikic/fast-route v0.7.0 v1.0.0
oscarotero/psr7-middlewares v3.14.3 v3.15.1
Tip
Pick the 

correct 

version
Library Consumer Version Selection
Library Consumer Version Selection
dev-master
Library Consumer Version Selection
Library Consumer Using forks
found a bug?
Library Consumer Using forks
$ composer install --prefer-source
Tip
Library Consumer Using forks
patch it,
fork it,
push it…
wait for it.
Library Consumer Using forks
symfony/symfony
rdohms/symfony
"repositories": [
{
"type": "vcs",
"url": "https://github.com/rdohms/symfony"
}
]
+
Library Consumer Using forks
Do not put
forked repositories

on packagist
,
Library Consumer Using forks
"require": {
"symfony/symfony": "dev-my-patch as 2.5.0"
}
Tip
Library Consumer Composer and deployments
Composer
and
production
Library Consumer Composer and deployments
$ composer install --prefer-dist --no-dev --optimize-autoloader
,
- Install same versions
- Uses information defined in the composer.lock file
$ composer install --prefer-dist --no-dev --optimize-autoloader
Library Consumer Composer and deployments
,
- Downloads distribution packages
- Can use local cache for previously downloaded
- No git required
$ composer install --prefer-dist --no-dev --optimize-autoloader
Library Consumer Composer and deployments
,
- Avoids download unnecessary developer libraries
$ composer install --prefer-dist --no-dev --optimize-autoloader
Library Consumer Composer and deployments
,
- Generates classmap from PSR-0/4 autoloaders
- Speeds up autoloading
Library Consumer Licensing
$ composer licenses
Name: __root__
Version: 1.0.0
Licenses: none
Dependencies:
doctrine/annotations v1.2.1 MIT
doctrine/cache v1.3.1 MIT
doctrine/collections v1.2 MIT
doctrine/common v2.4.2 MIT
doctrine/inflector v1.0 MIT
doctrine/lexer v1.0 MIT
psr/log 1.0.0 MIT
symfony/symfony v2.5.6 MIT
twig/twig v1.16.2 BSD-3-Clause
Tip
Library Consumer Simulating Environments
"config": {
"platform": {
"php": “5.6.2”,
“ext-mongodb”: “1.1”
}
},
Tip
Production
Server
.
Development
Server
.PHP
7.0
PHP
5.6
Library Consumer Simulating Environments
$ composer install —-ignore-platform-reqs
Tip
Library Consumer Private Packages and Proxy
Satis and Toran
composer Packagist
!
Your application
"
Public
Repository
#
Library Consumer Private Packages and Proxy
composer
Packagist
!
Your application
"
Public
Repository
#
Satis / Toran
!
Private
Repository
/
proxy
Library Consumer Private Packages and Proxy
Library Consumer Private Packages and Proxy
toranproxy.com
private repos, automatic packagist proxy
and support composer development
Library Consumer One last thing
One last thing…
Library Consumer pickle!
Library Consumer pickle!
$ pickle install memcache
https://wiki.php.net/rfc/pickle
https://github.com/FriendsOfPHP/pickle
Thank you.any questions?
0 http://slides.doh.ms
1 http://doh.ms
2 @rdohms

Composer the Right Way - MM16NL