22. Benefits
‣
Updating dependency versions extremely simple
‣
Ensures your team is on the same page
‣
Easily declare project dependencies
Saturday, November 2, 13
23. Benefits
‣
Updating dependency versions extremely simple
‣
Ensures your team is on the same page
‣
Tons of excellent related features
‣
Easily declare project dependencies
Saturday, November 2, 13
31. Keeping up to Date
$ php composer.phar self-update
You are using the latest composer version.
or
$ composer self-update
You are using the latest composer version.
Saturday, November 2, 13
32. Keeping up to Date
$ php composer.phar self-update
You are using the latest composer version.
or
$ composer self-update
You are using the latest composer version.
(Always updates to the latest dev-master)
Saturday, November 2, 13
51. composer.lock
‣
List of exact versions installed
‣
Commit both composer.lock and composer.json
‣
install writes a dependency lock file
Saturday, November 2, 13
52. composer.lock
‣
List of exact versions installed
‣
Commit both composer.lock and composer.json
‣
install writes a dependency lock file
‣ composer
install now checks the lock file, not
composer.json
Saturday, November 2, 13
53. composer.lock
‣
List of exact versions installed
‣
Commit both composer.lock and composer.json
‣
install writes a dependency lock file
‣ composer
install now checks the lock file, not
composer.json
‣
Saturday, November 2, 13
Update dependencies with composer update
63. Adding New Dependencies
Or use the command line
composer require
$ composer require ircmaxell/password-compat:1.0.3
composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing ircmaxell/password-compat (1.0.3)
Downloading: 100%
Writing lock file
Generating autoload files
Saturday, November 2, 13
68. Autoloading
Don’t forget to add your own code!
{
"require": {
"monolog/monolog": "1.6.*@dev"
},
"autoload": {
"psr-0": {
"Beeblebrox": "src/"
}
}
}
Saturday, November 2, 13
69. Autoloading
Pro Tip
Grab an autoloader instance and
add more namespaces.
$loader = require 'vendor/autoload.php';
$loader->add('AcmeTest', __DIR__);
Saturday, November 2, 13
70. Kickstart a Project
composer create-project
$ composer create-project slim/slim-skeleton super-sweet-application
Installing slim/slim-skeleton (1.1.0)
- Installing slim/slim-skeleton (1.1.0)
Downloading: 100%
Created project in super-sweet-application
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing slim/slim (2.3.0)
Downloading: 100%
- Installing slim/extras (2.0.3)
Loading from cache
- Installing twig/twig (v1.13.1)
Loading from cache
Writing lock file
Generating autoload files
Saturday, November 2, 13
71. Little Bobby Tables as a Service
composer create-project jeremykendall/lbtaas lbtaas
Saturday, November 2, 13
72. Little Bobby Tables as a Service
http://lbtaas.dev
{
"status":"success",
"data":{
"name":"Exploits of a Mom",
"permalink":"http://xkcd.com/327/",
"image":"http://imgs.xkcd.com/comics/exploits_of_a_mom.png"
}
}
Saturday, November 2, 13
76. Libraries
‣
Making up examples is not my strong suit
‣
Everyone has written a library of some sort
Saturday, November 2, 13
77. Libraries
‣
Making up examples is not my strong suit
‣
Let’s walk through a real library . . .
‣
Everyone has written a library of some sort
Saturday, November 2, 13
78. Libraries
‣
Making up examples is not my strong suit
‣
Let’s walk through a real library . . .
‣
. . . and check out some awesome Composer features
‣
Everyone has written a library of some sort
Saturday, November 2, 13
91. require-dev
‣
Only applies to the root package
‣
Lists packages required for development (think tests)
Saturday, November 2, 13
92. require-dev
‣
Only applies to the root package
‣
Both install and update install require-dev by default
‣
Lists packages required for development (think tests)
Saturday, November 2, 13
93. require-dev
‣
Only applies to the root package
‣
Both install and update install require-dev by default
‣
(Use the --no-dev flag to skip installing dev
‣ dependencies)
Lists packages required for development (think tests)
Saturday, November 2, 13
97. bin
‣
A set of files that should be treated as binaries
‣
cli scripts to pass along to package users
Saturday, November 2, 13
98. bin
‣
A set of files that should be treated as binaries
‣
Installs binaries to vendor/bin for any project that
‣ depends on your project
cli scripts to pass along to package users
Saturday, November 2, 13
99. bin
‣
A set of files that should be treated as binaries
‣
Installs binaries to vendor/bin for any project that
‣ depends on your project
cli scripts to pass along to package users
‣
Saturday, November 2, 13
php-domain-parser uses a bin to update the local copy
of the public suffix list
103. scripts
‣
‣
Saturday, November 2, 13
Used to execute custom code during the Composer
execution process
PHP callback (defined as a static method) . . .
104. scripts
‣
Used to execute custom code during the Composer
execution process
‣
. . . or any command-line executable command
‣
PHP callback (defined as a static method) . . .
Saturday, November 2, 13
105. scripts
‣
Used to execute custom code during the Composer
execution process
‣
. . . or any command-line executable command
‣
Only scripts defined in the root composer.json are
‣ executed
PHP callback (defined as a static method) . . .
Saturday, November 2, 13
106. scripts
‣
Used to execute custom code during the Composer
execution process
‣
. . . or any command-line executable command
‣
Only scripts defined in the root composer.json are
‣ executed
PHP callback (defined as a static method) . . .
‣
Saturday, November 2, 13
If a script is defined in a dependency, you can use it in
your composer.json
111. scripts
‣
Named events include:
‣
pre- and post-install-cmd
‣
pre- and post-update-cmd
‣
Composer fires “named events” during execution
Saturday, November 2, 13
112. scripts
‣
Named events include:
‣
pre- and post-install-cmd
‣
pre- and post-update-cmd
‣
post-root-package-install
‣
Composer fires “named events” during execution
Saturday, November 2, 13
113. scripts
‣
Named events include:
‣
pre- and post-install-cmd
‣
pre- and post-update-cmd
‣
post-root-package-install
‣
Many more . . .
‣
Composer fires “named events” during execution
Saturday, November 2, 13
117. Running scripts
Execute Composer (script will execute if the named
event is triggered) or . . .
composer run-script <named event>
Saturday, November 2, 13
121. Push it to a VCS
‣
Saturday, November 2, 13
git, svn, or hg all work equally well
122. Push it to a VCS
‣
For the sake of simplicity I’ll assume git/github
‣
git, svn, or hg all work equally well
Saturday, November 2, 13
123. Push it to a VCS
‣
For the sake of simplicity I’ll assume git/github
‣
Package versions:
‣
git, svn, or hg all work equally well
Saturday, November 2, 13
124. Push it to a VCS
‣
For the sake of simplicity I’ll assume git/github
‣
Package versions:
‣
Tags are package versions (1.0.0, v2.5.4, etc)
‣
git, svn, or hg all work equally well
Saturday, November 2, 13
125. Push it to a VCS
‣
For the sake of simplicity I’ll assume git/github
‣
Package versions:
‣
Tags are package versions (1.0.0, v2.5.4, etc)
‣
Branches are dev versions (dev-{branchname},
‣ {branchname}-dev)
git, svn, or hg all work equally well
Saturday, November 2, 13
126. Push it to a VCS
‣
For the sake of simplicity I’ll assume git/github
‣
Package versions:
‣
Tags are package versions (1.0.0, v2.5.4, etc)
‣
Branches are dev versions (dev-{branchname},
‣ {branchname}-dev)
git, svn, or hg all work equally well
‣
Saturday, November 2, 13
For this reason, I strongly recommend using semantic
versioning: http://semver.org
132. Packagist
‣
(Aside: Search Packagist before “rolling your own”)
‣
Packages published there need no special settings in
‣ composer.json to be installable (see “repositories” key)
The main package repository for Composer
Saturday, November 2, 13
133. Packagist
‣
(Aside: Search Packagist before “rolling your own”)
‣
Packages published there need no special settings in
‣ composer.json to be installable (see “repositories” key)
The main package repository for Composer
‣
Saturday, November 2, 13
Submitting is dead simple
134. Packagist
‣
(Aside: Search Packagist before “rolling your own”)
‣
Packages published there need no special settings in
‣ composer.json to be installable (see “repositories” key)
The main package repository for Composer
‣
Create account, hit big green submit button
‣
Submitting is dead simple
Saturday, November 2, 13
141. Satis to the Rescue
‣
Saturday, November 2, 13
Static composer repository generator
142. Satis to the Rescue
‣
Lightweight, static file based version of Packagist
‣
Static composer repository generator
Saturday, November 2, 13
143. Satis to the Rescue
‣
Lightweight, static file based version of Packagist
‣
Simple to configure
‣
Static composer repository generator
Saturday, November 2, 13
144. Satis to the Rescue
‣
Lightweight, static file based version of Packagist
‣
Simple to configure
‣
Flexible
‣
Static composer repository generator
Saturday, November 2, 13
145. composer create-project composer/satis --stability=dev
$ composer create-project composer/satis --stability=dev --keep-vcs
Installing composer/satis (dev-master 059588ef0fd0977964ad13637e02012519686202)
- Installing composer/satis (dev-master master)
Cloning master
Created project in /Users/jkendall/dev/satis
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json . . .
- Installing symfony/process (dev-master 75c8101)
Cloning 75c810176f8e069714cef8696d7ecc3aa86e8168
- [ . . . ]
- Installing twig/twig (v1.13.1)
Loading from cache
symfony/console suggests installing symfony/event-dispatcher ()
Generating autoload files
Saturday, November 2, 13
157. Satis Demo Project
‣
See: https://github.com/jeremykendall/satis-demo
‣
Want to goof around with Satis?
Saturday, November 2, 13
158. Satis Demo Project
‣
See: https://github.com/jeremykendall/satis-demo
‣
Clone, follow instructions in README, and WIN
‣
Want to goof around with Satis?
Saturday, November 2, 13
159. Satis Demo Project
‣
See: https://github.com/jeremykendall/satis-demo
‣
Clone, follow instructions in README, and WIN
‣
Satis really is dead simple to set up
‣
Want to goof around with Satis?
Saturday, November 2, 13
171. Credits
‣
Thanks to TechCamp for having me
‣
Thanks to Rafael Dohms, the Composer presenter
Saturday, November 2, 13
172. Credits
‣
Thanks to TechCamp for having me
‣
Thanks to Jordi Boggiano, Nils Adermann, and the
‣ community for an amazing project (and all the
Thanks to Rafael Dohms, the Composer presenter
documentation I cribbed from)
Saturday, November 2, 13
173. Credits
‣
Thanks to TechCamp for having me
‣
Thanks to Jordi Boggiano, Nils Adermann, and the
‣ community for an amazing project (and all the
Thanks to Rafael Dohms, the Composer presenter
documentation I cribbed from)
‣
Saturday, November 2, 13
Thanks to our sponsors for help making this happen
174. Credits
‣
Thanks to TechCamp for having me
‣
Thanks to Jordi Boggiano, Nils Adermann, and the
‣ community for an amazing project (and all the
Thanks to Rafael Dohms, the Composer presenter
documentation I cribbed from)
‣
Thanks to all of you for being here
‣
Thanks to our sponsors for help making this happen
Saturday, November 2, 13