Presented by Rob Loach and Larry Garfield
(... and pray)
It's dumb to make it Symfony specific
—Jordi Boggiano
Nils Aderman (PHPBB): libzypp -> PHP
Jordi Boggiano (Monolog): Packagist, less sucky front-end for PEAR
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
.info
files, but for any libraryI'd say until early 2012 it was pretty unusable, yet people used it. I guess that's how badly it was needed.
— Jordi Boggiano
April 2013: 10,000 packages
(Not just Symfony!)
Some of the libraries available via Composer include...
PHP framework for web applications
PHP framework for web applications
Unit testing software framework for PHP
HTTP client & framework for building RESTful web service clients
Solr client library for PHP
Elasticsearch search engine/database for PHP
Log to files, sockets, inboxes, databases and various web services
JavaScript, stylesheet, and image asset management
Base manifest file for your project
{
"name": "crell/mypackage",
"description": "This package provides some awesomeness.",
"require": {
"guzzle/guzzle": "3.4.*"
},
"autoload": {
"psr-0": {
"MyName\\MyPackage": "src/"
}
}
}
Installs all dependencies for your project
$ curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer successfully installed to: composer.phar
Use it: php composer.phar
$ php composer.phar install
-rw-rw-r-- composer.json (your composer file)
-rw-rw-r-- composer.lock (generated)
drwxrwxr-x src/ (your code)
drwxrwxr-x vendor/ (everyone else's code)
require_once __DIR__ . '/vendor/autoload.php';
// Every class is now yours to command!
// Autoload on demand! Your work: zero.
$client = new Guzzle\Http\Client('https://api.github.com');
$request = $client->get('/user')->setAuth('user', 'pass');
$response = $request->send();
echo $response->getBody();
Updates all installed dependencies to the latest version
$ php composer.phar update
Loading composer repositories with package information
Updating dependencies
{
"license": "MIT",
"require": {
"php": ">=5.3.10",
"guzzle/guzzle": "3.4.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"suggest": {
"monolog/monolog": "Advanced logging package"
}
}
Satis allows you to host your own Composer repositories
{
"repositories": [
{
"type": "composer",
"url": "http://packages.example.org/"
}
],
"require": {
"company/package": "1.2.0",
"company/package2": "1.5.2",
"company/package3": "dev-master"
}
}
Allows running Composer commands through Drush
$ drush dl composer-8.x
$ drush composer
drupal.org/project/composer
Automatically loads any generated Composer files
Jimmy Berry - drupal.org/project/composer_autoloadBuilds Composer files from module composer.json
files
Downloads and installs dependencies for Drupal modules
$ drush dl composer_manager monolog
$ drush en composer_manager monolog
$ drush composer-manager
Loading composer repositories with package information
Installing dependencies
- Installing psr/log (1.0.0)
Downloading: 100%
- Installing monolog/monolog (1.5.0)
Downloading: 100%
drupal.org/project/composer_manager
Facilitates installation of Drupal modules/themes/profiles
github.com/composer/installersAdd a composer.json file in your module/theme directory
{
"name": "dries/mymodule",
"type": "drupal-module",
"require": {
"composer/installers": "*"
}
}
github.com/composer/installers
Adding these to each module is cumbersome though, so there is...
Indexes Drupal themes/modules for installation using Satis
{
"repositories": [
{
"type": "composer",
"url": "http://drugist.espend.de"
}
],
"require": {
"drupal/views": "*"
}
}
Haehnchen - github.com/haehnchen/drupal-packagist
Still very early
Sprint with the community on Friday. Tasks for every skill set. Mentors are available for new contributors.
Optional Friday morning workshop will help you set up community tools.
Drupal tag: #composer Follow @drupalmentoringEvaluate this session at:
portland2013.drupal.org/node/3468