SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
Dependency management with
Composer
Jason Grimes / @jason_grimes / jason@grimesit.com
Triangle PHP - June 2013
Composer is a
dependency manager
for
PHP.
Like npm in Node,
or bundler in Ruby.
What are dependencies?
Third-party libraries
or other assets your project depends on
which are stored in a separate repository
from your project sources.
• Define dependencies in a version controlled
config file.
• Download & install them all with one
command.
• Have identical versions in all project
environments.
• Automate this part of your build process.
A dependency manager lets you:
ComposerPEAR
• Per-project
• Open inclusion
• Central repository
• System-wide
• Strict control
• Dispersed channels
vs
Composer is becoming the de-facto standard
Installing Composer:
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
Keeping Composer
up to date periodically:
$ sudo composer self-update
Updating to version
d498e73363f8dae5b9984bf84ff2a2ca27240925.
Downloading: 100%
Two main use cases:
• Managing dependencies in a project
• Distributing a library
Managing dependencies
in a project
Getting a dependency:
{
"require": {
"silex/silex": "~1.0"
}
}
$ cd ~/myproject
$ vim composer.json
$ composer install
$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing psr/log (1.0.0)
Loading from cache
- Installing symfony/routing (v2.3.0)
Loading from cache
- Installing symfony/debug (v2.3.1)
Downloading: 100%
- Installing symfony/http-foundation (v2.3.1)
Downloading: 100%
- Installing symfony/event-dispatcher (v2.3.0)
Loading from cache
- Installing symfony/http-kernel (v2.3.0)
Loading from cache
- Installing pimple/pimple (v1.0.2)
Loading from cache
- Installing silex/silex (v1.0.0)
Loading from cache
symfony/routing suggests installing symfony/config ()
...
Writing lock file
Generating autoload files
Packages are installed
in the vendor/ subdirectory
$ ls vendor
autoload.php
composer/
pimple/
psr/
silex/
symfony/
Specifying versions
"~1.2"
">=1.2,<2.0"
"1.2.*"
"1.2.3"
Recommended. “Up to next significant release.” (semver)
Only stable packages are installed by default.
Get a non-stable version like this:
{
"require": {
"silex/silex": "~1.0@dev"
},
}
Stability flags, in order of priority: dev, alpha, beta, RC, and stable.
To get the latest commit from the master branch:
{
"require": {
"silex/silex": "dev-master"
},
}
Ensuring identical versions
in all project environments
• composer.json - the config file.
Specifies versions as flexible patterns.
• composer.lock - the lock file.
Automatically written by composer.
Lists the exact versions that were installed.
Both files should be stored in version control.
Two important files:
• composer install - Install dependencies,
using the versions listed in composer.lock.
• composer update - Determine the latest
allowed versions, install them, and write the
version numbers to composer.lock.
Two important commands:
You can specify which packages to update,
leaving the others untouched:
$ composer update monolog/monolog
This can be useful when adding a new dependency.
composer update might break things.
Only run it in dev environments.
Commit composer.lock to version
control when you’re ready to deploy the
new versions.
Remember:
composer install ensures you have
the exact same versions as everyone else
using that composer.lock file.
Run composer install in your build
scripts.
Autoloading
Composer sets up autoloading of your
dependencies (for free).
Just include vendor/autoload.php:
<?php
require ‘vendor/autoload.php’;
$app = new SilexApplication();
You can also use composer to configure
autoloading for your own code.
{
"require": {...},
"autoload": {
"psr-0": {"MyApp": "src/"}
},
}
<?php
require ‘vendor/autoload.php’;
$app = new MyAppFoo(); // From src/MyApp/Foo.php
composer.json
Various autoloading conventions are supported.
"autoload": {
"psr-0": {
"MyAppTest": "src/test",
"MyApp_": "src",
"": "src/"
},
"classmap": ["src/", "lib/", "Something.php"],
"files": ["src/MyLibrary/functions.php"]
},
MyAppTestFooTest => src/test/MyApp/Test/FooTest.php
MyApp_Foo => src/MyApp/Foo.php
Foo => src/Foo.php
Search for classes in *.php and *.inc files in these locations,
and generate a key/value array mapping class names to files.
Explicitly load these files on every request.
You can generate the autoload files
without running an install or update:
$ composer dump-autoload
In production, you can generate a class map
for all classes, to optimize performance:
$ composer dump-autoload --optimize
Finding packages
https://packagist.org
$ composer search oauth2 server
adoy/oauth2 Light PHP wrapper for the OAuth 2.0 protocol (based on
OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)
drahak/oauth2 Nette OAuth2 Provider bundle
opauth/oauth2 Base OAuth2 strategy for Opauth
zircote/oauth2 OAuth2 Library, this is by no means complete nor is
the test coverage optimal, mileage may (will) vary.
friendsofsymfony/oauth2-php OAuth2 library
bshaffer/oauth2-server-php OAuth2 Server for PHP
league/oauth2-server A lightweight and powerful OAuth 2.0
authorization and resource server library with support for all the
core specification grants. This library will allow you to secure
your API with OAuth and allow your applications users to approve
apps that want to access their data from your API.
...
$ composer show league/oauth2-server
name : league/oauth2-server
descrip. : A lightweight and powerful OAuth 2.0 authorization and resource server
library with support for all the core specification grants. This library will
allow you to secure your API with OAuth and allow your applications users to
approve apps that want to access their data from your API.
keywords : authorization, api, Authentication, oauth, oauth2, server, resource
versions : dev-master, 2.1.1, 2.1, 2.0.5, 2.0.4, 2.0.3, 2.0.2, 2.0, 1.0.8, 1.0.7,
1.0.6, 1.0.5, 1.0.4, 1.0.3, 1.0.2, 1.0.1, 1.0.0, 0.4.2, 0.4.1, 0.4, 0.3.5, 0.3.4,
0.3.3, 0.3.2, 0.3.1, 0.3, 0.2.3, 0.2.2, 0.2.1, 0.2, dev-develop, dev-temp
type : library
license : MIT
source : [git] https://github.com/php-loep/oauth2-server.git 2.1.1
dist : [zip] https://api.github.com/repos/php-loep/oauth2-server/zipball/
2.1.1 2.1.1
names : league/oauth2-server, lncd/oauth2, league/oauth2server
autoload
psr-0
LeagueOAuth2Server => src/
requires
php >=5.3.0
requires (dev)
mockery/mockery >=0.7.2
suggests
zetacomponents/database Allows use of the build in PDO storage classes
replaces
lncd/oauth2 *
league/oauth2server *
Bootstrapping a project
$ composer create-project fabpot/silex-skeleton ~/myproject
create-project clones a project skeleton
and installs its dependencies.
$ composer create-project fabpot/silex-skeleton ~/myproject
Installing fabpot/silex-skeleton (v1.0.0)
- Installing fabpot/silex-skeleton (v1.0.0)
Downloading: 100%
Created project in /home/vagrant/myproject
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing psr/log (1.0.0)
Loading from cache
- Installing twig/twig (v1.13.1)
Downloading: 100%
- Installing symfony/icu (v1.2.0)
Downloading: 100%
- Installing symfony/intl (v2.3.1)
Downloading: 100%
...
symfony/twig-bridge suggests installing symfony/templating ()
...
Writing lock file
Generating autoload files
$ ls ~/myproject
cache/
composer.json
composer.lock
config/
console
logs/
src/
templates/
vendor/
web/
Adding another dependency
from the command line
$ composer require doctrine/dbal:~2.3
composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing doctrine/common (2.3.0)
Loading from cache
- Installing doctrine/dbal (2.3.4)
Loading from cache
Writing lock file
Generating autoload files
Distributing a library
Any directory with a composer.json file
is a package.
To be installable, a package just needs a
name:
{
"name": "myvendorname/my-package",
"require": {...}
}
Recommended info for composer.json
{
"name": "jasongrimes/silex-simpleuser",
"description": "A simple db-backed user provider for Silex.",
"keywords": ["silex", "user", "user provider"],
"homepage": "http://github.com/jasongrimes/silex-simpleuser",
"license": "MIT",
"authors": [
{"name": "Jason Grimes", "email": "jason@grimesit.com"}
],
"require": { ... },
"autoload": {
"psr-0": {"JGSimpleUser": "src/"}
},
"suggest": {
"monolog/monolog": "Allows more advanced logging."
}
}
Specify versions with tags in yourVCS.
Tags should match X.Y.Z or vX.Y.Z
with optional RC, beta, alpha or patch suffix.
1.0.0
v1.0.0
1.10.5-RC1
v4.4.4beta2
v2.0.0-alpha
v2.0.4-p1
“dev” versions are created automatically
for every branch
Branch names that look like versions
become {branch}-dev:
2.0 => 2.0.x-dev
1.2.x => 1.2.x-dev
Other branch names become
dev-{branch}:
master => dev-master
bugfix => dev-bugfix
Specifying system requirements
{
"require": {
...
"php": ">=5.3",
"ext-PDO": “~1.0@dev”,
"lib-openssl": "openssl"
}
}
Run composer show --platform for a list of
locally available platform packages.
Executing scripts with Composer
{
"scripts": {
"post-update-cmd": "MyVendorMyClass::postUpdate",
"post-package-install": [
"MyVendorMyClass::postPackageInstall"
],
"post-install-cmd": [
"MyVendorMyClass::warmCache",
"phpunit -c app/"
]
}
}
composer.json
Many other pre- and post- event hooks are supported.
Submitting to Packagist
https://packagist.org
If using github, add a service hook
Packagist will update whenever you push, instead of being crawled only once daily.
https://github.org
Custom repositories
Maintaining your own forks
When you fix a bug in a third-party library,
use your own fork until your fix gets accepted upstream.
{
"repositories": [
{
"type": "vcs",
"url": “https://github.com/jasongrimes/monolog”,
}
],
"require": {
"monolog/monolog": "dev-bugfix"
}
}
Your fork
Branch with your fix
Custom repos have priority over packagist, so your fork gets used instead of the original.
PEAR packages
{
"repositories": [
{
"type": "pear",
"url": "http://pear2.php.net"
}
],
"require": {
"pear-pear2.php.net/PEAR2_Text_Markdown": "*",
"pear-pear2/PEAR2_HTTP_Request": "*"
}
}
Non-composer packages
{
"repositories": [
{
"type": "package",
"package": {
"name": "smarty/smarty",
"version": "3.1.7",
"dist": {
"url": "http://smarty.net/Smarty-3.1.7.zip",
"type": "zip"
},
"source": {
"url": "http://smarty-php.googlecode.com/svn/",
"type": "svn",
"reference": "tags/Smarty_3_1_7/distribution/"
},
"autoload": {
"classmap": ["libs/"]
}
}
}
],
"require": {
"smarty/smarty": "3.1.*"
}
}
Private repositories
Use Satis to generate private Composer repositories.
$ composer create-project composer/satis --stability=dev
$ vim config.json
{
"repositories": [
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo" },
{ "type": "vcs", "url": "http://svn.example.org/private/repo" },
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" }
],
"require": {
"company/package": "*",
"company/package2": "*",
"company/package3": "2.0.0"
}
}
$ php bin/satis build config.json web/
Builds static repo
in web/
Use your private repo like any other:
{
"repositories": [ {
"type": "composer",
"url": "http://packages.example.org/"
} ],
"require": {
"company/package": "1.2.0",
"company/package2": "1.5.2",
"company/package3": "dev-master"
}
}
In conclusion...
• ...install dependencies not stored in your project’sVCS repo.
• ...ensure identical versions in all your project’s environments.
• ...handle autoloading.
• ...distribute your open source libraries.
• ...manage your private repositories.
Use Composer to:
Resources
• http://getcomposer.org
• https://packagist.org/
• #composer on freenode
Jason Grimes / @jason_grimes / jason@grimesit.com

