+ All Categories
Home > Technology > Composer: There's a Module (or Library) for That

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

Date post: 01-Jul-2015
Category:
Upload: rob-loach
View: 977 times
Download: 2 times
Share this document with a friend
Description:
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/
51
COMPOSER THERE'S A MODULE (OR LIBRARY) FOR THAT! Presented by and Rob Loach Larry Garfield
Transcript
Page 1: Composer: There's a Module (or Library) for That

COMPOSERTHERE'SAMODULE(ORLIBRARY)FORTHAT!

Presentedby andRobLoach LarryGarfield

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

DEPENDENCYMANAGEMENTSUCKS

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

PHPSUCKSATSHARINGHowdoIgeta3rdpartylibrary?HowdoIloaditscode?Doesitdependonanything?WheredoIputthefiles?

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

SHARINGISHOWOPENSOURCEWORKS

SUCKINGATSHARINGISHOWOPENSOURCEDIES

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

BUTWE'REDRUPAL!Drupal.org:Greatformodules,nothingelseDuplicateworkelsewhereCodeisnotreusable

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

3RDPARTYCODEManuallydownloadintoyourmoduleandprayManuallydownloadinto/libraries/andprayManuallysetupextrahook

(...andpray)

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

"DOITMANUALLYANDPRAY"ISFORLOSERS

WE'REBETTERTHANTHAT,RIGHT?

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

ALITTLEHISTORY

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

PEARPHPExtensionandApplicationRepositoryFounded2000onthe"new"PHP4Requiredroottouseproperly(WTF?)ComplexprocessforaddingpackagesEasytogetwrong

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

SYMFONY2.0&PHPBBInitialalpha,SymfonyLiveParis,February2010PHPBB:We'rerebuildingonit!Symfony2uses3rdpartylibs(Doctrine,Monolog)

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

DEPENDENCYHELL

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

WENEEDADEPENDENCYSYSTEM!“It'sdumbtomakeitSymfonyspecific”

—JordiBoggiano

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

APRIL2011NilsAderman(PHPBB):libzypp->PHP

JordiBoggiano(Monolog):Packagist,lesssuckyfront-endforPEAR

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

WITHTHEIRPOWERSCOMBINED...ComposerisatoolfordependencymanagementinPHP.Itallowsyoutodeclarethedependentlibrariesyourprojectneedsanditwillinstalltheminyourprojectforyou.

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

UHH,WHAT?NomoreCopy/PasteoflibrariesResolvesdependenciesEachprojectdefinesitsownrequirementsPerformsbuildtasksLikemodule.infofiles,butforanylibrary

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

SEPTEMBER2011

1.2.3.4.5.6.

Packagist.orgMonologTwigPirumSwiftmailerPimpleSymfony

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

—JordiBoggiano

“I'dsayuntilearly2012itwasprettyunusable,yetpeopleusedit.Iguessthat's

howbadlyitwasneeded.”

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

PACKAGECOUNT

April2013:10,000packages(NotjustSymfony!)

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

LIBRARIESSomeofthelibrariesavailableviaComposerinclude...

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

SYMFONYPHPframeworkforwebapplications

http://symfony.com

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

ZENDFRAMEWORK

PHPframeworkforwebapplicationshttp://framework.zend.com

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

PHPUNIT

UnittestingsoftwareframeworkforPHPhttp://phpunit.de

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

GUZZLEHTTPclient&frameworkforbuildingRESTfulwebservice

clientshttp://guzzlephp.org

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

SOLARIUM

SolrclientlibraryforPHPhttp://solarium-project.org

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

ELASTICAElasticsearchsearchengine/databaseforPHP

http://elastica.io

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

MONOLOGLogtofiles,sockets,inboxes,databasesandvariousweb

serviceshttps://github.com/seldaek/monolog

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

ASSETICJavaScript,stylesheet,andimageassetmanagement

http://github.com/kriswallsmith/assetic

