Tweaks per @igorw and @Seldaek. Biggest change is the capitalization of Composer (in these first 2 chapters so far) when we're talking about the actual library
parent
37b4edc25d
commit
caf29268be
|
@ -15,7 +15,7 @@ This idea is not new and Composer is strongly inspired by node's [npm](http://np
|
||||||
and ruby's [bundler](http://gembundler.com/). But there has not been such a tool
|
and ruby's [bundler](http://gembundler.com/). But there has not been such a tool
|
||||||
for PHP.
|
for PHP.
|
||||||
|
|
||||||
The problem that composer solves is this:
|
The problem that Composer solves is this:
|
||||||
|
|
||||||
a) You have a project that depends on a number of libraries.
|
a) You have a project that depends on a number of libraries.
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ b) Some of those libraries depend on other libraries .
|
||||||
c) You declare the things you depend on
|
c) You declare the things you depend on
|
||||||
|
|
||||||
d) Composer finds out which versions of which packages need to be installed, and
|
d) Composer finds out which versions of which packages need to be installed, and
|
||||||
install them (meaning it downloads them into your project).
|
installs them (meaning it downloads them into your project).
|
||||||
|
|
||||||
## Declaring dependencies
|
## Declaring dependencies
|
||||||
|
|
||||||
|
@ -47,16 +47,16 @@ any version beginning with `1.0`.
|
||||||
### 1) Downloading the Composer Executable
|
### 1) Downloading the Composer Executable
|
||||||
|
|
||||||
To actually get Composer, we need to do two things. The first one is installing
|
To actually get Composer, we need to do two things. The first one is installing
|
||||||
composer (again, this mean downloading it into your project):
|
Composer (again, this mean downloading it into your project):
|
||||||
|
|
||||||
$ curl -s http://getcomposer.org/installer | php
|
$ curl -s http://getcomposer.org/installer | php
|
||||||
|
|
||||||
This will just check a few PHP settings and then download `composer.phar` to
|
This will just check a few PHP settings and then download `composer.phar` to
|
||||||
your working directory. This file is the composer binary. It is a PHAR (PHP
|
your working directory. This file is the Composer binary. It is a PHAR (PHP
|
||||||
archive), which is an archive format for PHP which can be run on the command
|
archive), which is an archive format for PHP which can be run on the command
|
||||||
line, amongst other things.
|
line, amongst other things.
|
||||||
|
|
||||||
You can install composer to a specific directory by using the `--install-dir`
|
You can install Composer to a specific directory by using the `--install-dir`
|
||||||
option and providing a target directory (it can be an absolute or relative path):
|
option and providing a target directory (it can be an absolute or relative path):
|
||||||
|
|
||||||
$ curl -s http://getcomposer.org/installer | php -- --install-dir=bin
|
$ curl -s http://getcomposer.org/installer | php -- --install-dir=bin
|
||||||
|
@ -67,7 +67,7 @@ executable and invoke it without `php`.
|
||||||
|
|
||||||
### 2) Using Composer
|
### 2) Using Composer
|
||||||
|
|
||||||
Next, run the command the `install` command to calculate and download dependencies:
|
Next, run the command the `install` command to resolve and download dependencies:
|
||||||
|
|
||||||
$ php composer.phar install
|
$ php composer.phar install
|
||||||
|
|
||||||
|
@ -75,14 +75,14 @@ This will download monolog into the `vendor/monolog/monolog` directory.
|
||||||
|
|
||||||
## Autoloading
|
## Autoloading
|
||||||
|
|
||||||
Besides download the library, Composer also prepares an autoload file that's
|
Besides downloading the library, Composer also prepares an autoload file that's
|
||||||
capable of autoloading all of the classes in any of the libraries that it
|
capable of autoloading all of the classes in any of the libraries that it
|
||||||
downloads. To use it, just add the following line to your code's bootstrap
|
downloads. To use it, just add the following line to your code's bootstrap
|
||||||
process:
|
process:
|
||||||
|
|
||||||
require 'vendor/.composer/autoload.php';
|
require 'vendor/.composer/autoload.php';
|
||||||
|
|
||||||
Woh! Now starting using monolog! To keep learning more about Composer, keep
|
Woh! Now start using monolog! To keep learning more about Composer, keep
|
||||||
reading the "Basic Usage" chapter.
|
reading the "Basic Usage" chapter.
|
||||||
|
|
||||||
[Basic Usage](01-basic-usage.md) →
|
[Basic Usage](01-basic-usage.md) →
|
||||||
|
|
|
@ -2,26 +2,26 @@
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
To install composer, you just need to download the `composer.phar` executable.
|
To install Composer, you just need to download the `composer.phar` executable.
|
||||||
|
|
||||||
$ curl -s http://getcomposer.org/installer | php
|
$ curl -s http://getcomposer.org/installer | php
|
||||||
|
|
||||||
For the details, see the [Introduction](00-intro.md) chapter.
|
For the details, see the [Introduction](00-intro.md) chapter.
|
||||||
|
|
||||||
To check if composer is working, just run the PHAR through `php`:
|
To check if Composer is working, just run the PHAR through `php`:
|
||||||
|
|
||||||
$ php composer.phar
|
$ php composer.phar
|
||||||
|
|
||||||
This should give you a list of available commands.
|
This should give you a list of available commands.
|
||||||
|
|
||||||
> **Note:** You can also perform the checks only without downloading composer
|
> **Note:** You can also perform the checks only without downloading Composer
|
||||||
> by using the `--check` option. For more information, just use `--help`.
|
> by using the `--check` option. For more information, just use `--help`.
|
||||||
>
|
>
|
||||||
> $ curl -s http://getcomposer.org/installer | php -- --help
|
> $ curl -s http://getcomposer.org/installer | php -- --help
|
||||||
|
|
||||||
## `composer.json`: Project Setup
|
## `composer.json`: Project Setup
|
||||||
|
|
||||||
To start using composer in your project, all you need is a `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
|
file. This file describes the dependencies of your project and may contain
|
||||||
other metadata as well.
|
other metadata as well.
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ define nested structures.
|
||||||
### The `require` Key
|
### The `require` Key
|
||||||
|
|
||||||
The first (and often only) thing you specify in `composer.json` is the
|
The first (and often only) thing you specify in `composer.json` is the
|
||||||
`require` key. You're simply telling composer which packages your project
|
`require` key. You're simply telling Composer which packages your project
|
||||||
depends on.
|
depends on.
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -40,8 +40,8 @@ depends on.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
As you can see, `require` takes an object that maps **package names(()) (e.g. `monolog/monolog`)
|
As you can see, `require` takes an object that maps **package names** (e.g. `monolog/monolog`)
|
||||||
to ** package versions** (e.g. `1.0.*`).
|
to **package versions** (e.g. `1.0.*`).
|
||||||
|
|
||||||
### Package Names
|
### Package Names
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ file into your project root.
|
||||||
|
|
||||||
## `composer.lock` - The Lock File
|
## `composer.lock` - The Lock File
|
||||||
|
|
||||||
After installing the dependencies, composer writes the list of the exact
|
After installing the dependencies, Composer writes the list of the exact
|
||||||
versions it installed into a `composer.lock` file. This locks the project
|
versions it installed into a `composer.lock` file. This locks the project
|
||||||
to those specific versions.
|
to those specific versions.
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ same version of the dependencies.
|
||||||
If no `composer.json` lock file exists, it will read the dependencies and
|
If no `composer.json` lock file exists, it will read the dependencies and
|
||||||
versions from `composer.json` and create the lock file.
|
versions from `composer.json` and create the lock file.
|
||||||
|
|
||||||
This means that if any of the dependencies gets a new version, you won't be updated
|
This means that if any of the dependencies get a new version, you won't get the updates.
|
||||||
automatically. To update to the new version, use `update` command. This will fetch
|
automatically. To update to the new version, use `update` command. This will fetch
|
||||||
the latest matching versions (according to your `composer.json` file) and also update
|
the latest matching versions (according to your `composer.json` file) and also update
|
||||||
the lock file with the new version.
|
the lock file with the new version.
|
||||||
|
@ -117,7 +117,7 @@ the lock file with the new version.
|
||||||
|
|
||||||
## Packagist
|
## Packagist
|
||||||
|
|
||||||
[Packagist](http://packagist.org/) is the main composer repository. A composer
|
[Packagist](http://packagist.org/) is the main Composer repository. A Composer
|
||||||
repository is basically a package source: a place where you can get packages
|
repository is basically a package source: a place where you can get packages
|
||||||
from. Packagist aims to be the central repository that everybody uses. This
|
from. Packagist aims to be the central repository that everybody uses. This
|
||||||
means that you can automatically `require` any package that is available
|
means that you can automatically `require` any package that is available
|
||||||
|
@ -126,16 +126,16 @@ there.
|
||||||
If you go to the [packagist website](http://packagist.org/) (packagist.org),
|
If you go to the [packagist website](http://packagist.org/) (packagist.org),
|
||||||
you can browse and search for packages.
|
you can browse and search for packages.
|
||||||
|
|
||||||
Any open source project using composer should publish their packages on
|
Any open source project using Composer should publish their packages on
|
||||||
packagist. A library doesn't need to be on packagist to be used by composer,
|
packagist. A library doesn't need to be on packagist to be used by Composer,
|
||||||
but it makes life quite a bit simpler.
|
but it makes life quite a bit simpler.
|
||||||
|
|
||||||
## Autoloading
|
## Autoloading
|
||||||
|
|
||||||
For libraries that follow the [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)
|
For libraries that follow the [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)
|
||||||
naming standard, composer generates a
|
naming standard, Composer generates a `vendor/.composer/autoload.php` file
|
||||||
`vendor/.composer/autoload.php` file for autoloading. You can simply include
|
for autoloading. You can simply include this file and you will get autoloading
|
||||||
this file and you will get autoloading for free.
|
for free.
|
||||||
|
|
||||||
require 'vendor/.composer/autoload.php';
|
require 'vendor/.composer/autoload.php';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue