Composer, best thing for php

In php

Composer is a package manager for PHP libraries. I was switched to python/django for my projects, but Composer then later Laravel really make me switch back to Php.

Composer is the command-line utility with which you install packages. Many features and concepts are inspired by npm and Bundler, so you may recognize things here and there if you are familiar with those tools. It contains a dependency solver to be able to recursively resolve inter-package dependencies, a set of downloaders, installers and other fancy things.

Jordi Boggiano

Basic usage

To install Composer, you just need to download the composer.phar executable.

curl -sS https://getcomposer.org/installer | php

To check if Composer is working, just run the PHAR through php:

php composer.phar

This should give you a list of available commands.

Note: You can also perform the checks only without downloading Composer by using the –check option. For more information, just use –help.

curl -sS https://getcomposer.org/installer | php -- --help

composer.json

To start using Composer in your project, all you need is a composer.json file. This file describes the dependencies of your project and may contain other metadata as well.

The JSON format is quite easy to write. It allows you to define nested structures.

The require Key

The first (and often only) thing you specify in composer.json is the require key. You’re simply telling Composer which packages your project depends on.

{
“require”: {
“monolog/monolog”: “1.0.*”
}
}

As you can see, require takes an object that maps package names (e.g. monolog/monolog) to package versions (e.g. 1.0.*).

You can continue reading the documentation.

This post is anĀ edited version of this composer page, shared with the same MIT licence.

Recommended Posts

Leave a Comment

Contact Me

I'm not around right now. But you can send me an email and we'll get back to you, asap.

Not readable? Change text. captcha txt