Composer introduction
Drupal and Composer relationship
Basic usage
slides.com/mikebarkas/drupal-composer
/live
Why do they use a conductor for their logo?
Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries.
wat?
It downloads stuff...
Run it from a shell terminal
Install it via a shell terminal
Composer allows you to declare the libraries your project needs
and it will manage (install/update) them for you.
The install command reads the composer.json file from the current directory, resolves the dependencies, and installs them into vendor
A central location where software is stored and managed called a repository.
The software repository is called:
Packagist is the main Composer repository.
https://packagist.org/
It aggregates public PHP packages installable with Composer.
This is where Composer looks to download the packages and libraries for your project.
Composer deals with "packages" or libraries, it manages them on a per-project basis, installing them in a directory named vendor inside your project.
By default it will never install anything globally. Thus, it is a dependency manager.
Dependency management is not unique to PHP, Composer, or Drupal
Ruby : Bundler http://bundler.io/
Javascript : NPM https://www.npmjs.com/
PHP : Composer https://getcomposer.org/
https://getcomposer.org/
https://packagist.org/
https://getcomposer.org/doc/
https://github.com/composer/composer
Why are you telling me about Composer ?
How does this relate to Drupal ?
Drupal 4
Drupal 5
Drupal 6
Functional programming paradigm
Community specific modules
Do it the "Drupal way"
Frameworks
Object oriented programming
Libraries
Composer
Other members of the open-source PHP community
to be more like the rest of the PHP community
The recent initiative by the Drupal community, with regards to version 8.
Increase use of frameworks
More object oriented
Utilize package manager
This is why you may think, Drupal 8 is soo... different.
http://drupal-composer.org/
Drupal's Packagist
https://groups.drupal.org/composer
for working with Composer
Composer
Composer Manager
Composer Generate
Composer Autoload
Drush utility for Drupal 8 only
Composer in relation to Drush Make
https://www.drupal.org/node/2471553
drush make =>
drush down-load =>
drush pm-update =>
composer install
composer require*
composer update
*composer require also updates your composer file
project-folder
composer.json
This file describes the dependencies of your project and may contain other metadata.
Require - Specify what vendor and package you want.
Package Names - Consists of vendor/package name.
Package Versions - Specify version of module/package. 1.0.*
Some basic commands:
It is a command line tool
What can composer do?
composer install
composer update
"require": {
"drupal/drupal": "7.*",
"drupal/ctools": "7.1.*",
"drupal/devel": "7.1.*",
"drupal/views": "7.3.*",
"drupal/module_filter": "7.2.*",
"drupal/admin_menu": "7.3.0-rc5"
}
"require": {
"vendor/package": "1.3.2",
"vendor/package2": "1.*",
"vendor/package3": "^2.0.3"
}
Many third-party plugins to extend Composer
"extra": {
"installer-paths": {
"www/": ["type:drupal-core"],
"www/sites/all/modules/contrib/{$name}/": ["type:drupal-module"],
"www/sites/all/themes/contrib/{$name}/": ["type:drupal-theme"],
"www/sites/all/libraries/{$name}/": ["type:drupal-library"],
"www/sites/all/drush/{$name}/": ["type:drupal-drush"],
"www/profiles/{$name}/": ["type:drupal-profile"]
},
"preserve-paths": [
"web/sites/all/modules/contrib",
"web/sites/all/themes/contrib",
"web/sites/all/libraries",
"web/sites/all/drush",
"web/sites/default/settings.php",
"web/sites/default/files"
]
}
Composer's command events are scripts that run a specific times.
Scripts are useful for running custom code when needed.
Examples:
pre-install-cmd
post-install-cmd
pre-update-cmd
post-update-cmd
custom-user-defined
"scripts": {
"post-install-cmd": "scripts/post-install.sh",
"pre-update-cmd": "scripts/backup-database.sh",
"install-drupal": "scripts/site-install.sh",
"generate-content": "scripts/generate-content.sh"
}
drupal-project
composer.json
scripts
database-backups
www