Más contenido relacionado

La actualidad más candente

Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22Võ Duy Tuấn
 
Composer The Right Way - 010PHP
Composer The Right Way - 010PHPComposer The Right Way - 010PHP
Composer The Right Way - 010PHPRafael Dohms
 
Composer | PHP Dependency Manager
Composer | PHP Dependency ManagerComposer | PHP Dependency Manager
Composer | PHP Dependency ManagerUjjwal Ojha
 
Composer The Right Way #PHPjhb15
Composer The Right Way #PHPjhb15Composer The Right Way #PHPjhb15
Composer The Right Way #PHPjhb15Rafael Dohms
 
Composer the Right Way - MM16NL
Composer the Right Way - MM16NLComposer the Right Way - MM16NL
Composer the Right Way - MM16NLRafael Dohms
 
Composer the right way
Composer the right wayComposer the right way
Composer the right wayRafael Dohms
 
Composer the Right Way - PHPSRB16
Composer the Right Way - PHPSRB16Composer the Right Way - PHPSRB16
Composer the Right Way - PHPSRB16Rafael Dohms
 
Composer The Right Way
Composer The Right WayComposer The Right Way
Composer The Right WayRafael Dohms
 
Composer the right way - DPC15
Composer the right way - DPC15Composer the right way - DPC15
Composer the right way - DPC15Rafael Dohms
 
