1
0
Fork 0

Add code-fences to examples for syntax highlighting

pull/3010/head
Jordi Boggiano 2014-05-19 12:17:07 +02:00
parent 0c343f925a
commit 0c85ca426d
14 changed files with 976 additions and 719 deletions

View File

@ -33,11 +33,13 @@ You decide to use [monolog](https://github.com/Seldaek/monolog). In order to
add it to your project, all you need to do is create a `composer.json` file add it to your project, all you need to do is create a `composer.json` file
which describes the project's dependencies. which describes the project's dependencies.
```json
{ {
"require": { "require": {
"monolog/monolog": "1.2.*" "monolog/monolog": "1.2.*"
} }
} }
```
We are simply stating that our project requires some `monolog/monolog` package, We are simply stating that our project requires some `monolog/monolog` package,
any version beginning with `1.2`. any version beginning with `1.2`.
@ -63,12 +65,16 @@ Linux and OSX.
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 means downloading it into your project): Composer (again, this means downloading it into your project):
$ curl -sS https://getcomposer.org/installer | php ```sh
curl -sS https://getcomposer.org/installer | php
```
> **Note:** If the above fails for some reason, you can download the installer > **Note:** If the above fails for some reason, you can download the installer
> with `php` instead: > with `php` instead:
$ php -r "readfile('https://getcomposer.org/installer');" | php ```sh
php -r "readfile('https://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
@ -78,7 +84,9 @@ 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 -sS https://getcomposer.org/installer | php -- --install-dir=bin ```sh
curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
```
#### Globally #### Globally
@ -88,8 +96,10 @@ executable and invoke it without `php`.
You can run these commands to easily access `composer` from anywhere on your system: You can run these commands to easily access `composer` from anywhere on your system:
$ curl -sS https://getcomposer.org/installer | php ```sh
$ mv composer.phar /usr/local/bin/composer curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
```
> **Note:** If the above fails due to permissions, run the `mv` line > **Note:** If the above fails due to permissions, run the `mv` line
> again with sudo. > again with sudo.
@ -123,21 +133,25 @@ just call `composer` from any directory in your command line.
Change to a directory on your `PATH` and run the install snippet to download Change to a directory on your `PATH` and run the install snippet to download
composer.phar: composer.phar:
```sh
C:\Users\username>cd C:\bin C:\Users\username>cd C:\bin
C:\bin>php -r "readfile('https://getcomposer.org/installer');" | php C:\bin>php -r "readfile('https://getcomposer.org/installer');" | php
```
> **Note:** If the above fails due to readfile, use the `http` url or enable php_openssl.dll in php.ini > **Note:** If the above fails due to readfile, use the `http` url or enable php_openssl.dll in php.ini
Create a new `composer.bat` file alongside `composer.phar`: Create a new `composer.bat` file alongside `composer.phar`:
```sh
C:\bin>echo @php "%~dp0composer.phar" %*>composer.bat C:\bin>echo @php "%~dp0composer.phar" %*>composer.bat
```
Close your current terminal. Test usage with a new terminal: Close your current terminal. Test usage with a new terminal:
```sh
C:\Users\username>composer -V C:\Users\username>composer -V
Composer version 27d8904 Composer version 27d8904
```
C:\Users\username>
## Using Composer ## Using Composer
@ -147,12 +161,16 @@ don't have a `composer.json` file in the current directory please skip to the
To resolve and download dependencies, run the `install` command: To resolve and download dependencies, run the `install` command:
$ php composer.phar install ```sh
php composer.phar install
```
If you did a global install and do not have the phar in that directory If you did a global install and do not have the phar in that directory
run this instead: run this instead:
$ composer install ```sh
composer install
```
Following the [example above](#declaring-dependencies), this will download Following the [example above](#declaring-dependencies), this will download
monolog into the `vendor/monolog/monolog` directory. monolog into the `vendor/monolog/monolog` directory.
@ -164,7 +182,9 @@ 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:
```php
require 'vendor/autoload.php'; require 'vendor/autoload.php';
```
Woah! Now start using monolog! To keep learning more about Composer, keep Woah! Now start using monolog! To keep learning more about Composer, keep
reading the "Basic Usage" chapter. reading the "Basic Usage" chapter.

View File

@ -4,20 +4,26 @@
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 -sS https://getcomposer.org/installer | php ```sh
curl -sS https://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 ```sh
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 -sS https://getcomposer.org/installer | php -- --help > ```sh
> curl -sS https://getcomposer.org/installer | php -- --help
> ```
## `composer.json`: Project Setup ## `composer.json`: Project Setup
@ -34,11 +40,13 @@ 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.
```json
{ {
"require": { "require": {
"monolog/monolog": "1.0.*" "monolog/monolog": "1.0.*"
} }
} }
```
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.*`).
@ -99,7 +107,9 @@ packages instead of doing per dependency you can also use the
To fetch the defined dependencies into your local project, just run the To fetch the defined dependencies into your local project, just run the
`install` command of `composer.phar`. `install` command of `composer.phar`.
$ php composer.phar install ```sh
php composer.phar install
```
This will find the latest version of `monolog/monolog` that matches the This will find the latest version of `monolog/monolog` that matches the
supplied version constraint and download it into the `vendor` directory. supplied version constraint and download it into the `vendor` directory.
@ -141,11 +151,15 @@ automatically. To update to the new version, use `update` command. This will fet
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.
$ php composer.phar update ```sh
php composer.phar update
```
If you only want to install or update one dependency, you can whitelist them: If you only want to install or update one dependency, you can whitelist them:
$ php composer.phar update monolog/monolog [...] ```sh
php composer.phar update monolog/monolog [...]
```
> **Note:** For libraries it is not necessarily recommended to commit the lock file, > **Note:** For libraries it is not necessarily recommended to commit the lock file,
> see also: [Libraries - Lock file](02-libraries.md#lock-file). > see also: [Libraries - Lock file](02-libraries.md#lock-file).
@ -171,25 +185,31 @@ For libraries that specify autoload information, Composer generates a
`vendor/autoload.php` file. You can simply include this file and you `vendor/autoload.php` file. You can simply include this file and you
will get autoloading for free. will get autoloading for free.
```php
require 'vendor/autoload.php'; require 'vendor/autoload.php';
```
This makes it really easy to use third party code. For example: If your This makes it really easy to use third party code. For example: If your
project depends on monolog, you can just start using classes from it, and they project depends on monolog, you can just start using classes from it, and they
will be autoloaded. will be autoloaded.
```php
$log = new Monolog\Logger('name'); $log = new Monolog\Logger('name');
$log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING)); $log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING));
$log->addWarning('Foo'); $log->addWarning('Foo');
```
You can even add your own code to the autoloader by adding an `autoload` field You can even add your own code to the autoloader by adding an `autoload` field
to `composer.json`. to `composer.json`.
```json
{ {
"autoload": { "autoload": {
"psr-4": {"Acme\\": "src/"} "psr-4": {"Acme\\": "src/"}
} }
} }
```
Composer will register a [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloader Composer will register a [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloader
for the `Acme` namespace. for the `Acme` namespace.
@ -205,8 +225,10 @@ Including that file will also return the autoloader instance, so you can store
the return value of the include call in a variable and add more namespaces. the return value of the include call in a variable and add more namespaces.
This can be useful for autoloading classes in a test suite, for example. This can be useful for autoloading classes in a test suite, for example.
```php
$loader = require 'vendor/autoload.php'; $loader = require 'vendor/autoload.php';
$loader->add('Acme\\Test\\', __DIR__); $loader->add('Acme\\Test\\', __DIR__);
```
In addition to PSR-4 autoloading, classmap is also supported. This allows In addition to PSR-4 autoloading, classmap is also supported. This allows
classes to be autoloaded even if they do not conform to PSR-4. See the classes to be autoloaded even if they do not conform to PSR-4. See the

View File

@ -12,12 +12,14 @@ libraries is that your project is a package without a name.
In order to make that package installable you need to give it a name. You do In order to make that package installable you need to give it a name. You do
this by adding a `name` to `composer.json`: this by adding a `name` to `composer.json`:
```json
{ {
"name": "acme/hello-world", "name": "acme/hello-world",
"require": { "require": {
"monolog/monolog": "1.0.*" "monolog/monolog": "1.0.*"
} }
} }
```
In this case the project name is `acme/hello-world`, where `acme` is the In this case the project name is `acme/hello-world`, where `acme` is the
vendor name. Supplying a vendor name is mandatory. vendor name. Supplying a vendor name is mandatory.
@ -62,9 +64,11 @@ version numbers are extracted from these.
If you are creating packages by hand and really have to specify it explicitly, If you are creating packages by hand and really have to specify it explicitly,
you can just add a `version` field: you can just add a `version` field:
```json
{ {
"version": "1.0.0" "version": "1.0.0"
} }
```
> **Note:** You should avoid specifying the version field explicitly, because > **Note:** You should avoid specifying the version field explicitly, because
> for tags the value must match the tag name. > for tags the value must match the tag name.
@ -78,12 +82,12 @@ a number.
Here are a few examples of valid tag names: Here are a few examples of valid tag names:
1.0.0 - 1.0.0
v1.0.0 - v1.0.0
1.10.5-RC1 - 1.10.5-RC1
v4.4.4beta2 - v4.4.4beta2
v2.0.0-alpha - v2.0.0-alpha
v2.0.4-p1 - v2.0.4-p1
> **Note:** Even if your tag is prefixed with `v`, a [version constraint](01-basic-usage.md#package-versions) > **Note:** Even if your tag is prefixed with `v`, a [version constraint](01-basic-usage.md#package-versions)
> in a `require` statement has to be specified without prefix > in a `require` statement has to be specified without prefix
@ -101,9 +105,9 @@ like a version, it will be `dev-{branchname}`. `master` results in a
Here are some examples of version branch names: Here are some examples of version branch names:
1.x - 1.x
1.0 (equals 1.0.x) - 1.0 (equals 1.0.x)
1.1.x - 1.1.x
> **Note:** When you install a development version, it will be automatically > **Note:** When you install a development version, it will be automatically
> pulled from its `source`. See the [`install`](03-cli.md#install) command > pulled from its `source`. See the [`install`](03-cli.md#install) command
@ -140,12 +144,14 @@ project locally. We will call it `acme/blog`. This blog will depend on
accomplish this by creating a new `blog` directory somewhere, containing a accomplish this by creating a new `blog` directory somewhere, containing a
`composer.json`: `composer.json`:
```json
{ {
"name": "acme/blog", "name": "acme/blog",
"require": { "require": {
"acme/hello-world": "dev-master" "acme/hello-world": "dev-master"
} }
} }
```
The name is not needed in this case, since we don't want to publish the blog The name is not needed in this case, since we don't want to publish the blog
as a library. It is added here to clarify which `composer.json` is being as a library. It is added here to clarify which `composer.json` is being
@ -155,6 +161,7 @@ Now we need to tell the blog app where to find the `hello-world` dependency.
We do this by adding a package repository specification to the blog's We do this by adding a package repository specification to the blog's
`composer.json`: `composer.json`:
```json
{ {
"name": "acme/blog", "name": "acme/blog",
"repositories": [ "repositories": [
@ -167,6 +174,7 @@ We do this by adding a package repository specification to the blog's
"acme/hello-world": "dev-master" "acme/hello-world": "dev-master"
} }
} }
```
For more details on how package repositories work and what other types are For more details on how package repositories work and what other types are
available, see [Repositories](05-repositories.md). available, see [Repositories](05-repositories.md).

View File

@ -36,7 +36,9 @@ it a bit easier to do this.
When you run the command it will interactively ask you to fill in the fields, When you run the command it will interactively ask you to fill in the fields,
while using some smart defaults. while using some smart defaults.
$ php composer.phar init ```sh
php composer.phar init
```
### Options ### Options
@ -54,7 +56,9 @@ while using some smart defaults.
The `install` command reads the `composer.json` file from the current The `install` command reads the `composer.json` file from the current
directory, resolves the dependencies, and installs them into `vendor`. directory, resolves the dependencies, and installs them into `vendor`.
$ php composer.phar install ```sh
php composer.phar install
```
If there is a `composer.lock` file in the current directory, it will use the If there is a `composer.lock` file in the current directory, it will use the
exact versions from there instead of resolving them. This ensures that exact versions from there instead of resolving them. This ensures that
@ -94,18 +98,24 @@ resolution.
In order to get the latest versions of the dependencies and to update the In order to get the latest versions of the dependencies and to update the
`composer.lock` file, you should use the `update` command. `composer.lock` file, you should use the `update` command.
$ php composer.phar update ```sh
php composer.phar update
```
This will resolve all dependencies of the project and write the exact versions This will resolve all dependencies of the project and write the exact versions
into `composer.lock`. into `composer.lock`.
If you just want to update a few packages and not all, you can list them as such: If you just want to update a few packages and not all, you can list them as such:
$ php composer.phar update vendor/package vendor/package2 ```sh
php composer.phar update vendor/package vendor/package2
```
You can also use wildcards to update a bunch of packages at once: You can also use wildcards to update a bunch of packages at once:
$ php composer.phar update vendor/* ```sh
php composer.phar update vendor/*
```
### Options ### Options
@ -131,7 +141,9 @@ You can also use wildcards to update a bunch of packages at once:
The `require` command adds new packages to the `composer.json` file from The `require` command adds new packages to the `composer.json` file from
the current directory. the current directory.
$ php composer.phar require ```sh
php composer.phar require
```
After adding/changing the requirements, the modified requirements will be After adding/changing the requirements, the modified requirements will be
installed or updated. installed or updated.
@ -139,7 +151,9 @@ installed or updated.
If you do not want to choose requirements interactively, you can just pass them If you do not want to choose requirements interactively, you can just pass them
to the command. to the command.
$ php composer.phar require vendor/package:2.* vendor/package2:dev-master ```sh
php composer.phar require vendor/package:2.* vendor/package2:dev-master
```
### Options ### Options
@ -162,13 +176,17 @@ This can be used to install CLI utilities globally and if you add
`$COMPOSER_HOME/vendor/bin` to your `$PATH` environment variable. Here is an `$COMPOSER_HOME/vendor/bin` to your `$PATH` environment variable. Here is an
example: example:
$ php composer.phar global require fabpot/php-cs-fixer:dev-master ```sh
php composer.phar global require fabpot/php-cs-fixer:dev-master
```
Now the `php-cs-fixer` binary is available globally (assuming you adjusted Now the `php-cs-fixer` binary is available globally (assuming you adjusted
your PATH). If you wish to update the binary later on you can just run a your PATH). If you wish to update the binary later on you can just run a
global update: global update:
$ php composer.phar global update ```sh
php composer.phar global update
```
## search ## search
@ -176,7 +194,9 @@ The search command allows you to search through the current project's package
repositories. Usually this will be just packagist. You simply pass it the repositories. Usually this will be just packagist. You simply pass it the
terms you want to search for. terms you want to search for.
$ php composer.phar search monolog ```sh
php composer.phar search monolog
```
You can also search for more than one term by passing multiple arguments. You can also search for more than one term by passing multiple arguments.
@ -188,12 +208,15 @@ You can also search for more than one term by passing multiple arguments.
To list all of the available packages, you can use the `show` command. To list all of the available packages, you can use the `show` command.
$ php composer.phar show ```sh
php composer.phar show
```
If you want to see the details of a certain package, you can pass the package If you want to see the details of a certain package, you can pass the package
name. name.
$ php composer.phar show monolog/monolog ```sh
php composer.phar show monolog/monolog
name : monolog/monolog name : monolog/monolog
versions : master-dev, 1.0.2, 1.0.1, 1.0.0, 1.0.0-RC1 versions : master-dev, 1.0.2, 1.0.1, 1.0.0, 1.0.0-RC1
@ -209,11 +232,14 @@ name.
requires requires
php >=5.3.0 php >=5.3.0
```
You can even pass the package version, which will tell you the details of that You can even pass the package version, which will tell you the details of that
specific version. specific version.
$ php composer.phar show monolog/monolog 1.0.2 ```sh
php composer.phar show monolog/monolog 1.0.2
```
### Options ### Options
@ -227,13 +253,15 @@ The `depends` command tells you which other packages depend on a certain
package. You can specify which link types (`require`, `require-dev`) package. You can specify which link types (`require`, `require-dev`)
should be included in the listing. By default both are used. should be included in the listing. By default both are used.
$ php composer.phar depends --link-type=require monolog/monolog ```sh
php composer.phar depends --link-type=require monolog/monolog
nrk/monolog-fluent nrk/monolog-fluent
poc/poc poc/poc
propel/propel propel/propel
symfony/monolog-bridge symfony/monolog-bridge
symfony/symfony symfony/symfony
```
### Options ### Options
@ -246,7 +274,9 @@ You should always run the `validate` command before you commit your
`composer.json` file, and before you tag a release. It will check if your `composer.json` file, and before you tag a release. It will check if your
`composer.json` is valid. `composer.json` is valid.
$ php composer.phar validate ```sh
php composer.phar validate
```
### Options ### Options
@ -258,31 +288,42 @@ If you often need to modify the code of your dependencies and they are
installed from source, the `status` command allows you to check if you have installed from source, the `status` command allows you to check if you have
local changes in any of them. local changes in any of them.
$ php composer.phar status ```sh
php composer.phar status
```
With the `--verbose` option you get some more information about what was With the `--verbose` option you get some more information about what was
changed: changed:
$ php composer.phar status -v ```sh
php composer.phar status -v
You have changes in the following dependencies: You have changes in the following dependencies:
vendor/seld/jsonlint: vendor/seld/jsonlint:
M README.mdown M README.mdown
```
## self-update ## self-update
To update composer itself to the latest version, just run the `self-update` To update composer itself to the latest version, just run the `self-update`
command. It will replace your `composer.phar` with the latest version. command. It will replace your `composer.phar` with the latest version.
$ php composer.phar self-update ```sh
php composer.phar self-update
```
If you would like to instead update to a specific release simply specify it: If you would like to instead update to a specific release simply specify it:
$ composer self-update 1.0.0-alpha7 ```sh
php composer.phar self-update 1.0.0-alpha7
```
If you have installed composer for your entire system (see [global installation](00-intro.md#globally)), If you have installed composer for your entire system (see [global installation](00-intro.md#globally)),
you may have to run the command with `root` privileges you may have to run the command with `root` privileges
$ sudo composer self-update ```sh
sudo composer self-update
```
### Options ### Options
@ -294,7 +335,9 @@ you may have to run the command with `root` privileges
The `config` command allows you to edit some basic composer settings in either The `config` command allows you to edit some basic composer settings in either
the local composer.json file or the global config.json file. the local composer.json file or the global config.json file.
$ php composer.phar config --list ```sh
php composer.phar config --list
```
### Usage ### Usage
@ -326,7 +369,9 @@ the global config file.
In addition to modifying the config section, the `config` command also supports making In addition to modifying the config section, the `config` command also supports making
changes to the repositories section by using it the following way: changes to the repositories section by using it the following way:
$ php composer.phar config repositories.foo vcs http://github.com/foo/bar ```sh
php composer.phar config repositories.foo vcs http://github.com/foo/bar
```
## create-project ## create-project
@ -347,7 +392,9 @@ provide a version as third argument, otherwise the latest version is used.
If the directory does not currently exist, it will be created during installation. If the directory does not currently exist, it will be created during installation.
```sh
php composer.phar create-project doctrine/orm path 2.2.* php composer.phar create-project doctrine/orm path 2.2.*
```
It is also possible to run the command without params in a directory with an It is also possible to run the command without params in a directory with an
existing `composer.json` file to bootstrap a project. existing `composer.json` file to bootstrap a project.
@ -409,7 +456,9 @@ If you think you found a bug, or something is behaving strangely, you might
want to run the `diagnose` command to perform automated checks for many common want to run the `diagnose` command to perform automated checks for many common
problems. problems.
$ php composer.phar diagnose ```sh
php composer.phar diagnose
```
## archive ## archive
@ -417,7 +466,9 @@ This command is used to generate a zip/tar archive for a given package in a
given version. It can also be used to archive your entire project without given version. It can also be used to archive your entire project without
excluded/ignored files. excluded/ignored files.
$ php composer.phar archive vendor/package 2.0.21 --format=zip ```sh
php composer.phar archive vendor/package 2.0.21 --format=zip
```
### Options ### Options
@ -429,7 +480,9 @@ excluded/ignored files.
To get more information about a certain command, just use `help`. To get more information about a certain command, just use `help`.
$ php composer.phar help install ```sh
php composer.phar help install
```
## Environment variables ## Environment variables
@ -445,7 +498,9 @@ By setting the `COMPOSER` env variable it is possible to set the filename of
For example: For example:
$ COMPOSER=composer-other.json php composer.phar install ```sh
COMPOSER=composer-other.json php composer.phar install
```
### COMPOSER_ROOT_VERSION ### COMPOSER_ROOT_VERSION

View File

@ -59,14 +59,14 @@ RC suffixes can also be followed by a number.
Examples: Examples:
1.0.0 - 1.0.0
1.0.2 - 1.0.2
1.1.0 - 1.1.0
0.2.5 - 0.2.5
1.0.0-dev - 1.0.0-dev
1.0.0-alpha3 - 1.0.0-alpha3
1.0.0-beta2 - 1.0.0-beta2
1.0.0-RC5 - 1.0.0-RC5
Optional if the package repository can infer the version from somewhere, such Optional if the package repository can infer the version from somewhere, such
as the VCS tag name in the VCS repository. In that case it is also recommended as the VCS tag name in the VCS repository. In that case it is also recommended
@ -113,11 +113,11 @@ searching and filtering.
Examples: Examples:
logging - logging
events - events
database - database
redis - redis
templating - templating
Optional. Optional.
@ -141,19 +141,19 @@ The license of the package. This can be either a string or an array of strings.
The recommended notation for the most common licenses is (alphabetical): The recommended notation for the most common licenses is (alphabetical):
Apache-2.0 - Apache-2.0
BSD-2-Clause - BSD-2-Clause
BSD-3-Clause - BSD-3-Clause
BSD-4-Clause - BSD-4-Clause
GPL-2.0 - GPL-2.0
GPL-2.0+ - GPL-2.0+
GPL-3.0 - GPL-3.0
GPL-3.0+ - GPL-3.0+
LGPL-2.1 - LGPL-2.1
LGPL-2.1+ - LGPL-2.1+
LGPL-3.0 - LGPL-3.0
LGPL-3.0+ - LGPL-3.0+
MIT - MIT
Optional, but it is highly recommended to supply this. More identifiers are Optional, but it is highly recommended to supply this. More identifiers are
listed at the [SPDX Open Source License Registry](http://www.spdx.org/licenses/). listed at the [SPDX Open Source License Registry](http://www.spdx.org/licenses/).
@ -162,28 +162,33 @@ For closed-source software, you may use `"proprietary"` as the license identifie
An Example: An Example:
```json
{ {
"license": "MIT" "license": "MIT"
} }
```
For a package, when there is a choice between licenses ("disjunctive license"), For a package, when there is a choice between licenses ("disjunctive license"),
multiple can be specified as array. multiple can be specified as array.
An Example for disjunctive licenses: An Example for disjunctive licenses:
```json
{ {
"license": [ "license": [
"LGPL-2.1", "LGPL-2.1",
"GPL-3.0+" "GPL-3.0+"
] ]
} }
```
Alternatively they can be separated with "or" and enclosed in parenthesis; Alternatively they can be separated with "or" and enclosed in parenthesis;
```json
{ {
"license": "(LGPL-2.1 or GPL-3.0+)" "license": "(LGPL-2.1 or GPL-3.0+)"
} }
```
Similarly when multiple licenses need to be applied ("conjunctive license"), Similarly when multiple licenses need to be applied ("conjunctive license"),
they should be separated with "and" and enclosed in parenthesis. they should be separated with "and" and enclosed in parenthesis.
@ -201,6 +206,7 @@ Each author object can have following properties:
An example: An example:
```json
{ {
"authors": [ "authors": [
{ {
@ -217,6 +223,7 @@ An example:
} }
] ]
} }
```
Optional, but highly recommended. Optional, but highly recommended.
@ -235,12 +242,14 @@ Support information includes the following:
An example: An example:
```json
{ {
"support": { "support": {
"email": "support@example.org", "email": "support@example.org",
"irc": "irc://irc.freenode.org/composer" "irc": "irc://irc.freenode.org/composer"
} }
} }
```
Optional. Optional.
@ -251,11 +260,13 @@ All of the following take an object which maps package names to
Example: Example:
```json
{ {
"require": { "require": {
"monolog/monolog": "1.0.*" "monolog/monolog": "1.0.*"
} }
} }
```
All links are optional fields. All links are optional fields.
@ -267,24 +278,28 @@ allow unstable packages of a dependency for example.
Example: Example:
```json
{ {
"require": { "require": {
"monolog/monolog": "1.0.*@beta", "monolog/monolog": "1.0.*@beta",
"acme/foo": "@dev" "acme/foo": "@dev"
} }
} }
```
If one of your dependencies has a dependency on an unstable package you need to If one of your dependencies has a dependency on an unstable package you need to
explicitly require it as well, along with its sufficient stability flag. explicitly require it as well, along with its sufficient stability flag.
Example: Example:
```json
{ {
"require": { "require": {
"doctrine/doctrine-fixtures-bundle": "dev-master", "doctrine/doctrine-fixtures-bundle": "dev-master",
"doctrine/data-fixtures": "@dev" "doctrine/data-fixtures": "@dev"
} }
} }
```
`require` and `require-dev` additionally support explicit references (i.e. `require` and `require-dev` additionally support explicit references (i.e.
commit) for dev versions to make sure they are locked to a given state, even commit) for dev versions to make sure they are locked to a given state, even
@ -293,12 +308,14 @@ and append the reference with `#<ref>`.
Example: Example:
```json
{ {
"require": { "require": {
"monolog/monolog": "dev-master#2eb0c0978d290a1c45346a1955188929cb4e5db7", "monolog/monolog": "dev-master#2eb0c0978d290a1c45346a1955188929cb4e5db7",
"acme/foo": "1.0.x-dev#abc123" "acme/foo": "1.0.x-dev#abc123"
} }
} }
```
> **Note:** While this is convenient at times, it should not be how you use > **Note:** While this is convenient at times, it should not be how you use
> packages in the long term because it comes with a technical limitation. The > packages in the long term because it comes with a technical limitation. The
@ -370,11 +387,13 @@ and not version constraints.
Example: Example:
```json
{ {
"suggest": { "suggest": {
"monolog/monolog": "Allows more advanced logging of the application flow" "monolog/monolog": "Allows more advanced logging of the application flow"
} }
} }
```
### autoload ### autoload
@ -403,6 +422,7 @@ key => value array which may be found in the generated file
Example: Example:
```json
{ {
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -411,24 +431,29 @@ Example:
} }
} }
} }
```
If you need to search for a same prefix in multiple directories, If you need to search for a same prefix in multiple directories,
you can specify them as an array as such: you can specify them as an array as such:
```json
{ {
"autoload": { "autoload": {
"psr-4": { "Monolog\\": ["src/", "lib/"] } "psr-4": { "Monolog\\": ["src/", "lib/"] }
} }
} }
```
If you want to have a fallback directory where any namespace will be looked for, If you want to have a fallback directory where any namespace will be looked for,
you can use an empty prefix like: you can use an empty prefix like:
```json
{ {
"autoload": { "autoload": {
"psr-4": { "": "src/" } "psr-4": { "": "src/" }
} }
} }
```
#### PSR-0 #### PSR-0
@ -444,6 +469,7 @@ array which may be found in the generated file `vendor/composer/autoload_namespa
Example: Example:
```json
{ {
"autoload": { "autoload": {
"psr-0": { "psr-0": {
@ -453,35 +479,42 @@ Example:
} }
} }
} }
```
If you need to search for a same prefix in multiple directories, If you need to search for a same prefix in multiple directories,
you can specify them as an array as such: you can specify them as an array as such:
```json
{ {
"autoload": { "autoload": {
"psr-0": { "Monolog\\": ["src/", "lib/"] } "psr-0": { "Monolog\\": ["src/", "lib/"] }
} }
} }
```
The PSR-0 style is not limited to namespace declarations only but may be The PSR-0 style is not limited to namespace declarations only but may be
specified right down to the class level. This can be useful for libraries with specified right down to the class level. This can be useful for libraries with
only one class in the global namespace. If the php source file is also located only one class in the global namespace. If the php source file is also located
in the root of the package, for example, it may be declared like this: in the root of the package, for example, it may be declared like this:
```json
{ {
"autoload": { "autoload": {
"psr-0": { "UniqueGlobalClass": "" } "psr-0": { "UniqueGlobalClass": "" }
} }
} }
```
If you want to have a fallback directory where any namespace can be, you can If you want to have a fallback directory where any namespace can be, you can
use an empty prefix like: use an empty prefix like:
```json
{ {
"autoload": { "autoload": {
"psr-0": { "": "src/" } "psr-0": { "": "src/" }
} }
} }
```
#### Classmap #### Classmap
@ -496,11 +529,13 @@ to search for classes.
Example: Example:
```json
{ {
"autoload": { "autoload": {
"classmap": ["src/", "lib/", "Something.php"] "classmap": ["src/", "lib/", "Something.php"]
} }
} }
```
#### Files #### Files
@ -510,11 +545,13 @@ that cannot be autoloaded by PHP.
Example: Example:
```json
{ {
"autoload": { "autoload": {
"files": ["src/MyLibrary/functions.php"] "files": ["src/MyLibrary/functions.php"]
} }
} }
```
### autoload-dev <span>(root-only)</span> ### autoload-dev <span>(root-only)</span>
@ -529,6 +566,7 @@ and to add it within the autoload-dev section.
Example: Example:
```json
{ {
"autoload": { "autoload": {
"psr-4": { "MyLibrary\\": "src/" } "psr-4": { "MyLibrary\\": "src/" }
@ -537,6 +575,7 @@ Example:
"psr-4": { "MyLibrary\\Tests\\": "tests/" } "psr-4": { "MyLibrary\\Tests\\": "tests/" }
} }
} }
```
### include-path ### include-path
@ -548,9 +587,11 @@ A list of paths which should get appended to PHP's `include_path`.
Example: Example:
```json
{ {
"include-path": ["lib/"] "include-path": ["lib/"]
} }
```
Optional. Optional.
@ -574,12 +615,14 @@ it from `vendor/symfony/yaml`.
To do that, `autoload` and `target-dir` are defined as follows: To do that, `autoload` and `target-dir` are defined as follows:
```json
{ {
"autoload": { "autoload": {
"psr-0": { "Symfony\\Component\\Yaml\\": "" } "psr-0": { "Symfony\\Component\\Yaml\\": "" }
}, },
"target-dir": "Symfony/Component/Yaml" "target-dir": "Symfony/Component/Yaml"
} }
```
Optional. Optional.
@ -637,6 +680,7 @@ For more information on any of these, see [Repositories](05-repositories.md).
Example: Example:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -678,6 +722,7 @@ Example:
} }
] ]
} }
```
> **Note:** Order is significant here. When looking for a package, Composer > **Note:** Order is significant here. When looking for a package, Composer
will look from the first to the last repository, and pick the first match. will look from the first to the last repository, and pick the first match.
@ -749,11 +794,13 @@ The following options are supported:
Example: Example:
```json
{ {
"config": { "config": {
"bin-dir": "bin" "bin-dir": "bin"
} }
} }
```
### scripts <span>(root-only)</span> ### scripts <span>(root-only)</span>
@ -769,7 +816,9 @@ Arbitrary extra data for consumption by `scripts`.
This can be virtually anything. To access it from within a script event This can be virtually anything. To access it from within a script event
handler, you can do: handler, you can do:
```php
$extra = $event->getComposer()->getPackage()->getExtra(); $extra = $event->getComposer()->getPackage()->getExtra();
```
Optional. Optional.
@ -796,11 +845,13 @@ The following options are supported:
Example: Example:
```json
{ {
"archive": { "archive": {
"exclude": ["/foo/bar", "baz", "/*.test", "!/foo/bar/baz"] "exclude": ["/foo/bar", "baz", "/*.test", "!/foo/bar/baz"]
} }
} }
```
The example will include `/dir/foo/bar/file`, `/foo/bar/baz`, `/file.php`, The example will include `/dir/foo/bar/file`, `/foo/bar/baz`, `/file.php`,
`/foo/my.test` but it will exclude `/foo/bar/any`, `/foo/baz`, and `/my.test`. `/foo/my.test` but it will exclude `/foo/bar/any`, `/foo/baz`, and `/my.test`.

View File

@ -66,6 +66,7 @@ repository URL would be `example.org`.
The only required field is `packages`. The JSON structure is as follows: The only required field is `packages`. The JSON structure is as follows:
```json
{ {
"packages": { "packages": {
"vendor/package-name": { "vendor/package-name": {
@ -76,6 +77,7 @@ The only required field is `packages`. The JSON structure is as follows:
} }
} }
} }
```
The `@composer.json` marker would be the contents of the `composer.json` from The `@composer.json` marker would be the contents of the `composer.json` from
that package version including as a minimum: that package version including as a minimum:
@ -86,6 +88,7 @@ that package version including as a minimum:
Here is a minimal package definition: Here is a minimal package definition:
```json
{ {
"name": "smarty/smarty", "name": "smarty/smarty",
"version": "3.1.7", "version": "3.1.7",
@ -94,6 +97,7 @@ Here is a minimal package definition:
"type": "zip" "type": "zip"
} }
} }
```
It may include any of the other fields specified in the [schema](04-schema.md). It may include any of the other fields specified in the [schema](04-schema.md).
@ -105,19 +109,23 @@ every time a user installs a package. The URL can be either an absolute path
An example value: An example value:
```json
{ {
"notify-batch": "/downloads/" "notify-batch": "/downloads/"
} }
```
For `example.org/packages.json` containing a `monolog/monolog` package, this For `example.org/packages.json` containing a `monolog/monolog` package, this
would send a `POST` request to `example.org/downloads/` with following would send a `POST` request to `example.org/downloads/` with following
JSON request body: JSON request body:
```json
{ {
"downloads": [ "downloads": [
{"name": "monolog/monolog", "version": "1.2.1.0"}, {"name": "monolog/monolog", "version": "1.2.1.0"},
] ]
} }
```
The version field will contain the normalized representation of the version The version field will contain the normalized representation of the version
number. number.
@ -132,6 +140,7 @@ files.
An example: An example:
```json
{ {
"includes": { "includes": {
"packages-2011.json": { "packages-2011.json": {
@ -145,6 +154,7 @@ An example:
} }
} }
} }
```
The SHA-1 sum of the file allows it to be cached and only re-requested if the The SHA-1 sum of the file allows it to be cached and only re-requested if the
hash changed. hash changed.
@ -164,6 +174,7 @@ is an absolute path from the repository root.
An example: An example:
```json
{ {
"provider-includes": { "provider-includes": {
"providers-a.json": { "providers-a.json": {
@ -175,10 +186,12 @@ An example:
}, },
"providers-url": "/p/%package%$%hash%.json" "providers-url": "/p/%package%$%hash%.json"
} }
```
Those files contain lists of package names and hashes to verify the file Those files contain lists of package names and hashes to verify the file
integrity, for example: integrity, for example:
```json
{ {
"providers": { "providers": {
"acme/foo": { "acme/foo": {
@ -189,6 +202,7 @@ integrity, for example:
} }
} }
} }
```
The file above declares that acme/foo and acme/bar can be found in this The file above declares that acme/foo and acme/bar can be found in this
repository, by loading the file referenced by `providers-url`, replacing repository, by loading the file referenced by `providers-url`, replacing
@ -225,6 +239,7 @@ point to your custom branch. For version constraint naming conventions see
Example assuming you patched monolog to fix a bug in the `bugfix` branch: Example assuming you patched monolog to fix a bug in the `bugfix` branch:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -236,6 +251,7 @@ Example assuming you patched monolog to fix a bug in the `bugfix` branch:
"monolog/monolog": "dev-bugfix" "monolog/monolog": "dev-bugfix"
} }
} }
```
When you run `php composer.phar update`, you should get your modified version When you run `php composer.phar update`, you should get your modified version
of `monolog/monolog` instead of the one from packagist. of `monolog/monolog` instead of the one from packagist.
@ -256,6 +272,7 @@ For more information [see the aliases article](articles/aliases.md).
Exactly the same solution allows you to work with your private repositories at Exactly the same solution allows you to work with your private repositories at
GitHub and BitBucket: GitHub and BitBucket:
```json
{ {
"require": { "require": {
"vendor/my-private-repo": "dev-master" "vendor/my-private-repo": "dev-master"
@ -267,6 +284,7 @@ GitHub and BitBucket:
} }
] ]
} }
```
The only requirement is the installation of SSH keys for a git client. The only requirement is the installation of SSH keys for a git client.
@ -305,6 +323,7 @@ by default that code is located in `$url/trunk`, `$url/branches` and
values. For example if you used capitalized names you could configure the values. For example if you used capitalized names you could configure the
repository like this: repository like this:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -316,6 +335,7 @@ repository like this:
} }
] ]
} }
```
If you have no branches or tags directory you can disable them entirely by If you have no branches or tags directory you can disable them entirely by
setting the `branches-path` or `tags-path` to `false`. setting the `branches-path` or `tags-path` to `false`.
@ -333,6 +353,7 @@ avoid conflicts. All packages are also aliased with prefix `pear-{channelAlias}/
Example using `pear2.php.net`: Example using `pear2.php.net`:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -345,6 +366,7 @@ Example using `pear2.php.net`:
"pear-pear2/PEAR2_HTTP_Request": "*" "pear-pear2/PEAR2_HTTP_Request": "*"
} }
} }
```
In this case the short name of the channel is `pear2`, so the In this case the short name of the channel is `pear2`, so the
`PEAR2_HTTP_Request` package name becomes `pear-pear2/PEAR2_HTTP_Request`. `PEAR2_HTTP_Request` package name becomes `pear-pear2/PEAR2_HTTP_Request`.
@ -387,6 +409,7 @@ To illustrate, the following example would get the `BasePackage`,
`TopLevelPackage1`, and `TopLevelPackage2` packages from your PEAR repository `TopLevelPackage1`, and `TopLevelPackage2` packages from your PEAR repository
and `IntermediatePackage` from a Github repository: and `IntermediatePackage` from a Github repository:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -404,6 +427,7 @@ and `IntermediatePackage` from a Github repository:
"foobar/TopLevelPackage2": "*" "foobar/TopLevelPackage2": "*"
} }
} }
```
### Package ### Package
@ -418,6 +442,7 @@ minimum required fields are `name`, `version`, and either of `dist` or
Here is an example for the smarty template engine: Here is an example for the smarty template engine:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -444,6 +469,7 @@ Here is an example for the smarty template engine:
"smarty/smarty": "3.1.*" "smarty/smarty": "3.1.*"
} }
} }
```
Typically you would leave the source part off, as you don't really need it. Typically you would leave the source part off, as you don't really need it.
@ -512,6 +538,7 @@ of the times they are private. To simplify maintenance, one can simply use a
repository of type `artifact` with a folder containing ZIP archives of those repository of type `artifact` with a folder containing ZIP archives of those
private packages: private packages:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -525,12 +552,16 @@ private packages:
"acme-corp/parser": "10.3.5" "acme-corp/parser": "10.3.5"
} }
} }
```
Each zip artifact is just a ZIP archive with `composer.json` in root folder: Each zip artifact is just a ZIP archive with `composer.json` in root folder:
$ unzip -l acme-corp-parser-10.3.5.zip ```sh
unzip -l acme-corp-parser-10.3.5.zip
composer.json composer.json
... ...
```
If there are two archives with different versions of a package, they are both If there are two archives with different versions of a package, they are both
imported. When an archive with a newer version is added in the artifact folder imported. When an archive with a newer version is added in the artifact folder
@ -542,6 +573,7 @@ update to the latest version.
You can disable the default Packagist repository by adding this to your You can disable the default Packagist repository by adding this to your
`composer.json`: `composer.json`:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -549,6 +581,6 @@ You can disable the default Packagist repository by adding this to your
} }
] ]
} }
```
&larr; [Schema](04-schema.md) | [Community](06-community.md) &rarr; &larr; [Schema](04-schema.md) | [Community](06-community.md) &rarr;

View File

@ -28,6 +28,7 @@ someone will want the latest master dev version. Thus, Composer allows you to
alias your `dev-master` branch to a `1.0.x-dev` version. It is done by alias your `dev-master` branch to a `1.0.x-dev` version. It is done by
specifying a `branch-alias` field under `extra` in `composer.json`: specifying a `branch-alias` field under `extra` in `composer.json`:
```json
{ {
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -35,6 +36,7 @@ specifying a `branch-alias` field under `extra` in `composer.json`:
} }
} }
} }
```
The branch version must begin with `dev-` (non-comparable version), the alias The branch version must begin with `dev-` (non-comparable version), the alias
must be a comparable dev version (i.e. start with numbers, and end with must be a comparable dev version (i.e. start with numbers, and end with
@ -68,6 +70,7 @@ You are using `symfony/monolog-bundle` which requires `monolog/monolog` version
Just add this to your project's root `composer.json`: Just add this to your project's root `composer.json`:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -80,6 +83,7 @@ Just add this to your project's root `composer.json`:
"monolog/monolog": "dev-bugfix as 1.0.x-dev" "monolog/monolog": "dev-bugfix as 1.0.x-dev"
} }
} }
```
That will fetch the `dev-bugfix` version of `monolog/monolog` from your GitHub That will fetch the `dev-bugfix` version of `monolog/monolog` from your GitHub
and alias it to `1.0.x-dev`. and alias it to `1.0.x-dev`.

View File

@ -34,6 +34,7 @@ An example use-case would be:
An example composer.json of such a template package would be: An example composer.json of such a template package would be:
```json
{ {
"name": "phpdocumentor/template-responsive", "name": "phpdocumentor/template-responsive",
"type": "phpdocumentor-template", "type": "phpdocumentor-template",
@ -41,6 +42,7 @@ An example composer.json of such a template package would be:
"phpdocumentor/template-installer-plugin": "*" "phpdocumentor/template-installer-plugin": "*"
} }
} }
```
> **IMPORTANT**: to make sure that the template installer is present at the > **IMPORTANT**: to make sure that the template installer is present at the
> time the template package is installed, template packages should require > time the template package is installed, template packages should require
@ -70,6 +72,7 @@ requirements:
Example: Example:
```json
{ {
"name": "phpdocumentor/template-installer-plugin", "name": "phpdocumentor/template-installer-plugin",
"type": "composer-plugin", "type": "composer-plugin",
@ -84,6 +87,7 @@ Example:
"composer-plugin-api": "1.0.0" "composer-plugin-api": "1.0.0"
} }
} }
```
### The Plugin class ### The Plugin class
@ -96,6 +100,9 @@ autoloadable and matches the `extra.class` element in the package definition.
Example: Example:
```php
<?php
namespace phpDocumentor\Composer; namespace phpDocumentor\Composer;
use Composer\Composer; use Composer\Composer;
@ -110,6 +117,7 @@ Example:
$composer->getInstallationManager()->addInstaller($installer); $composer->getInstallationManager()->addInstaller($installer);
} }
} }
```
### The Custom Installer class ### The Custom Installer class
@ -138,6 +146,9 @@ source for the exact signature):
Example: Example:
```php
<?php
namespace phpDocumentor\Composer; namespace phpDocumentor\Composer;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
@ -170,6 +181,7 @@ Example:
return 'phpdocumentor-template' === $packageType; return 'phpdocumentor-template' === $packageType;
} }
} }
```
The example demonstrates that it is quite simple to extend the The example demonstrates that it is quite simple to extend the
[`Composer\Installer\LibraryInstaller`][5] class to strip a prefix [`Composer\Installer\LibraryInstaller`][5] class to strip a prefix

View File

@ -25,6 +25,7 @@ repositories you defined.
The default file Satis looks for is `satis.json` in the root of the repository. The default file Satis looks for is `satis.json` in the root of the repository.
```json
{ {
"name": "My Repository", "name": "My Repository",
"homepage": "http://packages.example.org", "homepage": "http://packages.example.org",
@ -35,12 +36,14 @@ The default file Satis looks for is `satis.json` in the root of the repository.
], ],
"require-all": true "require-all": true
} }
```
If you want to cherry pick which packages you want, you can list all the packages If you want to cherry pick which packages you want, you can list all the packages
you want to have in your satis repository inside the classic composer `require` key, you want to have in your satis repository inside the classic composer `require` key,
using a `"*"` constraint to make sure all versions are selected, or another using a `"*"` constraint to make sure all versions are selected, or another
constraint if you want really specific versions. constraint if you want really specific versions.
```json
{ {
"repositories": [ "repositories": [
{ "type": "vcs", "url": "http://github.com/mycompany/privaterepo" }, { "type": "vcs", "url": "http://github.com/mycompany/privaterepo" },
@ -53,6 +56,7 @@ constraint if you want really specific versions.
"company/package3": "2.0.0" "company/package3": "2.0.0"
} }
} }
```
Once you did this, you just run `php bin/satis build <configuration file> <build dir>`. Once you did this, you just run `php bin/satis build <configuration file> <build dir>`.
For example `php bin/satis build config.json web/` would read the `config.json` For example `php bin/satis build config.json web/` would read the `config.json`
@ -80,6 +84,7 @@ everything should work smoothly. You don't need to copy all your repositories
in every project anymore. Only that one unique repository that will update in every project anymore. Only that one unique repository that will update
itself. itself.
```json
{ {
"repositories": [ { "type": "composer", "url": "http://packages.example.org/" } ], "repositories": [ { "type": "composer", "url": "http://packages.example.org/" } ],
"require": { "require": {
@ -88,6 +93,7 @@ itself.
"company/package3": "dev-master" "company/package3": "dev-master"
} }
} }
```
### Security ### Security
@ -97,6 +103,7 @@ connection options for the server.
Example using a custom repository using SSH (requires the SSH2 PECL extension): Example using a custom repository using SSH (requires the SSH2 PECL extension):
```json
{ {
"repositories": [ "repositories": [
{ {
@ -112,11 +119,13 @@ Example using a custom repository using SSH (requires the SSH2 PECL extension):
} }
] ]
} }
```
> **Tip:** See [ssh2 context options](http://www.php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-options) for more information. > **Tip:** See [ssh2 context options](http://www.php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-options) for more information.
Example using HTTP over SSL using a client certificate: Example using HTTP over SSL using a client certificate:
```json
{ {
"repositories": [ "repositories": [
{ {
@ -130,6 +139,7 @@ Example using HTTP over SSL using a client certificate:
} }
] ]
} }
```
> **Tip:** See [ssl context options](http://www.php.net/manual/en/context.ssl.php) for more information. > **Tip:** See [ssl context options](http://www.php.net/manual/en/context.ssl.php) for more information.
@ -145,6 +155,7 @@ Subversion) will not have downloads available and thus installations usually tak
To enable your satis installation to create downloads for all (Git, Mercurial and Subversion) your packages, add the To enable your satis installation to create downloads for all (Git, Mercurial and Subversion) your packages, add the
following to your `satis.json`: following to your `satis.json`:
```json
{ {
"archive": { "archive": {
"directory": "dist", "directory": "dist",
@ -153,6 +164,7 @@ following to your `satis.json`:
"skip-dev": true "skip-dev": true
} }
} }
```
#### Options explained #### Options explained
@ -178,10 +190,11 @@ It is possible to make satis automatically resolve and add all dependencies for
with the Downloads functionality to have a complete local mirror of packages. Just add the following with the Downloads functionality to have a complete local mirror of packages. Just add the following
to your `satis.json`: to your `satis.json`:
```json
{ {
"require-dependencies": true "require-dependencies": true
} }
```
When searching for packages, satis will attempt to resolve all the required packages from the listed repositories. When searching for packages, satis will attempt to resolve all the required packages from the listed repositories.
Therefore, if you are requiring a package from Packagist, you will need to define it in your `satis.json`. Therefore, if you are requiring a package from Packagist, you will need to define it in your `satis.json`.

View File

@ -35,6 +35,7 @@ current composer plugin API version is 1.0.0.
For example For example
```json
{ {
"name": "my/plugin-package", "name": "my/plugin-package",
"type": "composer-plugin", "type": "composer-plugin",
@ -42,6 +43,7 @@ For example
"composer-plugin-api": "1.0.0" "composer-plugin-api": "1.0.0"
} }
} }
```
### Plugin Class ### Plugin Class
@ -54,6 +56,9 @@ be read and all internal objects and state can be manipulated as desired.
Example: Example:
```php
<?php
namespace phpDocumentor\Composer; namespace phpDocumentor\Composer;
use Composer\Composer; use Composer\Composer;
@ -68,6 +73,7 @@ Example:
$composer->getInstallationManager()->addInstaller($installer); $composer->getInstallationManager()->addInstaller($installer);
} }
} }
```
## Event Handler ## Event Handler
@ -88,6 +94,9 @@ The events available for plugins are:
Example: Example:
```php
<?php
namespace Naderman\Composer\AWS; namespace Naderman\Composer\AWS;
use Composer\Composer; use Composer\Composer;
@ -128,6 +137,7 @@ Example:
} }
} }
} }
```
## Using Plugins ## Using Plugins

View File

@ -67,6 +67,7 @@ autoload functionality.
Script definition example: Script definition example:
```json
{ {
"scripts": { "scripts": {
"post-update-cmd": "MyVendor\\MyClass::postUpdate", "post-update-cmd": "MyVendor\\MyClass::postUpdate",
@ -79,10 +80,12 @@ Script definition example:
] ]
} }
} }
```
Using the previous definition example, here's the class `MyVendor\MyClass` Using the previous definition example, here's the class `MyVendor\MyClass`
that might be used to execute the PHP callbacks: that might be used to execute the PHP callbacks:
```php
<?php <?php
namespace MyVendor; namespace MyVendor;
@ -108,6 +111,7 @@ that might be used to execute the PHP callbacks:
// make cache toasty // make cache toasty
} }
} }
```
When an event is fired, Composer's internal event handler receives a When an event is fired, Composer's internal event handler receives a
`Composer\Script\Event` object, which is passed as the first argument to your `Composer\Script\Event` object, which is passed as the first argument to your
@ -122,6 +126,8 @@ PHP callback. This `Event` object has getters for other contextual objects:
If you would like to run the scripts for an event manually, the syntax is: If you would like to run the scripts for an event manually, the syntax is:
$ composer run-script [--dev] [--no-dev] script ```sh
composer run-script [--dev] [--no-dev] script
```
For example `composer run-script post-install-cmd` will run any **post-install-cmd** scripts that have been defined. For example `composer run-script post-install-cmd` will run any **post-install-cmd** scripts that have been defined.

View File

@ -63,12 +63,14 @@ You can fix this by aliasing version 0.11 to 0.1:
composer.json: composer.json:
```json
{ {
"require": { "require": {
"A": "0.2", "A": "0.2",
"B": "0.11 as 0.1" "B": "0.11 as 0.1"
} }
} }
```
See [aliases](aliases.md) for more information. See [aliases](aliases.md) for more information.
@ -76,7 +78,7 @@ See [aliases](aliases.md) for more information.
If composer shows memory errors on some commands: If composer shows memory errors on some commands:
PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...> `PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...>`
The PHP `memory_limit` should be increased. The PHP `memory_limit` should be increased.
@ -86,17 +88,23 @@ The PHP `memory_limit` should be increased.
To get the current `memory_limit` value, run: To get the current `memory_limit` value, run:
```sh
php -r "echo ini_get('memory_limit').PHP_EOL;" php -r "echo ini_get('memory_limit').PHP_EOL;"
```
Try increasing the limit in your `php.ini` file (ex. `/etc/php5/cli/php.ini` for Try increasing the limit in your `php.ini` file (ex. `/etc/php5/cli/php.ini` for
Debian-like systems): Debian-like systems):
```ini
; Use -1 for unlimited or define an explicit value like 512M ; Use -1 for unlimited or define an explicit value like 512M
memory_limit = -1 memory_limit = -1
```
Or, you can increase the limit with a command-line argument: Or, you can increase the limit with a command-line argument:
```sh
php -d memory_limit=-1 composer.phar <...> php -d memory_limit=-1 composer.phar <...>
```
## "The system cannot find the path specified" (Windows) ## "The system cannot find the path specified" (Windows)
@ -123,18 +131,23 @@ Now Composer should install/update without asking for authentication.
## proc_open(): fork failed errors ## proc_open(): fork failed errors
If composer shows proc_open() fork failed on some commands: If composer shows proc_open() fork failed on some commands:
PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar `PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar`
This could be happening because the VPS runs out of memory and has no Swap space enabled. This could be happening because the VPS runs out of memory and has no Swap space enabled.
[root@my_tiny_vps htdocs]# free -m ```sh
free -m
total used free shared buffers cached total used free shared buffers cached
Mem: 2048 357 1690 0 0 237 Mem: 2048 357 1690 0 0 237
-/+ buffers/cache: 119 1928 -/+ buffers/cache: 119 1928
Swap: 0 0 0 Swap: 0 0 0
```
To enable the swap you can use for example: To enable the swap you can use for example:
```sh
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1 /sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1 /sbin/swapon /var/swap.1
```

View File

@ -20,10 +20,11 @@ It is defined by adding the `bin` key to a project's `composer.json`.
It is specified as an array of files so multiple binaries can be added It is specified as an array of files so multiple binaries can be added
for any given project. for any given project.
```json
{ {
"bin": ["bin/my-script", "bin/my-other-script"] "bin": ["bin/my-script", "bin/my-other-script"]
} }
```
## What does defining a vendor binary in composer.json do? ## What does defining a vendor binary in composer.json do?
@ -46,22 +47,26 @@ symlink is created from each dependency's binaries to `vendor/bin`.
Say package `my-vendor/project-a` has binaries setup like this: Say package `my-vendor/project-a` has binaries setup like this:
```json
{ {
"name": "my-vendor/project-a", "name": "my-vendor/project-a",
"bin": ["bin/project-a-bin"] "bin": ["bin/project-a-bin"]
} }
```
Running `composer install` for this `composer.json` will not do Running `composer install` for this `composer.json` will not do
anything with `bin/project-a-bin`. anything with `bin/project-a-bin`.
Say project `my-vendor/project-b` has requirements setup like this: Say project `my-vendor/project-b` has requirements setup like this:
```json
{ {
"name": "my-vendor/project-b", "name": "my-vendor/project-b",
"require": { "require": {
"my-vendor/project-a": "*" "my-vendor/project-a": "*"
} }
} }
```
Running `composer install` for this `composer.json` will look at Running `composer install` for this `composer.json` will look at
all of project-b's dependencies and install them to `vendor/bin`. all of project-b's dependencies and install them to `vendor/bin`.
@ -95,11 +100,13 @@ Yes, there are two ways an alternate vendor binary location can be specified:
An example of the former looks like this: An example of the former looks like this:
```json
{ {
"config": { "config": {
"bin-dir": "scripts" "bin-dir": "scripts"
} }
} }
```
Running `composer install` for this `composer.json` will result in Running `composer install` for this `composer.json` will result in
all of the vendor binaries being installed in `scripts/` instead of all of the vendor binaries being installed in `scripts/` instead of

View File

@ -11,6 +11,7 @@ This is common if your package is intended for a specific framework such as
CakePHP, Drupal or WordPress. Here is an example composer.json file for a CakePHP, Drupal or WordPress. Here is an example composer.json file for a
WordPress theme: WordPress theme:
```json
{ {
"name": "you/themename", "name": "you/themename",
"type": "wordpress-theme", "type": "wordpress-theme",
@ -18,6 +19,7 @@ WordPress theme:
"composer/installers": "~1.0" "composer/installers": "~1.0"
} }
} }
```
Now when your theme is installed with Composer it will be placed into Now when your theme is installed with Composer it will be placed into
`wp-content/themes/themename/` folder. Check the `wp-content/themes/themename/` folder. Check the
@ -30,6 +32,7 @@ useful example would be for a Drupal multisite setup where the package should be
installed into your sites subdirectory. Here we are overriding the install path installed into your sites subdirectory. Here we are overriding the install path
for a module that uses composer/installers: for a module that uses composer/installers:
```json
{ {
"extra": { "extra": {
"installer-paths": { "installer-paths": {
@ -37,6 +40,7 @@ for a module that uses composer/installers:
} }
} }
} }
```
Now the package would be installed to your folder location, rather than the default Now the package would be installed to your folder location, rather than the default
composer/installers determined location. composer/installers determined location.