Stop making,start composing!
Using Composer for Drupal development
• CTO and partner at Reload! A/S
• Ding.Core team member
• Maintainer of wsdl2phpgenerator
• Interested in developer workflows automation and code quality.
• [email protected] / @kasperg
About me
• Drupal development agency
• 15 people
• Office in Frederiksberg
• Specialists in agile development, complex solutions, integrations and consultancy
• Clients include Danish Radio, IDA, Samvirke, STOFA, TV2 and others
What is wrong about Drush Make?
• Making is slow
• Making is frail
• Drush Make is not intended for rebuilding
Get off the island […] get involved in the wider PHP community, both to learn
from it and to share with it.
– Larry Garfield, Drupal Core contribuor, 31 December 2012
!
!
!
What is right about Drush Make
• Overview of used
projects
• Supports patching
• Support for non-Drupal
code
projects[feedback_simple][subdir] = contrib projects[feedback_simple][version] = 1.6 !projects[feeds][subdir] = contrib projects[feeds][version] = 2.0-alpha7 ; Support the use of summary on body fields. Summary here ; is the built-in teaser in Drupal. projects[feeds][patch][962912] = http://drupal.org/files/node-summary-mapper-962912-11.patch !libraries[chosen][download][type] = git libraries[chosen][download][url] = https://github.com/harvesthq/chosen.git libraries[chosen][download][revision] = v0.9.9
5 minute Composer crash course
What is Composer?Composer is a project dependency manager,
not a package manager.
!
Inspired by Ruby Bundler and Node.JS npm
!
Cross-platform compatible (Windows, Linux, and OSX)
Requires >= PHP 5.3.2 and
optionally Subversion, GIT, and/or Mercurial
!
Released in 2011 under the MIT license
Developed by: Nils Adermann and Jordi Boggiano
What does Composer do?
• Manages dependent
libraries
• Handles cascading
dependencies
• Declarative dependency
• Install and update
dependencies
• Autoload dependencies
{ "name": "kasperg/composer-demo", "description": "A demo Composer project", "require": { "silex/silex": "1.1.*" }, "authors": [ { "name": "Kasper Garnaes", "email": "[email protected]" } ] }
Live demo
Packagist
• Over 40.000 packages
• Default package repository for Composer
• Contains nearly every widely used open source PHP package
• Free accounts to register and maintain own packages
Composer vs. Drush Make
• Manages dependent
libraries
• Handles cascading
dependencies
• Declarative dependency
# composer.json { "require": { "silex/silex": "1.1.*" }, } !!!# drush.make api = 2 core = 7.x projects[ctools][version] = 1.4
By Carsten ten Brink, https://flic.kr/p/fX4XWL
Time to jump through some hoops
Lets get started!
Drupal Core
• Located in the root directory of the project
• Use Composer custom installers
• Example: Composer non-destructive archive installer
• https://github.com/azt3k/non-destructive-archive-installer
Modules and themes I
• Composer repository for Drupal projects
• Developed by Will MiltonLead technology architect, Promet Source
• http://static.drupal-packagist.org/v0.2.0/
• Source: https://github.com/winmillwill/drupal-parse-composer
Modules and themes II
• Package naming:drupal/[project-name]
• Version naming:[drupal-major-version]. [project-major-version]. [project-minor-version]
• http://static.drupal-packagist.org/v0.2.0/
• Source: https://github.com/winmillwill/drupal-parse-composer
Modules and themes III
• Move projects to the appropriate location using Composer Installers
• http://composer.github.io/installers/
• Supports individual projects and types including drupal-module, drupal-theme, drupal-profile, drupal-drush
Patches
• Composer does not support patching projects. It promotes a fork/pullrequest-based workflow.
• Use Composer Patches Plugin
• Developed for TYPO3
• https://github.com/netresearch/composer-patches-plugin
Libraries
• Packagist packages can be added through requires
• Includes PHP but also JS, CSS!
• Packages without composer support can be defined manually through composer.json
• Same approach applies for sandboxes
• Composer can support the same use cases as Drush Make in the development process and more through community work.
• Enables tapping into and sharing with the PHP community at large.
Wrap up
By Richard Paterson, https://flic.kr/p/6wnBHM
Project template
• Use a project template to get started and avoid repeating boilerplate configuration
• php composer.phar create-project reload/drupal-composer-project some-dir --stability dev —no-interaction
• https://github.com/reload/drupal-composer-project
Whats next?
Drupal composer repository
• drupal.org must provide an authoritative Composer repository for Drupal packages.
• Could replace updates.drupal.org over time.
• Until then: Continued work on static.drupal-packagist.org.
!
The Future of Drush
• Relevant as ever
• Reduced scope
• make and dl no longer
needed
What about Drupal 8?
• Already has a composer.json file
in the project root.
• Better directory structure makes things a lot easier.
• Drupal 8 core directory subslit can be used as a Composer package
• https://github.com/tstoeckler/drupal-core
!
!
https://github.com/reload/job-application
!
ALWAYS LOOKING FOR TALENTED DEVELOPERS