Composer the right way [SweetlakePHP]
Composer the right way [SweetlakePHP]Composer the right way [SweetlakePHP]
Composer the right way [SweetlakePHP]Rafael Dohms
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
DevOps Hackathon - Session 1: Vagrant
DevOps Hackathon - Session 1: VagrantDevOps Hackathon - Session 1: Vagrant
DevOps Hackathon - Session 1: VagrantAntons Kranga
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is DockerNick Belhomme
 
DevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of ChefDevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of ChefAntons Kranga
 
Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2Sergii Shymko
 
How to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org RepositoryHow to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org RepositoryTareq Hasan
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90minsLarry Cai
 
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Matthew McCullough
 

La actualidad más candente (20)

Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22
 
Composer The Right Way - 010PHP
Composer The Right Way - 010PHPComposer The Right Way - 010PHP
Composer The Right Way - 010PHP
 
Composer | PHP Dependency Manager
Composer | PHP Dependency ManagerComposer | PHP Dependency Manager
Composer | PHP Dependency Manager
 
Composer The Right Way #PHPjhb15
Composer The Right Way #PHPjhb15Composer The Right Way #PHPjhb15
Composer The Right Way #PHPjhb15
 
Composer the Right Way - MM16NL
Composer the Right Way - MM16NLComposer the Right Way - MM16NL
Composer the Right Way - MM16NL
 
