SlideShare a Scribd company logo
1 of 51
Download to read offline
COMPOSER
THERE'S	A	MODULE	(OR	LIBRARY)	FOR	THAT!
Presented	by	 	and	Rob	Loach Larry	Garfield
DEPENDENCY	MANAGEMENT	SUCKS
PHP	SUCKS	AT	SHARING
How	do	I	get	a	3rd	party	library?
How	do	I	load	its	code?
Does	it	depend	on	anything?
Where	do	I	put	the	files?
SHARING	IS	HOW	OPEN	SOURCE	WORKS
SUCKING	AT	SHARING	IS	HOW
OPEN	SOURCE	DIES
BUT	WE'RE	DRUPAL!
Drupal.org:	Great	for	modules,	nothing	else
Duplicate	work	elsewhere
Code	is	not	reusable
3RD	PARTY	CODE
Manually	download	into	your	module	and	pray
Manually	download	into	/libraries/	and	pray
Manually	setup	extra	hook
(...	and	pray)
"DO	IT	MANUALLY	AND	PRAY"
IS	FOR	LOSERS
WE'RE	BETTER	THAN	THAT,	RIGHT?
A	LITTLE	HISTORY
PEAR
PHP	Extension	and	Application	Repository
Founded	2000	on	the	"new"	PHP	4
Required	root	to	use	properly	(WTF?)
Complex	process	for	adding	packages
Easy	to	get	wrong
SYMFONY	2.0	&	PHPBB
Initial	alpha,	Symfony	Live	Paris,	February	2010
PHPBB:	We're	rebuilding	on	it!
Symfony2	uses	3rd	party	libs	(Doctrine,	Monolog)
DEPENDENCY	HELL
WE	NEED	A	DEPENDENCY	SYSTEM!
“It's	dumb	to	make	it	Symfony	specific”
—Jordi	Boggiano
APRIL	2011
Nils	Aderman	(PHPBB):	libzypp	->	PHP
Jordi	Boggiano	(Monolog):	Packagist,	less	sucky	front-end	fo
PEAR
WITH	THEIR	POWERS	COMBINED...
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.
UHH,	WHAT?
No	more	Copy/Paste	of	libraries
Resolves	dependencies
Each	project	defines	its	own	requirements
Performs	build	tasks
Like	module	.info	files,	but	for	any	library
SEPTEMBER	2011
1.	
2.	
3.	
4.	
5.	
6.	
Packagist.org
Monolog
Twig
Pirum
Swiftmailer
Pimple
Symfony
—	Jordi	Boggiano
“I'd	say	until	early	2012	it	was	pretty
unusable,	yet	people	used	it.	I	guess	that's
how	badly	it	was	needed.”
PACKAGE	COUNT
April	2013:	10,000	packages
(Not	just	Symfony!)
LIBRARIES
Some	of	the	libraries	available	via	Composer	include...
SYMFONY
PHP	framework	for	web	applications
http://symfony.com
ZEND	FRAMEWORK
PHP	framework	for	web	applications
http://framework.zend.com
PHPUNIT
Unit	testing	software	framework	for	PHP
http://phpunit.de
GUZZLE
HTTP	client	&	framework	for	building	RESTful	web	service
clients
http://guzzlephp.org
SOLARIUM
Solr	client	library	for	PHP
http://solarium-project.org
ELASTICA
Elasticsearch	search	engine/database	for	PHP
http://elastica.io
MONOLOG
Log	to	files,	sockets,	inboxes,	databases	and	various	web
services
https://github.com/seldaek/monolog
ASSETIC
JavaScript,	stylesheet,	and	image	asset	management
http://github.com/kriswallsmith/assetic
LET'S	DO	THIS
COMPOSER.JSON
Base	manifest	file	for	your	project
{
				"name":	"crell/mypackage",
				"description":	"This	package	provides	some	awesomeness.",
				"require":	{
								"guzzle/guzzle":	"3.4.*"
				},
				"autoload":	{
								"psr-0":	{
												"MyNameMyPackage":	"src/"
								}
				}
}
COMPOSER	INSTALL
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
FILE	SYSTEM
-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)
INDEX.PHP
require_once	__DIR__	.	'/vendor/autoload.php';
//	Every	class	is	now	yours	to	command!
//	Autoload	on	demand!	Your	work:	zero.
$client	=	new	GuzzleHttpClient('https://api.github.com');
$request	=	$client->get('/user')->setAuth('user',	'pass');
$response	=	$request->send();
echo	$response->getBody();
COMPOSER	UPDATE
Updates	all	installed	dependencies	to	the	latest	version
$	php	composer.phar	update
Loading	composer	repositories	with	package	information
Updating	dependencies
MORE	SCHEMA	OPTIONS
Schema	Documentation
{
				"license":	"MIT",
				"require":	{
								"php":	">=5.3.10",
								"guzzle/guzzle":	"3.4.*"
				},
				"require-dev":	{
								"phpunit/phpunit":	"3.7.*"
				},
				"suggest":	{
								"monolog/monolog":	"Advanced	logging	package"
				}
}
PRIVATE	REPOSITORIES
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"
		}
}
github.com/composer/satis
COMPOSER	FOR	DRUPAL
DRUSH	COMPOSER
Allows	running	Composer	commands	through	Drush
		$	drush	dl	composer-8.x
		$	drush	composer
												
