COMPOSERTHERES	A	MODULE	(OR	LIBRARY)	FOR	THAT!Presented	by	 	and	Rob	Loach Larry	Garfield
DEPENDENCY	MANAGEMENT	SUCKS
PHP	SUCKS	AT	SHARINGHow	do	I	get	a	3rd	party	library?How	do	I	load	its	code?Does	it	depend	on	anything?Where	do	I	put	the	...
SHARING	IS	HOW	OPEN	SOURCE	WORKSSUCKING	AT	SHARING	IS	HOWOPEN	SOURCE	DIES
BUT	WERE	DRUPAL!Drupal.org:	Great	for	modules,	nothing	elseDuplicate	work	elsewhereCode	is	not	reusable
3RD	PARTY	CODEManually	download	into	your	module	and	prayManually	download	into	/libraries/	and	prayManually	setup	extra	h...
"DO	IT	MANUALLY	AND	PRAY"IS	FOR	LOSERSWERE	BETTER	THAN	THAT,	RIGHT?
A	LITTLE	HISTORY
PEARPHP	Extension	and	Application	RepositoryFounded	2000	on	the	"new"	PHP	4Required	root	to	use	properly	(WTF?)Complex	pro...
SYMFONY	2.0	&	PHPBBInitial	alpha,	Symfony	Live	Paris,	February	2010PHPBB:	Were	rebuilding	on	it!Symfony2	uses	3rd	party	li...
DEPENDENCY	HELL
WE	NEED	A	DEPENDENCY	SYSTEM!“Its	dumb	to	make	it	Symfony	specific”—Jordi	Boggiano
APRIL	2011Nils	Aderman	(PHPBB):	libzypp	->	PHPJordi	Boggiano	(Monolog):	Packagist,	less	sucky	front-end	foPEAR
WITH	THEIR	POWERS	COMBINED...Composer	is	a	tool	for	dependency	management	in	PHP.	Itallows	you	to	declare	the	dependent	li...
UHH,	WHAT?No	more	Copy/Paste	of	librariesResolves	dependenciesEach	project	defines	its	own	requirementsPerforms	build	tasks...
SEPTEMBER	20111.	2.	3.	4.	5.	6.	Packagist.orgMonologTwigPirumSwiftmailerPimpleSymfony
—	Jordi	Boggiano“Id	say	until	early	2012	it	was	prettyunusable,	yet	people	used	it.	I	guess	thatshow	badly	it	was	needed.”
PACKAGE	COUNTApril	2013:	10,000	packages(Not	just	Symfony!)
LIBRARIESSome	of	the	libraries	available	via	Composer	include...
SYMFONYPHP	framework	for	web	applicationshttp://symfony.com
ZEND	FRAMEWORKPHP	framework	for	web	applicationshttp://framework.zend.com
PHPUNITUnit	testing	software	framework	for	PHPhttp://phpunit.de
GUZZLEHTTP	client	&	framework	for	building	RESTful	web	serviceclientshttp://guzzlephp.org
SOLARIUMSolr	client	library	for	PHPhttp://solarium-project.org
ELASTICAElasticsearch	search	engine/database	for	PHPhttp://elastica.io
MONOLOGLog	to	files,	sockets,	inboxes,	databases	and	various	webserviceshttps://github.com/seldaek/monolog
ASSETICJavaScript,	stylesheet,	and	image	asset	managementhttp://github.com/kriswallsmith/assetic
LETS	DO	THIS
COMPOSER.JSONBase	manifest	file	for	your	project{				"name":	"crell/mypackage",				"description":	"This	package	provides	so...
COMPOSER	INSTALLInstalls	all	dependencies	for	your	project$	curl	-sS	https://getcomposer.org/installer	|	phpAll	settings	c...
FILE	SYSTEM-rw-rw-r--	composer.json	(your	composer	file)-rw-rw-r--	composer.lock	(generated)drwxrwxr-x	src/										(your...
INDEX.PHPrequire_once	__DIR__	.	/vendor/autoload.php;//	Every	class	is	now	yours	to	command!//	Autoload	on	demand!	Your	wo...
COMPOSER	UPDATEUpdates	all	installed	dependencies	to	the	latest	version$	php	composer.phar	updateLoading	composer	reposito...
MORE	SCHEMA	OPTIONSSchema	Documentation{				"license":	"MIT",				"require":	{								"php":	">=5.3.10",								"guzzle/guz...
PRIVATE	REPOSITORIESSatis	allows	you	to	host	your	own	Composer	repositories{		"repositories":	[				{						"type":	"compose...
COMPOSER	FOR	DRUPAL
DRUSH	COMPOSERAllows	running	Composer	commands	through	Drush		$	drush	dl	composer-8.x		$	drush	composer												drupal....
COMPOSER	AUTOLOADAutomatically	loads	any	generated	Composer	files		-	Jimmy	Berry drupal.org/project/composer_autoload
COMPOSER	MANAGERBuilds	Composer	files	from	module	composer.json	files	-	Chris	Pliakas drupal.org/project/composer_manager
DRUSH	COMPOSER	MANAGERDownloads	and	installs	dependencies	for	Drupal	modules	$	drush	dl	composer_manager	monolog	$	drush	e...
COMPOSER	INSTALLERSFacilitates	installation	of	Drupal	modules/themes/profilesgithub.com/composer/installers
COMPOSER	INSTALLERSAdd	a	composer.json	file	in	your	module/theme	directoryAdding	these	to	each	module	is	cumbersome	though,...
DRUPAL	PACKAGISTIndexes	Drupal	themes/modules	for	installation	using	Satis	-	Still	very	early{		"repositories":	[				{				...
SPRINT:	FRIDAYSprint	with	the	community	on	Friday.	Tasks	for	every	skill	seMentors	are	available	for	new	contributors.Opti...
THANK	YOUEvaluate	this	session	at:portland2013.drupal.org/node/3468
Composer: There's a Module (or Library) for That
Composer: There's a Module (or Library) for That
Composer: There's a Module (or Library) for That
Composer: There's a Module (or Library) for That
Composer: There's a Module (or Library) for That
Composer: There's a Module (or Library) for That
Upcoming SlideShare
Loading in …5
×

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

1,241 views

Published on

Reinventing the wheel is always cumbersome.

There are already a vast amount of Drupal modules out there. Leveraging PEAR, Packagist, and the PHP community, it's now easier to broaden the functionality spectrum of your Drupal websites even more.

This session will introduce ways of integrating Drupal with the Composer package management system in order to take advantage of some of the best PHP libraries out there.

http://portland2013.drupal.org/node/3468
http://robloach.github.io/drupalcon2013/

Published in: Technology
  • Be the first to comment

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

  1. 1. COMPOSERTHERES A MODULE (OR LIBRARY) FOR THAT!Presented by and Rob Loach Larry Garfield
  2. 2. DEPENDENCY MANAGEMENT SUCKS
  3. 3. PHP SUCKS AT SHARINGHow do I get a 3rd party library?How do I load its code?Does it depend on anything?Where do I put the files?
  4. 4. SHARING IS HOW OPEN SOURCE WORKSSUCKING AT SHARING IS HOWOPEN SOURCE DIES
  5. 5. BUT WERE DRUPAL!Drupal.org: Great for modules, nothing elseDuplicate work elsewhereCode is not reusable
  6. 6. 3RD PARTY CODEManually download into your module and prayManually download into /libraries/ and prayManually setup extra hook(... and pray)
  7. 7. "DO IT MANUALLY AND PRAY"IS FOR LOSERSWERE BETTER THAN THAT, RIGHT?
  8. 8. A LITTLE HISTORY
  9. 9. PEARPHP Extension and Application RepositoryFounded 2000 on the "new" PHP 4Required root to use properly (WTF?)Complex process for adding packagesEasy to get wrong
  10. 10. SYMFONY 2.0 & PHPBBInitial alpha, Symfony Live Paris, February 2010PHPBB: Were rebuilding on it!Symfony2 uses 3rd party libs (Doctrine, Monolog)
  11. 11. DEPENDENCY HELL
  12. 12. WE NEED A DEPENDENCY SYSTEM!“Its dumb to make it Symfony specific”—Jordi Boggiano
  13. 13. APRIL 2011Nils Aderman (PHPBB): libzypp -> PHPJordi Boggiano (Monolog): Packagist, less sucky front-end foPEAR
  14. 14. WITH THEIR POWERS COMBINED...Composer is a tool for dependency management in PHP. Itallows you to declare the dependent libraries your projectneeds and it will install them in your project for you.
  15. 15. UHH, WHAT?No more Copy/Paste of librariesResolves dependenciesEach project defines its own requirementsPerforms build tasksLike module .info files, but for any library
  16. 16. SEPTEMBER 20111. 2. 3. 4. 5. 6. Packagist.orgMonologTwigPirumSwiftmailerPimpleSymfony
  17. 17. — Jordi Boggiano“Id say until early 2012 it was prettyunusable, yet people used it. I guess thatshow badly it was needed.”
  18. 18. PACKAGE COUNTApril 2013: 10,000 packages(Not just Symfony!)
  19. 19. LIBRARIESSome of the libraries available via Composer include...
  20. 20. SYMFONYPHP framework for web applicationshttp://symfony.com
  21. 21. ZEND FRAMEWORKPHP framework for web applicationshttp://framework.zend.com
  22. 22. PHPUNITUnit testing software framework for PHPhttp://phpunit.de
  23. 23. GUZZLEHTTP client & framework for building RESTful web serviceclientshttp://guzzlephp.org
  24. 24. SOLARIUMSolr client library for PHPhttp://solarium-project.org
  25. 25. ELASTICAElasticsearch search engine/database for PHPhttp://elastica.io
  26. 26. MONOLOGLog to files, sockets, inboxes, databases and various webserviceshttps://github.com/seldaek/monolog
  27. 27. ASSETICJavaScript, stylesheet, and image asset managementhttp://github.com/kriswallsmith/assetic
  28. 28. LETS DO THIS
  29. 29. COMPOSER.JSONBase manifest file for your project{ "name": "crell/mypackage", "description": "This package provides some awesomeness.", "require": { "guzzle/guzzle": "3.4.*" }, "autoload": { "psr-0": { "MyNameMyPackage": "src/" } }}
  30. 30. COMPOSER INSTALLInstalls all dependencies for your project$ curl -sS https://getcomposer.org/installer | phpAll settings correct for using ComposerDownloading...Composer successfully installed to: composer.pharUse it: php composer.phar$ php composer.phar install
  31. 31. 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 elses code)
  32. 32. INDEX.PHPrequire_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();
  33. 33. COMPOSER UPDATEUpdates all installed dependencies to the latest version$ php composer.phar updateLoading composer repositories with package informationUpdating dependencies
  34. 34. MORE SCHEMA OPTIONSSchema Documentation{ "license": "MIT", "require": { "php": ">=5.3.10", "guzzle/guzzle": "3.4.*" }, "require-dev": { "phpunit/phpunit": "3.7.*" }, "suggest": { "monolog/monolog": "Advanced logging package" }}
  35. 35. PRIVATE REPOSITORIESSatis 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
  36. 36. COMPOSER FOR DRUPAL
  37. 37. DRUSH COMPOSERAllows running Composer commands through Drush $ drush dl composer-8.x $ drush composer drupal.org/project/composer
  38. 38. COMPOSER AUTOLOADAutomatically loads any generated Composer files - Jimmy Berry drupal.org/project/composer_autoload
  39. 39. COMPOSER MANAGERBuilds Composer files from module composer.json files - Chris Pliakas drupal.org/project/composer_manager
  40. 40. DRUSH COMPOSER MANAGERDownloads 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
  41. 41. COMPOSER INSTALLERSFacilitates installation of Drupal modules/themes/profilesgithub.com/composer/installers
  42. 42. COMPOSER INSTALLERSAdd a composer.json file in your module/theme directoryAdding these to each module is cumbersome though, so there is...{ "name": "dries/mymodule", "type": "drupal-module", "require": { "composer/installers": "*" }}github.com/composer/installers
  43. 43. DRUPAL PACKAGISTIndexes 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
  44. 44. SPRINT: FRIDAYSprint with the community on Friday. Tasks for every skill seMentors are available for new contributors.Optional Friday morning workshop will help you set upcommunity tools.Drupal tag: Follow #composer @drupalmentoring
  45. 45. THANK YOUEvaluate this session at:portland2013.drupal.org/node/3468

×