Composer the right way
Composer the right wayComposer the right way
Composer the right way
 
Composer the Right Way - PHPSRB16
Composer the Right Way - PHPSRB16Composer the Right Way - PHPSRB16
Composer the Right Way - PHPSRB16
 
Composer The Right Way
Composer The Right WayComposer The Right Way
Composer The Right Way
 
Composer the right way - DPC15
Composer the right way - DPC15Composer the right way - DPC15
Composer the right way - DPC15
 
Composer the right way [SweetlakePHP]
Composer the right way [SweetlakePHP]Composer the right way [SweetlakePHP]
Composer the right way [SweetlakePHP]
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Maven 3.0 at Øredev
Maven 3.0 at ØredevMaven 3.0 at Øredev
Maven 3.0 at Øredev
 
DevOps Hackathon - Session 1: Vagrant
DevOps Hackathon - Session 1: VagrantDevOps Hackathon - Session 1: Vagrant
DevOps Hackathon - Session 1: Vagrant
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is Docker
 
DevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of ChefDevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of Chef
 
Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2
 
Composer
ComposerComposer
Composer
 
How to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org RepositoryHow to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org Repository
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
 
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
 

Destacado

Nebosh Oil and Gas opearational safety certificate (2)
Nebosh Oil and Gas opearational safety certificate (2)Nebosh Oil and Gas opearational safety certificate (2)
Nebosh Oil and Gas opearational safety certificate (2)Gulf Test Safety Consultancies
 
Krijesa të mrekullueshme. albanian (shqip)
Krijesa të mrekullueshme. albanian (shqip)Krijesa të mrekullueshme. albanian (shqip)
Krijesa të mrekullueshme. albanian (shqip)HarunyahyaAlbanian
 
AOA - Annual OMEL Conference Encourages Osteopathic Discourse
AOA - Annual OMEL Conference Encourages Osteopathic Discourse AOA - Annual OMEL Conference Encourages Osteopathic Discourse
AOA - Annual OMEL Conference Encourages Osteopathic Discourse Dr. Michael Thomas (Neurosurgeon)
 
The Monthly Lekhapara, July 2015
The Monthly Lekhapara, July 2015The Monthly Lekhapara, July 2015
The Monthly Lekhapara, July 2015Shahida Akhter
 
Js高级技巧
Js高级技巧Js高级技巧
Js高级技巧fool2fish
 
Η αγαπημένη μου πόλη
Η αγαπημένη μου πόληΗ αγαπημένη μου πόλη
Η αγαπημένη μου πόληdroula_
 
Open Educational Resources: Policy Implications
Open Educational Resources: Policy ImplicationsOpen Educational Resources: Policy Implications
Open Educational Resources: Policy ImplicationsOystein Johannessen
 
The Virtual Strike: on pitches in advertising
The Virtual Strike: on pitches in advertisingThe Virtual Strike: on pitches in advertising
The Virtual Strike: on pitches in advertisingZigurds Zakis
 
Presentación de Servicios Prevengest
Presentación de Servicios PrevengestPresentación de Servicios Prevengest
Presentación de Servicios PrevengestXavier Fillol de Blas
 
урок знам и мога
урок знам и могаурок знам и мога
урок знам и могаChavdara Veleva
 
