2. A quick slide about Me
Eric Van Johnson
PHP Developer, Architect and an Organizer of SDPHP
● Github: https://github.com/shocm
● LinkedIn: http://www.linkedin.com/in/vanjohnson
● Joind.in: https://joind.in/user/view/1770
● Twitter: @shocm
● IRC: @shocm
● eric@sdphp.org
● Website: www.shocm.com
3. The Issues
● Your app depends on libraries
● There is maintenance to keep
these libraries up to date
● Libraries also have dependency
on other libraries
4. We’ve (php) tried to
address this issue before
PEAR : A Library for PHP
PHP Extension and Application Repository
Used by many developers
Problems with PEAR
● In general, PEAR is meant to be installed on a system level. Although with
some tweaking this can be avoided. However, using PEAR at a system
level can make it difficult to migrate code from system to system.
● There are a TON of PEAR Libraries and not all of them are very well
documented.
5. Enter Composer
What Does Composer Do?
● You tell Composer what libraries you want
● Composer then manages the libraries and the
dependencies for those libraries
● Installs everything for you
● Creates an autoloader
6. Installing Composer
You can install Composer in a local directory
using the command
curl -s https://getcomposer.org/installer | php
A more common practice is to install composer
globally
curl -s https://getcomposer.org/composer.phar
-o $HOME/local/bin/composer
chmod +x $HOME/local/bin/composer
This gives you access to
composer install
7. Using Composer
composer create-project laravel/laravel --prefer-dist
The above command downloads and installs the core
libraries for a Laravel Project. It also downloads and install
all the dependencies such as several symfony
components.
End result
8. The composer.json File
This is where a lot of magic
happens.
“require” is the key to the
strength of Composer. This
tells composer what core
libraries, and their versions,
you would like to install.
Composer then figures out
the dependencies and their
versions and installs them.
9. Where do these Packages
come from?
Packagist
Main Repository
https://packagist.org/
Create your own
with Satis
https://github.com/composer/satis
10. Autoloading
index.php
<?php
require ‘vendor/autoload.php’;
// You can now use your dependencies
// without requiring them
use
SymfonyComponentConsoleApplication;
11. Updating with Composer
To add a library, you can edit the composer.json file directly or
use the command-line
composer require vendor/package:2.* vendor/package2:dev-master
Then simply run
composer update
‘composer update’ will also update all the existing packages and
dependencies based on the composer.json configuration.
12. Summary
● Very Simple to Install and Implement
● Cool “Magical” dependency resolution
● You can make and contribute your own packages
● Composer autoloader make life easy and is PSR compliant
13. THANK YOU!
Eric Van Johnson
● Twitter: @shocm
● IRC: @shocm
● eric@sdphp.org
● Website: www.shocm.com