drupal.org/project/composer
COMPOSER	AUTOLOAD
Automatically	loads	any	generated	Composer	files
	
	-	Jimmy	Berry drupal.org/project/composer_autoload
COMPOSER	MANAGER
Builds	Composer	files	from	module	composer.json	files
	-	Chris	Pliakas drupal.org/project/composer_manager
DRUSH	COMPOSER	MANAGER
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
COMPOSER	INSTALLERS
Facilitates	installation	of	Drupal	modules/themes/profiles
github.com/composer/installers
COMPOSER	INSTALLERS
Add	a	composer.json	file	in	your	module/theme	directory
Adding	these	to	each	module	is	cumbersome	though,	so	there	is...
{
		"name":	"dries/mymodule",
		"type":	"drupal-module",
		"require":	{
				"composer/installers":	"*"
		}
}
github.com/composer/installers
DRUPAL	PACKAGIST
Indexes	Drupal	themes/modules	for	installation	using	Satis
	-	
Still	very	early
{
		"repositories":	[
				{
						"type":	"composer",
						"url":	"http://drugist.espend.de"
				}
		],
		"require":	{
				"drupal/views":	"*"
		}
}
Haehnchen github.com/haehnchen/drupal-packagist
SPRINT:	FRIDAY
Sprint	with	the	community	on	Friday.	Tasks	for	every	skill	se
Mentors	are	available	for	new	contributors.
Optional	Friday	morning	workshop	will	help	you	set	up
community	tools.
Drupal	tag:	
	Follow	#composer @drupalmentoring
THANK	YOU
Evaluate	this	session	at:
portland2013.drupal.org/node/3468

More Related Content

Similar to Composer: There's a Module (or Library) for That

Introduction to new technologies in drupal 8
Introduction to new technologies in drupal 8Introduction to new technologies in drupal 8
Introduction to new technologies in drupal 8naxoc
 
PHP Doesn't Suck
PHP Doesn't SuckPHP Doesn't Suck
PHP Doesn't SuckJohn Hobbs
 
Php Symfony and software-life-cycle
Php Symfony and software-life-cyclePhp Symfony and software-life-cycle
Php Symfony and software-life-cycleSwatantra Kumar
 
How composer saved PHP
How composer saved PHPHow composer saved PHP
How composer saved PHPRyan Kilfedder
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorialknoppix
 
Bending the odoo learning curve - Odoo Experience 2015
Bending the odoo learning curve - Odoo Experience 2015Bending the odoo learning curve - Odoo Experience 2015
Bending the odoo learning curve - Odoo Experience 2015Daniel Reis
 
chapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfchapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfburasyacob012
 
Cakefest higher education
Cakefest higher educationCakefest higher education
Cakefest higher educationtherealphpdiddy
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Servicesroyans
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Servicesroyans
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to LaravelVin Lim
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13DanWooster1
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itRyan Weaver
 

Similar to Composer: There's a Module (or Library) for That (20)

Introduction to new technologies in drupal 8
Introduction to new technologies in drupal 8Introduction to new technologies in drupal 8
Introduction to new technologies in drupal 8
 
PHP Doesn't Suck
PHP Doesn't SuckPHP Doesn't Suck
PHP Doesn't Suck
 
Php Symfony and software-life-cycle
Php Symfony and software-life-cyclePhp Symfony and software-life-cycle
Php Symfony and software-life-cycle
 
معرفی و ساخت یک فریم‌ورک شخصی به کمک لاراول
معرفی و ساخت یک فریم‌ورک شخصی به کمک لاراولمعرفی و ساخت یک فریم‌ورک شخصی به کمک لاراول
معرفی و ساخت یک فریم‌ورک شخصی به کمک لاراول
 
How composer saved PHP
How composer saved PHPHow composer saved PHP
How composer saved PHP
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
 
Bending the odoo learning curve - Odoo Experience 2015
Bending the odoo learning curve - Odoo Experience 2015Bending the odoo learning curve - Odoo Experience 2015
Bending the odoo learning curve - Odoo Experience 2015
 
chapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfchapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdf
 
Cakefest higher education
Cakefest higher educationCakefest higher education
Cakefest higher education
 
LVPHP.org
LVPHP.orgLVPHP.org
LVPHP.org
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Services
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Services
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to Laravel
 
Php
PhpPhp
Php
 
composer_talk_20160209
composer_talk_20160209composer_talk_20160209
composer_talk_20160209
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
 
Apache Toree
Apache ToreeApache Toree
Apache Toree
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 

Recently uploaded

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 

Composer: There's a Module (or Library) for That