DALLA DELUSIONE ALLA SPERANZA
DALLA DELUSIONE ALLA SPERANZADALLA DELUSIONE ALLA SPERANZA
DALLA DELUSIONE ALLA SPERANZASimone Tranquilli
 
Predavanje OpenIT 2011 - Beograd
Predavanje OpenIT 2011 - BeogradPredavanje OpenIT 2011 - Beograd
Predavanje OpenIT 2011 - BeogradIvan Rečević
 
Unityを使ったVRアプリ作成入門 ABCD2015金沢編
Unityを使ったVRアプリ作成入門 ABCD2015金沢編Unityを使ったVRアプリ作成入門 ABCD2015金沢編
Unityを使ったVRアプリ作成入門 ABCD2015金沢編kinneko
 
Social Media Success in International Student Recruitment
Social Media Success in International Student RecruitmentSocial Media Success in International Student Recruitment
Social Media Success in International Student RecruitmentMarty Bennett
 

Destacado (20)

Nebosh Oil and Gas opearational safety certificate (2)
Nebosh Oil and Gas opearational safety certificate (2)Nebosh Oil and Gas opearational safety certificate (2)
Nebosh Oil and Gas opearational safety certificate (2)
 
Krijesa të mrekullueshme. albanian (shqip)
Krijesa të mrekullueshme. albanian (shqip)Krijesa të mrekullueshme. albanian (shqip)
Krijesa të mrekullueshme. albanian (shqip)
 
AOA - Annual OMEL Conference Encourages Osteopathic Discourse
AOA - Annual OMEL Conference Encourages Osteopathic Discourse AOA - Annual OMEL Conference Encourages Osteopathic Discourse
AOA - Annual OMEL Conference Encourages Osteopathic Discourse
 
The Monthly Lekhapara, July 2015
The Monthly Lekhapara, July 2015The Monthly Lekhapara, July 2015
The Monthly Lekhapara, July 2015
 
Js高级技巧
Js高级技巧Js高级技巧
Js高级技巧
 
Η αγαπημένη μου πόλη
Η αγαπημένη μου πόληΗ αγαπημένη μου πόλη
Η αγαπημένη μου πόλη
 
Open Educational Resources: Policy Implications
Open Educational Resources: Policy ImplicationsOpen Educational Resources: Policy Implications
Open Educational Resources: Policy Implications
 
The Virtual Strike: on pitches in advertising
The Virtual Strike: on pitches in advertisingThe Virtual Strike: on pitches in advertising
The Virtual Strike: on pitches in advertising
 
Escritura creativa
Escritura creativaEscritura creativa
Escritura creativa
 
Presentación de Servicios Prevengest
Presentación de Servicios PrevengestPresentación de Servicios Prevengest
Presentación de Servicios Prevengest
 
Open il vol4
Open il vol4Open il vol4
Open il vol4
 
Suzuki adferdin god_uppskrift
Suzuki adferdin  god_uppskriftSuzuki adferdin  god_uppskrift
Suzuki adferdin god_uppskrift
 
урок знам и мога
урок знам и могаурок знам и мога
урок знам и мога
 
DALLA DELUSIONE ALLA SPERANZA
DALLA DELUSIONE ALLA SPERANZADALLA DELUSIONE ALLA SPERANZA
DALLA DELUSIONE ALLA SPERANZA
 
Predavanje OpenIT 2011 - Beograd
Predavanje OpenIT 2011 - BeogradPredavanje OpenIT 2011 - Beograd
Predavanje OpenIT 2011 - Beograd
 
Lucy redes sociales myspace
Lucy redes sociales myspaceLucy redes sociales myspace
Lucy redes sociales myspace
 
Unityを使ったVRアプリ作成入門 ABCD2015金沢編
Unityを使ったVRアプリ作成入門 ABCD2015金沢編Unityを使ったVRアプリ作成入門 ABCD2015金沢編
Unityを使ったVRアプリ作成入門 ABCD2015金沢編
 
Social Media Success in International Student Recruitment
Social Media Success in International Student RecruitmentSocial Media Success in International Student Recruitment
Social Media Success in International Student Recruitment
 
Boletín IV enero 2016
Boletín IV enero 2016Boletín IV enero 2016
Boletín IV enero 2016
 
Ta mnimeiaeinaigiromas167
Ta mnimeiaeinaigiromas167Ta mnimeiaeinaigiromas167
Ta mnimeiaeinaigiromas167
 

Similar a Dependency management with Composer

Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning TalkEric Johnson
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupaldrubb
 
