Composer

Preview:

Citation preview

ComposerThe Missing Package Manger for PHP

Why Bother ?

l As a developer, you want to use consistent version of libraries/dependencies and tools

l Consistent version across all team members

Composer

l Dependency Manager per project .

l Dependency manager for PHP like node has npm and ruby has builder .

l Can be installed inside project or globally as well

Installing ComposerLocally

$ curl -sS https://getcomposer.org/installer | phpGlobally

$ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer

Now You Can Use Composer

Composer

l How does Composer guarantee consistency?

Composer

Composer.Jsonl Require keyl Package Name : package versionl Package version constraints can vary from single , range ,

hypen etc l If you want to get alpha , beta etc , you can define its

stability level as well ( can be per dependency or for all dependencies)

Installing Dependencies

l To fetch the dependencies , run composer install command in your project directory, it will fetch all dependencies that are defined in your project.json file.

l All dependencies will be installed in vendor folder plus a composer.lock file will be generated

l Composer.lock file mentioned exactly which version is being used in project

l Its recommended to have this file in version control manager .

Why Composer.lock in Git or SVN?

Anyone who sets up the project will download the exact same version of the dependencies. Your CI server, production machines, other developers in your team, everything and everyone runs on the same dependencies, which mitigates the potential for bugs affecting only some parts of the deployments. Even if you develop alone, in six months when reinstalling the project you can feel confident the dependencies installed are still working even if your dependencies released many new versions since then.

Using Composer with Drupal

Existing Project:

l Execute composer installl Executing composer install will delete everything in your core directory and download the core version from the repository above. Any modifications in core will be lost.

New Project:

l Execute composer create-project drupal/drupal my_site_name 8.0.*@dev

l Executing the command will download drupal/drupal into a folder named my_site_name and then execute composer install.

Using Composer with Drupal

Composer with Wordpress

New Project : mkdir my-wordpress-project cd my-wordpress-project curl -sS https://getcomposer.org/installer | php

l In composer.json, after writing content of this file run l Composer install

Important Links

l http://www.smashingmagazine.com/2014/03/07/better-dependency-management-team-based-wordpress-projects-composer/

l https://roots.io/using-composer-with-wordpress/

Recommended