Page 30: Composer: There's a Module (or Library) for That
Page 31: Composer: There's a Module (or Library) for That
Page 32: Composer: There's a Module (or Library) for That

LET'SDOTHIS

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

COMPOSER.JSONBasemanifestfileforyourproject

{"name":"crell/mypackage","description":"Thispackageprovidessomeawesomeness.","require":{"guzzle/guzzle":"3.4.*"},"autoload":{"psr-0":{"MyName\\MyPackage":"src/"}}}

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

COMPOSERINSTALLInstallsalldependenciesforyourproject

$curl-sShttps://getcomposer.org/installer|phpAllsettingscorrectforusingComposerDownloading...

Composersuccessfullyinstalledto:composer.pharUseit:phpcomposer.phar$phpcomposer.pharinstall

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

FILESYSTEM-rw-rw-r--composer.json(yourcomposerfile)-rw-rw-r--composer.lock(generated)drwxrwxr-xsrc/(yourcode)drwxrwxr-xvendor/(everyoneelse'scode)

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

INDEX.PHPrequire_once__DIR__.'/vendor/autoload.php';

//Everyclassisnowyourstocommand!

//Autoloadondemand!Yourwork:zero.$client=newGuzzle\Http\Client('https://api.github.com');$request=$client->get('/user')->setAuth('user','pass');$response=$request->send();echo$response->getBody();

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

COMPOSERUPDATEUpdatesallinstalleddependenciestothelatestversion$phpcomposer.pharupdateLoadingcomposerrepositorieswithpackageinformationUpdatingdependencies

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

MORESCHEMAOPTIONSSchemaDocumentation

{"license":"MIT","require":{"php":">=5.3.10","guzzle/guzzle":"3.4.*"},"require-dev":{"phpunit/phpunit":"3.7.*"},"suggest":{"monolog/monolog":"Advancedloggingpackage"}}

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

PRIVATEREPOSITORIESSatisallowsyoutohostyourownComposerrepositories{"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

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

COMPOSERFORDRUPAL

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

DRUSHCOMPOSERAllowsrunningComposercommandsthroughDrush

$drushdlcomposer-8.x$drushcomposer

drupal.org/project/composer

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

COMPOSERAUTOLOADAutomaticallyloadsanygeneratedComposerfiles

-JimmyBerry drupal.org/project/composer_autoload

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

COMPOSERMANAGERBuildsComposerfilesfrommodulecomposer.jsonfiles

-ChrisPliakas drupal.org/project/composer_manager

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

DRUSHCOMPOSERMANAGERDownloadsandinstallsdependenciesforDrupalmodules$drushdlcomposer_managermonolog$drushencomposer_managermonolog$drushcomposer-managerLoadingcomposerrepositorieswithpackageinformationInstallingdependencies-Installingpsr/log(1.0.0)Downloading:100%

-Installingmonolog/monolog(1.5.0)Downloading:100%

drupal.org/project/composer_manager

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

COMPOSERINSTALLERSFacilitatesinstallationofDrupalmodules/themes/profiles

github.com/composer/installers

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

COMPOSERINSTALLERSAddacomposer.jsonfileinyourmodule/themedirectory

Addingthesetoeachmoduleiscumbersomethough,sothereis...

{"name":"dries/mymodule","type":"drupal-module","require":{"composer/installers":"*"}}

github.com/composer/installers

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

DRUPALPACKAGISTIndexesDrupalthemes/modulesforinstallationusingSatis

-

Stillveryearly

{"repositories":[{"type":"composer","url":"http://drugist.espend.de"}],"require":{"drupal/views":"*"}}

Haehnchen github.com/haehnchen/drupal-packagist

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

SPRINT:FRIDAYSprintwiththecommunityonFriday.Tasksforeveryskillset.

Mentorsareavailablefornewcontributors.OptionalFridaymorningworkshopwillhelpyousetup

communitytools.Drupaltag: Follow#composer @drupalmentoring

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

THANKYOUEvaluatethissessionat:

portland2013.drupal.org/node/3468


Recommended