Piattaforma Web Linux completa dai sorgenti
Piattaforma Web Linux completa dai sorgentiPiattaforma Web Linux completa dai sorgenti
Piattaforma Web Linux completa dai sorgentiGiulio Destri
 
Composer Best Practices
Composer Best PracticesComposer Best Practices
Composer Best PracticesAbid Malik
 
Composer Best Practices
Composer Best PracticesComposer Best Practices
Composer Best PracticesAbid Malik
 
Composer Best Practices.pdf
Composer Best Practices.pdfComposer Best Practices.pdf
Composer Best Practices.pdfAbid Malik
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guidevjvarenya
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Clark Everetts
 
Composer Tutorial (PHP Hampshire Sept 2013)
Composer Tutorial (PHP Hampshire Sept 2013)Composer Tutorial (PHP Hampshire Sept 2013)
Composer Tutorial (PHP Hampshire Sept 2013)James Titcumb
 
Managing your Drupal project with Composer
Managing your Drupal project with ComposerManaging your Drupal project with Composer
Managing your Drupal project with ComposerMatt Glaman
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 
Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Antonio Peric-Mazar
 
Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Micah Wood
 

Similar a Dependency management with Composer (20)

Composer
ComposerComposer
Composer
 
Composer
ComposerComposer
Composer
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning Talk
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupal
 
Piattaforma Web Linux completa dai sorgenti
Piattaforma Web Linux completa dai sorgentiPiattaforma Web Linux completa dai sorgenti
Piattaforma Web Linux completa dai sorgenti
 
Composer Best Practices
Composer Best PracticesComposer Best Practices
Composer Best Practices
 
Composer Best Practices
Composer Best PracticesComposer Best Practices
Composer Best Practices
 
Composer Best Practices.pdf
Composer Best Practices.pdfComposer Best Practices.pdf
Composer Best Practices.pdf
 
Composer
ComposerComposer
Composer
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guide
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Composer Tutorial (PHP Hampshire Sept 2013)
Composer Tutorial (PHP Hampshire Sept 2013)Composer Tutorial (PHP Hampshire Sept 2013)
Composer Tutorial (PHP Hampshire Sept 2013)
 
Managing your Drupal project with Composer
Managing your Drupal project with ComposerManaging your Drupal project with Composer
Managing your Drupal project with Composer
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 
Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19
 
Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0
 
Build server
Build serverBuild server
Build server
 
Composer: Dependency Manager for PHP
Composer: Dependency Manager for PHPComposer: Dependency Manager for PHP
Composer: Dependency Manager for PHP
 
HPC_MPI_CICD.pptx
HPC_MPI_CICD.pptxHPC_MPI_CICD.pptx
HPC_MPI_CICD.pptx
 

Último

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Último (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

Dependency management with Composer

  • 1. Dependency management with Composer Jason Grimes / @jason_grimes / jason@grimesit.com Triangle PHP - June 2013
  • 2. Composer is a dependency manager for PHP. Like npm in Node, or bundler in Ruby.
  • 3. What are dependencies? Third-party libraries or other assets your project depends on which are stored in a separate repository from your project sources.
  • 4. • Define dependencies in a version controlled config file. • Download & install them all with one command. • Have identical versions in all project environments. • Automate this part of your build process. A dependency manager lets you:
  • 5. ComposerPEAR • Per-project • Open inclusion • Central repository • System-wide • Strict control • Dispersed channels vs Composer is becoming the de-facto standard
  • 6. Installing Composer: $ curl -sS https://getcomposer.org/installer | php $ sudo mv composer.phar /usr/local/bin/composer
  • 7. Keeping Composer up to date periodically: $ sudo composer self-update Updating to version d498e73363f8dae5b9984bf84ff2a2ca27240925. Downloading: 100%
  • 8. Two main use cases: • Managing dependencies in a project • Distributing a library
  • 10. Getting a dependency: { "require": { "silex/silex": "~1.0" } } $ cd ~/myproject $ vim composer.json $ composer install
  • 11. $ composer install Loading composer repositories with package information Installing dependencies (including require-dev) - Installing psr/log (1.0.0) Loading from cache - Installing symfony/routing (v2.3.0) Loading from cache - Installing symfony/debug (v2.3.1) Downloading: 100% - Installing symfony/http-foundation (v2.3.1) Downloading: 100% - Installing symfony/event-dispatcher (v2.3.0) Loading from cache - Installing symfony/http-kernel (v2.3.0) Loading from cache - Installing pimple/pimple (v1.0.2) Loading from cache - Installing silex/silex (v1.0.0) Loading from cache symfony/routing suggests installing symfony/config () ... Writing lock file Generating autoload files
  • 12. Packages are installed in the vendor/ subdirectory $ ls vendor autoload.php composer/ pimple/ psr/ silex/ symfony/
  • 14. Only stable packages are installed by default. Get a non-stable version like this: { "require": { "silex/silex": "~1.0@dev" }, } Stability flags, in order of priority: dev, alpha, beta, RC, and stable. To get the latest commit from the master branch: { "require": { "silex/silex": "dev-master" }, }
  • 15. Ensuring identical versions in all project environments
  • 16. • composer.json - the config file. Specifies versions as flexible patterns. • composer.lock - the lock file. Automatically written by composer. Lists the exact versions that were installed. Both files should be stored in version control. Two important files:
  • 17. • composer install - Install dependencies, using the versions listed in composer.lock. • composer update - Determine the latest allowed versions, install them, and write the version numbers to composer.lock. Two important commands:
  • 18. You can specify which packages to update, leaving the others untouched: $ composer update monolog/monolog This can be useful when adding a new dependency.
  • 19. composer update might break things. Only run it in dev environments. Commit composer.lock to version control when you’re ready to deploy the new versions. Remember:
  • 20. composer install ensures you have the exact same versions as everyone else using that composer.lock file. Run composer install in your build scripts.
  • 22. Composer sets up autoloading of your dependencies (for free). Just include vendor/autoload.php: <?php require ‘vendor/autoload.php’; $app = new SilexApplication();
  • 23. You can also use composer to configure autoloading for your own code. { "require": {...}, "autoload": { "psr-0": {"MyApp": "src/"} }, } <?php require ‘vendor/autoload.php’; $app = new MyAppFoo(); // From src/MyApp/Foo.php composer.json
  • 24. Various autoloading conventions are supported. "autoload": { "psr-0": { "MyAppTest": "src/test", "MyApp_": "src", "": "src/" }, "classmap": ["src/", "lib/", "Something.php"], "files": ["src/MyLibrary/functions.php"] }, MyAppTestFooTest => src/test/MyApp/Test/FooTest.php MyApp_Foo => src/MyApp/Foo.php Foo => src/Foo.php Search for classes in *.php and *.inc files in these locations, and generate a key/value array mapping class names to files. Explicitly load these files on every request.
  • 25. You can generate the autoload files without running an install or update: $ composer dump-autoload In production, you can generate a class map for all classes, to optimize performance: $ composer dump-autoload --optimize
  • 28.
  • 29. $ composer search oauth2 server adoy/oauth2 Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15) drahak/oauth2 Nette OAuth2 Provider bundle opauth/oauth2 Base OAuth2 strategy for Opauth zircote/oauth2 OAuth2 Library, this is by no means complete nor is the test coverage optimal, mileage may (will) vary. friendsofsymfony/oauth2-php OAuth2 library bshaffer/oauth2-server-php OAuth2 Server for PHP league/oauth2-server A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API. ...
  • 30. $ composer show league/oauth2-server name : league/oauth2-server descrip. : A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API. keywords : authorization, api, Authentication, oauth, oauth2, server, resource versions : dev-master, 2.1.1, 2.1, 2.0.5, 2.0.4, 2.0.3, 2.0.2, 2.0, 1.0.8, 1.0.7, 1.0.6, 1.0.5, 1.0.4, 1.0.3, 1.0.2, 1.0.1, 1.0.0, 0.4.2, 0.4.1, 0.4, 0.3.5, 0.3.4, 0.3.3, 0.3.2, 0.3.1, 0.3, 0.2.3, 0.2.2, 0.2.1, 0.2, dev-develop, dev-temp type : library license : MIT source : [git] https://github.com/php-loep/oauth2-server.git 2.1.1 dist : [zip] https://api.github.com/repos/php-loep/oauth2-server/zipball/ 2.1.1 2.1.1 names : league/oauth2-server, lncd/oauth2, league/oauth2server autoload psr-0 LeagueOAuth2Server => src/ requires php >=5.3.0 requires (dev) mockery/mockery >=0.7.2 suggests zetacomponents/database Allows use of the build in PDO storage classes replaces lncd/oauth2 * league/oauth2server *
  • 32. $ composer create-project fabpot/silex-skeleton ~/myproject create-project clones a project skeleton and installs its dependencies.
  • 33. $ composer create-project fabpot/silex-skeleton ~/myproject Installing fabpot/silex-skeleton (v1.0.0) - Installing fabpot/silex-skeleton (v1.0.0) Downloading: 100% Created project in /home/vagrant/myproject Loading composer repositories with package information Installing dependencies (including require-dev) - Installing psr/log (1.0.0) Loading from cache - Installing twig/twig (v1.13.1) Downloading: 100% - Installing symfony/icu (v1.2.0) Downloading: 100% - Installing symfony/intl (v2.3.1) Downloading: 100% ... symfony/twig-bridge suggests installing symfony/templating () ... Writing lock file Generating autoload files
  • 35. Adding another dependency from the command line $ composer require doctrine/dbal:~2.3 composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) - Installing doctrine/common (2.3.0) Loading from cache - Installing doctrine/dbal (2.3.4) Loading from cache Writing lock file Generating autoload files
  • 37. Any directory with a composer.json file is a package. To be installable, a package just needs a name: { "name": "myvendorname/my-package", "require": {...} }
  • 38. Recommended info for composer.json { "name": "jasongrimes/silex-simpleuser", "description": "A simple db-backed user provider for Silex.", "keywords": ["silex", "user", "user provider"], "homepage": "http://github.com/jasongrimes/silex-simpleuser", "license": "MIT", "authors": [ {"name": "Jason Grimes", "email": "jason@grimesit.com"} ], "require": { ... }, "autoload": { "psr-0": {"JGSimpleUser": "src/"} }, "suggest": { "monolog/monolog": "Allows more advanced logging." } }
  • 39. Specify versions with tags in yourVCS. Tags should match X.Y.Z or vX.Y.Z with optional RC, beta, alpha or patch suffix. 1.0.0 v1.0.0 1.10.5-RC1 v4.4.4beta2 v2.0.0-alpha v2.0.4-p1
  • 40. “dev” versions are created automatically for every branch
  • 41. Branch names that look like versions become {branch}-dev: 2.0 => 2.0.x-dev 1.2.x => 1.2.x-dev
  • 42. Other branch names become dev-{branch}: master => dev-master bugfix => dev-bugfix
  • 43. Specifying system requirements { "require": { ... "php": ">=5.3", "ext-PDO": “~1.0@dev”, "lib-openssl": "openssl" } } Run composer show --platform for a list of locally available platform packages.
  • 44. Executing scripts with Composer { "scripts": { "post-update-cmd": "MyVendorMyClass::postUpdate", "post-package-install": [ "MyVendorMyClass::postPackageInstall" ], "post-install-cmd": [ "MyVendorMyClass::warmCache", "phpunit -c app/" ] } } composer.json Many other pre- and post- event hooks are supported.
  • 46. If using github, add a service hook Packagist will update whenever you push, instead of being crawled only once daily. https://github.org
  • 48. Maintaining your own forks When you fix a bug in a third-party library, use your own fork until your fix gets accepted upstream. { "repositories": [ { "type": "vcs", "url": “https://github.com/jasongrimes/monolog”, } ], "require": { "monolog/monolog": "dev-bugfix" } } Your fork Branch with your fix Custom repos have priority over packagist, so your fork gets used instead of the original.
  • 49. PEAR packages { "repositories": [ { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" } }
  • 50. Non-composer packages { "repositories": [ { "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://smarty.net/Smarty-3.1.7.zip", "type": "zip" }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/" }, "autoload": { "classmap": ["libs/"] } } } ], "require": { "smarty/smarty": "3.1.*" } }
  • 52. Use Satis to generate private Composer repositories. $ composer create-project composer/satis --stability=dev $ vim config.json { "repositories": [ { "type": "vcs", "url": "http://github.com/mycompany/privaterepo" }, { "type": "vcs", "url": "http://svn.example.org/private/repo" }, { "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" } ], "require": { "company/package": "*", "company/package2": "*", "company/package3": "2.0.0" } } $ php bin/satis build config.json web/ Builds static repo in web/
  • 53. Use your private repo like any other: { "repositories": [ { "type": "composer", "url": "http://packages.example.org/" } ], "require": { "company/package": "1.2.0", "company/package2": "1.5.2", "company/package3": "dev-master" } }
  • 55. • ...install dependencies not stored in your project’sVCS repo. • ...ensure identical versions in all your project’s environments. • ...handle autoloading. • ...distribute your open source libraries. • ...manage your private repositories. Use Composer to:
  • 56. Resources • http://getcomposer.org • https://packagist.org/ • #composer on freenode Jason Grimes / @jason_grimes / jason@grimesit.com