2020-05-01 08:18:54 +00:00
|
|
|
# The composer.json schema
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-04-13 12:35:13 +00:00
|
|
|
This chapter will explain all of the fields available in `composer.json`.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
## JSON schema
|
|
|
|
|
2020-04-12 22:54:46 +00:00
|
|
|
We have a [JSON schema](https://json-schema.org) that documents the format and
|
2012-02-20 10:08:18 +00:00
|
|
|
can also be used to validate your `composer.json`. In fact, it is used by the
|
2016-05-04 09:34:12 +00:00
|
|
|
`validate` command. You can find it at: https://getcomposer.org/schema.json
|
2012-04-13 12:35:13 +00:00
|
|
|
|
|
|
|
## Root Package
|
|
|
|
|
|
|
|
The root package is the package defined by the `composer.json` at the root of
|
|
|
|
your project. It is the main `composer.json` that defines your project
|
|
|
|
requirements.
|
|
|
|
|
|
|
|
Certain fields only apply when in the root package context. One example of
|
|
|
|
this is the `config` field. Only the root package can define configuration.
|
|
|
|
The config of dependencies is ignored. This makes the `config` field
|
|
|
|
`root-only`.
|
|
|
|
|
2012-07-20 18:38:46 +00:00
|
|
|
> **Note:** A package can be the root package or not, depending on the context.
|
|
|
|
> For example, if your project depends on the `monolog` library, your project
|
|
|
|
> is the root package. However, if you clone `monolog` from GitHub in order to
|
|
|
|
> fix a bug in it, then `monolog` is the root package.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
## Properties
|
|
|
|
|
|
|
|
### name
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
The name of the package. It consists of vendor name and project name,
|
2017-04-05 07:15:06 +00:00
|
|
|
separated by `/`. Examples:
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
* monolog/monolog
|
|
|
|
* igorw/event-source
|
|
|
|
|
2021-12-19 14:15:21 +00:00
|
|
|
The name must be lowercase and consist of words separated by `-`, `.` or `_`.
|
2020-04-23 09:02:50 +00:00
|
|
|
The complete name should match `^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$`.
|
2017-04-05 07:15:06 +00:00
|
|
|
|
2020-04-23 09:02:50 +00:00
|
|
|
The `name` property is required for published packages (libraries).
|
|
|
|
|
|
|
|
> **Note:** Before Composer version 2.0, a name could contain any character, including white spaces.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### description
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2018-03-23 10:37:33 +00:00
|
|
|
A short description of the package. Usually this is one line long.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-04-14 21:52:52 +00:00
|
|
|
Required for published packages (libraries).
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### version
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2013-08-13 12:46:43 +00:00
|
|
|
The version of the package. In most cases this is not required and should
|
|
|
|
be omitted (see below).
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2013-08-13 12:46:43 +00:00
|
|
|
This must follow the format of `X.Y.Z` or `vX.Y.Z` with an optional suffix
|
2015-01-20 08:05:40 +00:00
|
|
|
of `-dev`, `-patch` (`-p`), `-alpha` (`-a`), `-beta` (`-b`) or `-RC`.
|
|
|
|
The patch, alpha, beta and RC suffixes can also be followed by a number.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
- 1.0.0
|
|
|
|
- 1.0.2
|
|
|
|
- 1.1.0
|
|
|
|
- 0.2.5
|
|
|
|
- 1.0.0-dev
|
|
|
|
- 1.0.0-alpha3
|
|
|
|
- 1.0.0-beta2
|
|
|
|
- 1.0.0-RC5
|
2015-01-20 08:05:40 +00:00
|
|
|
- v2.0.4-p1
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
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
|
|
|
|
to omit it.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-06-14 12:59:11 +00:00
|
|
|
> **Note:** Packagist uses VCS repositories, so the statement above is very
|
|
|
|
> much true for Packagist as well. Specifying the version yourself will
|
|
|
|
> most likely end up creating problems at some point due to human error.
|
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### type
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
The type of the package. It defaults to `library`.
|
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
Package types are used for custom installation logic. If you have a package
|
|
|
|
that needs some special logic, you can define a custom type. This could be a
|
2016-12-02 19:22:07 +00:00
|
|
|
`symfony-bundle`, a `wordpress-plugin` or a `typo3-cms-extension`. These types
|
|
|
|
will all be specific to certain projects, and they will need to provide an
|
2012-02-26 11:40:35 +00:00
|
|
|
installer capable of installing packages of that type.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2015-06-22 09:08:23 +00:00
|
|
|
Out of the box, Composer supports four types:
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2020-10-23 19:52:05 +00:00
|
|
|
- **library:** This is the default. It will copy the files to `vendor`.
|
2013-04-11 10:35:41 +00:00
|
|
|
- **project:** This denotes a project rather than a library. For example
|
2013-04-11 09:53:19 +00:00
|
|
|
application shells like the [Symfony standard edition](https://github.com/symfony/symfony-standard),
|
|
|
|
CMSs like the [SilverStripe installer](https://github.com/silverstripe/silverstripe-installer)
|
|
|
|
or full fledged applications distributed as packages. This can for example
|
|
|
|
be used by IDEs to provide listings of projects to initialize when creating
|
2021-05-24 08:15:10 +00:00
|
|
|
a new workspace.
|
2012-03-24 17:20:27 +00:00
|
|
|
- **metapackage:** An empty package that contains requirements and will trigger
|
|
|
|
their installation, but contains no files and will not write anything to the
|
|
|
|
filesystem. As such, it does not require a dist or source key to be
|
|
|
|
installable.
|
2013-08-13 11:25:21 +00:00
|
|
|
- **composer-plugin:** A package of type `composer-plugin` may provide an
|
2012-04-08 17:13:00 +00:00
|
|
|
installer for other packages that have a custom type. Read more in the
|
|
|
|
[dedicated article](articles/custom-installers.md).
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
Only use a custom type if you need custom logic during installation. It is
|
2018-03-23 10:37:33 +00:00
|
|
|
recommended to omit this field and have it default to `library`.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### keywords
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
An array of keywords that the package is related to. These can be used for
|
|
|
|
searching and filtering.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
- logging
|
|
|
|
- events
|
|
|
|
- database
|
|
|
|
- redis
|
|
|
|
- templating
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2022-07-21 12:40:21 +00:00
|
|
|
> **Note**: Some special keywords trigger `composer require` without the
|
|
|
|
> `--dev` option to prompt users if they would like to add these packages to
|
|
|
|
> `require-dev` instead of `require`. These are: `dev`, `testing`, `static analysis`.
|
|
|
|
|
2012-02-19 20:07:30 +00:00
|
|
|
Optional.
|
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### homepage
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2020-06-30 15:39:56 +00:00
|
|
|
A URL to the website of the project.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2018-04-13 07:06:45 +00:00
|
|
|
### readme
|
|
|
|
|
2023-03-10 16:51:56 +00:00
|
|
|
A relative path to the readme document. Defaults to `README.md`.
|
|
|
|
|
|
|
|
This is mainly useful for packages not on GitHub, as for GitHub packages Packagist.org will use the readme API to fetch the one detected by GitHub.
|
2018-04-13 07:06:45 +00:00
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### time
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Release date of the version.
|
|
|
|
|
|
|
|
Must be in `YYYY-MM-DD` or `YYYY-MM-DD HH:MM:SS` format.
|
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### license
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
The license of the package. This can be either a string or an array of strings.
|
|
|
|
|
2012-05-07 19:34:25 +00:00
|
|
|
The recommended notation for the most common licenses is (alphabetical):
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
- Apache-2.0
|
|
|
|
- BSD-2-Clause
|
|
|
|
- BSD-3-Clause
|
|
|
|
- BSD-4-Clause
|
2018-01-22 08:37:05 +00:00
|
|
|
- GPL-2.0-only / GPL-2.0-or-later
|
|
|
|
- GPL-3.0-only / GPL-3.0-or-later
|
|
|
|
- LGPL-2.1-only / LGPL-2.1-or-later
|
|
|
|
- LGPL-3.0-only / LGPL-3.0-or-later
|
2014-05-19 10:17:07 +00:00
|
|
|
- MIT
|
2012-05-07 19:34:25 +00:00
|
|
|
|
|
|
|
Optional, but it is highly recommended to supply this. More identifiers are
|
2017-12-29 10:37:42 +00:00
|
|
|
listed at the [SPDX Open Source License Registry](https://spdx.org/licenses/).
|
2012-05-07 19:34:25 +00:00
|
|
|
|
2021-07-22 10:08:25 +00:00
|
|
|
> **Note:** For closed-source software, you may use `"proprietary"` as the license identifier.
|
2013-02-24 17:33:06 +00:00
|
|
|
|
2012-05-07 19:34:25 +00:00
|
|
|
An Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"license": "MIT"
|
|
|
|
}
|
|
|
|
```
|
2012-05-07 19:34:25 +00:00
|
|
|
|
2012-05-12 16:42:35 +00:00
|
|
|
For a package, when there is a choice between licenses ("disjunctive license"),
|
2021-12-19 14:15:21 +00:00
|
|
|
multiple can be specified as an array.
|
2012-05-07 19:34:25 +00:00
|
|
|
|
|
|
|
An Example for disjunctive licenses:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"license": [
|
2022-08-20 10:23:00 +00:00
|
|
|
"LGPL-2.1-only",
|
|
|
|
"GPL-3.0-or-later"
|
2014-05-19 10:17:07 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2012-05-07 19:34:25 +00:00
|
|
|
|
2020-06-30 15:39:56 +00:00
|
|
|
Alternatively they can be separated with "or" and enclosed in parentheses;
|
2012-05-07 19:34:25 +00:00
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
2018-01-22 08:42:50 +00:00
|
|
|
"license": "(LGPL-2.1-only or GPL-3.0-or-later)"
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-05-07 19:34:25 +00:00
|
|
|
|
2020-06-30 15:39:56 +00:00
|
|
|
Similarly, when multiple licenses need to be applied ("conjunctive license"),
|
|
|
|
they should be separated with "and" and enclosed in parentheses.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### authors
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
The authors of the package. This is an array of objects.
|
|
|
|
|
|
|
|
Each author object can have following properties:
|
|
|
|
|
2016-02-29 18:59:19 +00:00
|
|
|
* **name:** The author's name. Usually their real name.
|
2012-02-19 20:07:30 +00:00
|
|
|
* **email:** The author's email address.
|
2022-02-21 12:33:20 +00:00
|
|
|
* **homepage:** URL to the author's website.
|
2016-03-14 16:25:58 +00:00
|
|
|
* **role:** The author's role in the project (e.g. developer or translator)
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
An example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"authors": [
|
|
|
|
{
|
|
|
|
"name": "Nils Adermann",
|
|
|
|
"email": "naderman@naderman.de",
|
2020-04-12 22:54:46 +00:00
|
|
|
"homepage": "https://www.naderman.de",
|
2014-05-19 10:17:07 +00:00
|
|
|
"role": "Developer"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Jordi Boggiano",
|
|
|
|
"email": "j.boggiano@seld.be",
|
2017-12-29 10:33:19 +00:00
|
|
|
"homepage": "https://seld.be",
|
2014-05-19 10:17:07 +00:00
|
|
|
"role": "Developer"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Optional, but highly recommended.
|
|
|
|
|
2012-05-27 23:57:12 +00:00
|
|
|
### support
|
|
|
|
|
|
|
|
Various information to get support about the project.
|
|
|
|
|
|
|
|
Support information includes the following:
|
|
|
|
|
|
|
|
* **email:** Email address for support.
|
2015-05-28 11:03:24 +00:00
|
|
|
* **issues:** URL to the issue tracker.
|
|
|
|
* **forum:** URL to the forum.
|
|
|
|
* **wiki:** URL to the wiki.
|
2012-05-27 23:57:12 +00:00
|
|
|
* **irc:** IRC channel for support, as irc://server/channel.
|
|
|
|
* **source:** URL to browse or download the sources.
|
2015-05-28 11:03:24 +00:00
|
|
|
* **docs:** URL to the documentation.
|
2016-03-28 08:23:34 +00:00
|
|
|
* **rss:** URL to the RSS feed.
|
2018-10-22 08:11:34 +00:00
|
|
|
* **chat:** URL to the chat channel.
|
2012-05-27 23:57:12 +00:00
|
|
|
|
|
|
|
An example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"support": {
|
|
|
|
"email": "support@example.org",
|
|
|
|
"irc": "irc://irc.freenode.org/composer"
|
2012-05-27 23:57:12 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-05-27 23:57:12 +00:00
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2019-11-28 21:34:29 +00:00
|
|
|
### funding
|
|
|
|
|
|
|
|
A list of URLs to provide funding to the package authors for maintenance and
|
|
|
|
development of new functionality.
|
|
|
|
|
|
|
|
Each entry consists of the following
|
|
|
|
|
2020-06-30 15:39:56 +00:00
|
|
|
* **type:** The type of funding, or the platform through which funding can be provided, e.g. patreon, opencollective, tidelift or github.
|
|
|
|
* **url:** URL to a website with details, and a way to fund the package.
|
2019-11-28 21:34:29 +00:00
|
|
|
|
|
|
|
An example:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"funding": [
|
|
|
|
{
|
|
|
|
"type": "patreon",
|
|
|
|
"url": "https://www.patreon.com/phpdoctrine"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "tidelift",
|
|
|
|
"url": "https://tidelift.com/subscription/pkg/packagist-doctrine_doctrine-bundle"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "other",
|
|
|
|
"url": "https://www.doctrine-project.org/sponsorship.html"
|
|
|
|
}
|
2019-12-02 10:03:25 +00:00
|
|
|
]
|
2019-11-28 21:34:29 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2012-05-12 10:08:35 +00:00
|
|
|
### Package links
|
|
|
|
|
|
|
|
All of the following take an object which maps package names to
|
2017-01-23 19:06:51 +00:00
|
|
|
versions of the package via version constraints. Read more about
|
|
|
|
versions [here](articles/versions.md).
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"require": {
|
|
|
|
"monolog/monolog": "1.0.*"
|
2012-02-19 20:07:30 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-05-12 10:08:35 +00:00
|
|
|
All links are optional fields.
|
|
|
|
|
2019-12-25 19:13:57 +00:00
|
|
|
`require` and `require-dev` additionally support _stability flags_ ([root-only](04-schema.md#root-package)).
|
2020-04-14 22:24:13 +00:00
|
|
|
They take the form "_constraint_@_stability flag_".
|
2012-05-12 10:08:35 +00:00
|
|
|
These allow you to further restrict or expand the stability of a package beyond
|
|
|
|
the scope of the [minimum-stability](#minimum-stability) setting. You can apply
|
2019-12-25 19:13:57 +00:00
|
|
|
them to a constraint, or apply them to an empty _constraint_ if you want to
|
2013-08-23 09:09:46 +00:00
|
|
|
allow unstable packages of a dependency for example.
|
2012-05-12 10:08:35 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"require": {
|
|
|
|
"monolog/monolog": "1.0.*@beta",
|
|
|
|
"acme/foo": "@dev"
|
2012-05-12 10:08:35 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-05-12 10:08:35 +00:00
|
|
|
|
2013-08-23 09:09:46 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
Example:
|
2017-08-07 08:57:15 +00:00
|
|
|
|
|
|
|
Assuming `doctrine/doctrine-fixtures-bundle` requires `"doctrine/data-fixtures": "dev-master"`
|
|
|
|
then inside the root composer.json you need to add the second line below to allow dev
|
|
|
|
releases for the `doctrine/data-fixtures` package :
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"require": {
|
|
|
|
"doctrine/doctrine-fixtures-bundle": "dev-master",
|
|
|
|
"doctrine/data-fixtures": "@dev"
|
2013-08-23 09:09:46 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2013-08-23 09:09:46 +00:00
|
|
|
|
2012-05-17 08:08:48 +00:00
|
|
|
`require` and `require-dev` additionally support explicit references (i.e.
|
2013-01-04 21:43:00 +00:00
|
|
|
commit) for dev versions to make sure they are locked to a given state, even
|
2012-05-17 08:08:48 +00:00
|
|
|
when you run update. These only work if you explicitly require a dev version
|
2018-04-12 17:49:18 +00:00
|
|
|
and append the reference with `#<ref>`. This is also a
|
|
|
|
[root-only](04-schema.md#root-package) feature and will be ignored in
|
|
|
|
dependencies.
|
2012-05-17 08:08:48 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"require": {
|
|
|
|
"monolog/monolog": "dev-master#2eb0c0978d290a1c45346a1955188929cb4e5db7",
|
|
|
|
"acme/foo": "1.0.x-dev#abc123"
|
2012-05-17 08:08:48 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-05-17 08:08:48 +00:00
|
|
|
|
2017-03-07 11:33:19 +00:00
|
|
|
> **Note:** This feature has severe technical limitations, as the
|
2013-11-11 13:41:21 +00:00
|
|
|
> composer.json metadata will still be read from the branch name you specify
|
2016-10-31 15:26:37 +00:00
|
|
|
> before the hash. You should therefore only use this as a temporary solution
|
|
|
|
> during development to remediate transient issues, until you can switch to
|
|
|
|
> tagged releases. The Composer team does not actively support this feature
|
2017-03-07 11:33:19 +00:00
|
|
|
> and will not accept bug reports related to it.
|
2013-11-11 13:41:21 +00:00
|
|
|
|
|
|
|
It is also possible to inline-alias a package constraint so that it matches
|
|
|
|
a constraint that it otherwise would not. For more information [see the
|
2012-11-07 12:11:09 +00:00
|
|
|
aliases article](articles/aliases.md).
|
|
|
|
|
2015-11-22 15:26:10 +00:00
|
|
|
`require` and `require-dev` also support references to specific PHP versions
|
2016-09-29 06:20:23 +00:00
|
|
|
and PHP extensions your project needs to run successfully.
|
2015-11-22 15:26:10 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2015-11-22 15:30:55 +00:00
|
|
|
```json
|
2015-11-22 15:26:10 +00:00
|
|
|
{
|
2022-08-20 10:23:00 +00:00
|
|
|
"require": {
|
|
|
|
"php": ">=7.4",
|
2015-11-22 15:26:10 +00:00
|
|
|
"ext-mbstring": "*"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-09-29 06:20:23 +00:00
|
|
|
> **Note:** It is important to list PHP extensions your project requires.
|
|
|
|
> Not all PHP installations are created equal: some may miss extensions you
|
|
|
|
> may consider as standard (such as `ext-mysqli` which is not installed by
|
|
|
|
> default in Fedora/CentOS minimal installation systems). Failure to list
|
|
|
|
> required PHP extensions may lead to a bad user experience: Composer will
|
|
|
|
> install your package without any errors but it will then fail at run-time.
|
|
|
|
> The `composer show --platform` command lists all PHP extensions available on
|
|
|
|
> your system. You may use it to help you compile the list of extensions you
|
|
|
|
> use and require. Alternatively you may use third party tools to analyze
|
|
|
|
> your project for the list of extensions used.
|
2016-09-28 11:40:16 +00:00
|
|
|
|
2012-05-12 10:08:35 +00:00
|
|
|
#### require
|
|
|
|
|
2021-01-08 08:29:25 +00:00
|
|
|
Map of packages required by this package. The package will not be installed
|
2012-05-12 10:08:35 +00:00
|
|
|
unless those requirements can be met.
|
|
|
|
|
2015-06-22 08:00:04 +00:00
|
|
|
#### require-dev <span>([root-only](04-schema.md#root-package))</span>
|
2012-05-12 10:08:35 +00:00
|
|
|
|
2021-01-08 08:29:25 +00:00
|
|
|
Map of packages required for developing this package, or running
|
2013-08-07 19:11:52 +00:00
|
|
|
tests, etc. The dev requirements of the root package are installed by default.
|
|
|
|
Both `install` or `update` support the `--no-dev` option that prevents dev
|
|
|
|
dependencies from being installed.
|
2012-05-21 16:41:20 +00:00
|
|
|
|
2012-05-12 10:08:35 +00:00
|
|
|
#### conflict
|
|
|
|
|
2021-01-08 08:29:25 +00:00
|
|
|
Map of packages that conflict with this version of this package. They
|
2012-05-12 10:08:35 +00:00
|
|
|
will not be allowed to be installed together with your package.
|
|
|
|
|
2014-01-15 15:47:27 +00:00
|
|
|
Note that when specifying ranges like `<1.0 >=1.1` in a `conflict` link,
|
2013-06-20 21:32:59 +00:00
|
|
|
this will state a conflict with all versions that are less than 1.0 *and* equal
|
|
|
|
or newer than 1.1 at the same time, which is probably not what you want. You
|
2016-02-12 09:09:28 +00:00
|
|
|
probably want to go for `<1.0 || >=1.1` in this case.
|
2013-06-20 21:32:59 +00:00
|
|
|
|
2012-05-12 10:08:35 +00:00
|
|
|
#### replace
|
|
|
|
|
2021-01-08 08:29:25 +00:00
|
|
|
Map of packages that are replaced by this package. This allows you to fork a
|
2012-05-12 16:27:28 +00:00
|
|
|
package, publish it under a different name with its own version numbers, while
|
|
|
|
packages requiring the original package continue to work with your fork because
|
|
|
|
it replaces the original package.
|
2012-05-12 10:08:35 +00:00
|
|
|
|
2012-05-12 16:27:28 +00:00
|
|
|
This is also useful for packages that contain sub-packages, for example the main
|
2012-05-12 10:08:35 +00:00
|
|
|
symfony/symfony package contains all the Symfony Components which are also
|
|
|
|
available as individual packages. If you require the main package it will
|
|
|
|
automatically fulfill any requirement of one of the individual components,
|
|
|
|
since it replaces them.
|
|
|
|
|
2012-05-12 16:27:28 +00:00
|
|
|
Caution is advised when using replace for the sub-package purpose explained
|
|
|
|
above. You should then typically only replace using `self.version` as a version
|
2012-05-12 10:08:35 +00:00
|
|
|
constraint, to make sure the main package only replaces the sub-packages of
|
|
|
|
that exact version, and not any other version, which would be incorrect.
|
|
|
|
|
|
|
|
#### provide
|
|
|
|
|
2021-01-08 08:29:25 +00:00
|
|
|
Map of packages that are provided by this package. This is mostly
|
2020-10-22 13:13:01 +00:00
|
|
|
useful for implementations of common interfaces. A package could depend on
|
2021-01-08 08:29:25 +00:00
|
|
|
some virtual package e.g. `psr/logger-implementation`, any library that implements
|
|
|
|
this logger interface would list it in `provide`. Implementors can then
|
|
|
|
be [found on Packagist.org](https://packagist.org/providers/psr/log-implementation).
|
|
|
|
|
2020-10-22 13:13:01 +00:00
|
|
|
Using `provide` with the name of an actual package rather than a virtual one
|
|
|
|
implies that the code of that package is also shipped, in which case `replace`
|
|
|
|
is generally a better choice. A common convention for packages providing an
|
|
|
|
interface and relying on other packages to provide an implementation (for
|
|
|
|
instance the PSR interfaces) is to use a `-implementation` suffix for the
|
|
|
|
name of the virtual package corresponding to the interface package.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2015-01-09 09:08:13 +00:00
|
|
|
#### suggest
|
2012-04-14 21:52:52 +00:00
|
|
|
|
|
|
|
Suggested packages that can enhance or work well with this package. These are
|
2018-03-23 10:37:33 +00:00
|
|
|
informational and are displayed after the package is installed, to give
|
2012-04-14 21:52:52 +00:00
|
|
|
your users a hint that they could add more packages, even though they are not
|
|
|
|
strictly required.
|
|
|
|
|
|
|
|
The format is like package links above, except that the values are free text
|
|
|
|
and not version constraints.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"suggest": {
|
2016-09-29 06:20:23 +00:00
|
|
|
"monolog/monolog": "Allows more advanced logging of the application flow",
|
|
|
|
"ext-xml": "Needed to support XML format in class Foo"
|
2012-04-14 21:52:52 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-04-14 21:52:52 +00:00
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### autoload
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Autoload mapping for a PHP autoloader.
|
|
|
|
|
2020-04-12 22:54:46 +00:00
|
|
|
[`PSR-4`](https://www.php-fig.org/psr/psr-4/) and [`PSR-0`](http://www.php-fig.org/psr/psr-0/)
|
2017-03-07 11:33:19 +00:00
|
|
|
autoloading, `classmap` generation and `files` includes are supported.
|
|
|
|
|
|
|
|
PSR-4 is the recommended way since it offers greater ease of use (no need
|
|
|
|
to regenerate the autoloader when you add classes).
|
2014-01-03 15:46:56 +00:00
|
|
|
|
|
|
|
#### PSR-4
|
|
|
|
|
|
|
|
Under the `psr-4` key you define a mapping from namespaces to paths, relative to the
|
|
|
|
package root. When autoloading a class like `Foo\\Bar\\Baz` a namespace prefix
|
|
|
|
`Foo\\` pointing to a directory `src/` means that the autoloader will look for a
|
|
|
|
file named `src/Bar/Baz.php` and include it if present. Note that as opposed to
|
|
|
|
the older PSR-0 style, the prefix (`Foo\\`) is **not** present in the file path.
|
|
|
|
|
|
|
|
Namespace prefixes must end in `\\` to avoid conflicts between similar prefixes.
|
|
|
|
For example `Foo` would match classes in the `FooBar` namespace so the trailing
|
|
|
|
backslashes solve the problem: `Foo\\` and `FooBar\\` are distinct.
|
|
|
|
|
|
|
|
The PSR-4 references are all combined, during install/update, into a single
|
|
|
|
key => value array which may be found in the generated file
|
|
|
|
`vendor/composer/autoload_psr4.php`.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-4": {
|
|
|
|
"Monolog\\": "src/",
|
|
|
|
"Vendor\\Namespace\\": ""
|
2014-01-03 15:46:56 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2014-01-03 15:46:56 +00:00
|
|
|
|
|
|
|
If you need to search for a same prefix in multiple directories,
|
|
|
|
you can specify them as an array as such:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-4": { "Monolog\\": ["src/", "lib/"] }
|
2014-01-03 15:46:56 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2014-01-03 15:46:56 +00:00
|
|
|
|
|
|
|
If you want to have a fallback directory where any namespace will be looked for,
|
|
|
|
you can use an empty prefix like:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-4": { "": "src/" }
|
2014-01-03 15:46:56 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-03-05 13:13:06 +00:00
|
|
|
|
2012-10-24 12:31:59 +00:00
|
|
|
#### PSR-0
|
|
|
|
|
2012-03-05 13:13:06 +00:00
|
|
|
Under the `psr-0` key you define a mapping from namespaces to paths, relative to the
|
2012-06-04 03:15:59 +00:00
|
|
|
package root. Note that this also supports the PEAR-style non-namespaced convention.
|
|
|
|
|
2013-05-13 12:58:11 +00:00
|
|
|
Please note namespace declarations should end in `\\` to make sure the autoloader
|
2013-05-13 13:03:42 +00:00
|
|
|
responds exactly. For example `Foo` would match in `FooBar` so the trailing
|
2013-05-13 12:58:11 +00:00
|
|
|
backslashes solve the problem: `Foo\\` and `FooBar\\` are distinct.
|
|
|
|
|
2012-06-07 10:25:05 +00:00
|
|
|
The PSR-0 references are all combined, during install/update, into a single key => value
|
2012-06-04 03:15:59 +00:00
|
|
|
array which may be found in the generated file `vendor/composer/autoload_namespaces.php`.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-0": {
|
|
|
|
"Monolog\\": "src/",
|
|
|
|
"Vendor\\Namespace\\": "src/",
|
|
|
|
"Vendor_Namespace_": "src/"
|
2012-02-29 14:56:53 +00:00
|
|
|
}
|
2012-02-19 20:07:30 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-04-27 08:01:01 +00:00
|
|
|
If you need to search for a same prefix in multiple directories,
|
2012-03-28 15:09:07 +00:00
|
|
|
you can specify them as an array as such:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-0": { "Monolog\\": ["src/", "lib/"] }
|
2012-03-28 15:09:07 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-06-07 10:25:05 +00:00
|
|
|
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
|
|
|
|
only one class in the global namespace. If the php source file is also located
|
2012-06-04 03:15:59 +00:00
|
|
|
in the root of the package, for example, it may be declared like this:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-0": { "UniqueGlobalClass": "" }
|
2012-06-04 03:15:59 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-06-04 03:15:59 +00:00
|
|
|
|
2012-04-27 08:01:01 +00:00
|
|
|
If you want to have a fallback directory where any namespace can be, you can
|
|
|
|
use an empty prefix like:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-0": { "": "src/" }
|
2012-04-27 08:01:01 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-04-27 08:01:01 +00:00
|
|
|
|
2012-10-24 12:31:59 +00:00
|
|
|
#### Classmap
|
|
|
|
|
2012-06-07 10:25:05 +00:00
|
|
|
The `classmap` references are all combined, during install/update, into a single
|
|
|
|
key => value array which may be found in the generated file
|
2012-12-08 20:54:51 +00:00
|
|
|
`vendor/composer/autoload_classmap.php`. This map is built by scanning for
|
|
|
|
classes in all `.php` and `.inc` files in the given directories/files.
|
2012-06-04 03:15:59 +00:00
|
|
|
|
2012-03-05 13:13:06 +00:00
|
|
|
You can use the classmap generation support to define autoloading for all libraries
|
2014-01-03 15:46:56 +00:00
|
|
|
that do not follow PSR-0/4. To configure this you specify all directories or files
|
2012-03-05 13:13:06 +00:00
|
|
|
to search for classes.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"classmap": ["src/", "lib/", "Something.php"]
|
2012-03-05 13:13:06 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-03-05 13:13:06 +00:00
|
|
|
|
2020-06-03 11:12:22 +00:00
|
|
|
Wildcards (`*`) are also supported in a classmap paths, and expand to match any directory name:
|
2020-06-03 09:04:43 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"classmap": ["src/addons/*/lib/", "3rd-party/*", "Something.php"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2012-10-24 12:31:59 +00:00
|
|
|
#### Files
|
|
|
|
|
2012-06-02 16:18:33 +00:00
|
|
|
If you want to require certain files explicitly on every request then you can use
|
2017-12-29 11:44:51 +00:00
|
|
|
the `files` autoloading mechanism. This is useful if your package includes PHP functions
|
2012-06-02 16:18:33 +00:00
|
|
|
that cannot be autoloaded by PHP.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"files": ["src/MyLibrary/functions.php"]
|
2012-06-02 16:18:33 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-06-02 16:18:33 +00:00
|
|
|
|
2022-06-07 13:27:43 +00:00
|
|
|
Files autoload rules are included whenever `vendor/autoload.php` is included, right after
|
|
|
|
the autoloader is registered. The order of inclusion depends on package dependencies so that
|
|
|
|
if package A depends on B, files in package B will be included first to ensure package B is fully
|
|
|
|
initialized and ready to be used when files from package A are included.
|
|
|
|
|
|
|
|
If two packages have the same amount of dependents or no dependencies, the order is alphabetical.
|
|
|
|
|
|
|
|
Files from the root package are always loaded last, and you cannot use files autoloading
|
|
|
|
yourself to override functions from your dependencies. If you want to achieve that we recommend
|
|
|
|
you include your own functions *before* including Composer's `vendor/autoload.php`.
|
|
|
|
|
2015-10-30 00:00:44 +00:00
|
|
|
#### Exclude files from classmaps
|
2015-02-17 14:56:34 +00:00
|
|
|
|
2017-12-29 11:44:51 +00:00
|
|
|
If you want to exclude some files or folders from the classmap you can use the `exclude-from-classmap` property.
|
2015-10-30 18:50:47 +00:00
|
|
|
This might be useful to exclude test classes in your live environment, for example, as those will be skipped
|
|
|
|
from the classmap even when building an optimized autoloader.
|
2015-10-30 00:00:44 +00:00
|
|
|
|
2015-10-30 20:48:00 +00:00
|
|
|
The classmap generator will ignore all files in the paths configured here. The paths are absolute from the package
|
|
|
|
root directory (i.e. composer.json location), and support `*` to match anything but a slash, and `**` to
|
|
|
|
match anything. `**` is implicitly added to the end of the paths.
|
2015-02-17 14:56:34 +00:00
|
|
|
|
2015-10-30 00:00:44 +00:00
|
|
|
Example:
|
2015-02-17 14:56:34 +00:00
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"exclude-from-classmap": ["/Tests/", "/test/", "/tests/"]
|
|
|
|
}
|
|
|
|
}
|
2015-10-30 18:50:47 +00:00
|
|
|
```
|
2015-02-17 14:56:34 +00:00
|
|
|
|
2017-03-07 11:33:19 +00:00
|
|
|
#### Optimizing the autoloader
|
|
|
|
|
|
|
|
The autoloader can have quite a substantial impact on your request time
|
|
|
|
(50-100ms per request in large frameworks using a lot of classes). See the
|
2017-12-29 11:44:51 +00:00
|
|
|
[article about optimizing the autoloader](articles/autoloader-optimization.md)
|
2017-03-07 11:33:19 +00:00
|
|
|
for more details on how to reduce this impact.
|
|
|
|
|
2015-06-22 08:00:04 +00:00
|
|
|
### autoload-dev <span>([root-only](04-schema.md#root-package))</span>
|
2014-02-27 09:39:33 +00:00
|
|
|
|
2021-12-19 14:15:21 +00:00
|
|
|
This section allows defining autoload rules for development purposes.
|
2014-02-27 09:39:33 +00:00
|
|
|
|
2014-03-01 19:39:06 +00:00
|
|
|
Classes needed to run the test suite should not be included in the main autoload
|
|
|
|
rules to avoid polluting the autoloader in production and when other people use
|
|
|
|
your package as a dependency.
|
2014-02-27 09:39:33 +00:00
|
|
|
|
2014-03-01 19:39:06 +00:00
|
|
|
Therefore, it is a good idea to rely on a dedicated path for your unit tests
|
|
|
|
and to add it within the autoload-dev section.
|
2014-02-27 09:39:33 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-4": { "MyLibrary\\": "src/" }
|
|
|
|
},
|
|
|
|
"autoload-dev": {
|
|
|
|
"psr-4": { "MyLibrary\\Tests\\": "tests/" }
|
2014-02-27 09:39:33 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2014-02-27 09:39:33 +00:00
|
|
|
|
2012-04-08 15:42:57 +00:00
|
|
|
### include-path
|
|
|
|
|
2012-05-12 10:13:15 +00:00
|
|
|
> **DEPRECATED**: This is only present to support legacy projects, and all new code
|
|
|
|
> should preferably use autoloading. As such it is a deprecated practice, but the
|
|
|
|
> feature itself will not likely disappear from Composer.
|
2012-04-04 08:39:00 +00:00
|
|
|
|
|
|
|
A list of paths which should get appended to PHP's `include_path`.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"include-path": ["lib/"]
|
|
|
|
}
|
|
|
|
```
|
2012-04-04 08:39:00 +00:00
|
|
|
|
2012-04-13 10:41:16 +00:00
|
|
|
Optional.
|
|
|
|
|
2012-03-18 10:49:06 +00:00
|
|
|
### target-dir
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2014-01-03 15:46:56 +00:00
|
|
|
> **DEPRECATED**: This is only present to support legacy PSR-0 style autoloading,
|
|
|
|
> and all new code should preferably use PSR-4 without target-dir and projects
|
|
|
|
> using PSR-0 with PHP namespaces are encouraged to migrate to PSR-4 instead.
|
|
|
|
|
2012-02-19 20:07:30 +00:00
|
|
|
Defines the installation target.
|
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
In case the package root is below the namespace declaration you cannot
|
|
|
|
autoload properly. `target-dir` solves this problem.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
An example is Symfony. There are individual packages for the components. The
|
|
|
|
Yaml component is under `Symfony\Component\Yaml`. The package root is that
|
|
|
|
`Yaml` directory. To make autoloading possible, we need to make sure that it
|
|
|
|
is not installed into `vendor/symfony/yaml`, but instead into
|
|
|
|
`vendor/symfony/yaml/Symfony/Component/Yaml`, so that the autoloader can load
|
|
|
|
it from `vendor/symfony/yaml`.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
To do that, `autoload` and `target-dir` are defined as follows:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"autoload": {
|
|
|
|
"psr-0": { "Symfony\\Component\\Yaml\\": "" }
|
|
|
|
},
|
|
|
|
"target-dir": "Symfony/Component/Yaml"
|
|
|
|
}
|
|
|
|
```
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2015-06-22 08:00:04 +00:00
|
|
|
### minimum-stability <span>([root-only](04-schema.md#root-package))</span>
|
2012-05-12 10:08:35 +00:00
|
|
|
|
|
|
|
This defines the default behavior for filtering packages by stability. This
|
2012-07-04 14:37:28 +00:00
|
|
|
defaults to `stable`, so if you rely on a `dev` package, you should specify
|
|
|
|
it in your file to avoid surprises.
|
2012-05-12 10:08:35 +00:00
|
|
|
|
2012-07-04 14:37:28 +00:00
|
|
|
All versions of each package are checked for stability, and those that are less
|
2012-05-12 10:08:35 +00:00
|
|
|
stable than the `minimum-stability` setting will be ignored when resolving
|
2017-01-23 19:06:51 +00:00
|
|
|
your project dependencies. (Note that you can also specify stability requirements
|
|
|
|
on a per-package basis using stability flags in the version constraints that you
|
|
|
|
specify in a `require` block (see [package links](#package-links) for more details).
|
2012-05-12 10:08:35 +00:00
|
|
|
|
2012-09-10 15:18:22 +00:00
|
|
|
Available options (in order of stability) are `dev`, `alpha`, `beta`, `RC`,
|
|
|
|
and `stable`.
|
2012-07-04 14:37:28 +00:00
|
|
|
|
2015-06-22 08:00:04 +00:00
|
|
|
### prefer-stable <span>([root-only](04-schema.md#root-package))</span>
|
2013-03-30 19:02:29 +00:00
|
|
|
|
|
|
|
When this is enabled, Composer will prefer more stable packages over unstable
|
|
|
|
ones when finding compatible stable packages is possible. If you require a
|
|
|
|
dev version or only alphas are available for a package, those will still be
|
2013-06-30 22:14:57 +00:00
|
|
|
selected granted that the minimum-stability allows for it.
|
|
|
|
|
|
|
|
Use `"prefer-stable": true` to enable.
|
2013-03-30 19:02:29 +00:00
|
|
|
|
2015-06-22 08:00:04 +00:00
|
|
|
### repositories <span>([root-only](04-schema.md#root-package))</span>
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Custom package repositories to use.
|
|
|
|
|
2018-03-23 10:37:33 +00:00
|
|
|
By default Composer only uses the packagist repository. By specifying
|
2012-02-20 10:08:18 +00:00
|
|
|
repositories you can get packages from elsewhere.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
Repositories are not resolved recursively. You can only add them to your main
|
|
|
|
`composer.json`. Repository declarations of dependencies' `composer.json`s are
|
|
|
|
ignored.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2012-02-26 11:40:35 +00:00
|
|
|
The following repository types are supported:
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2020-10-23 19:52:05 +00:00
|
|
|
* **composer:** A Composer repository is a `packages.json` file served
|
2012-10-03 18:32:00 +00:00
|
|
|
via the network (HTTP, FTP, SSH), that contains a list of `composer.json`
|
|
|
|
objects with additional `dist` and/or `source` information. The `packages.json`
|
|
|
|
file is loaded using a PHP stream. You can set extra options on that stream
|
|
|
|
using the `options` parameter.
|
2012-02-20 10:08:18 +00:00
|
|
|
* **vcs:** The version control system repository can fetch packages from git,
|
2016-06-22 05:19:29 +00:00
|
|
|
svn, fossil and hg repositories.
|
2012-02-20 10:08:18 +00:00
|
|
|
* **package:** If you depend on a project that does not have any support for
|
2021-10-25 11:11:56 +00:00
|
|
|
Composer whatsoever you can define the package inline using a `package`
|
2018-03-23 10:37:33 +00:00
|
|
|
repository. You basically inline the `composer.json` object.
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-03-07 23:18:03 +00:00
|
|
|
For more information on any of these, see [Repositories](05-repositories.md).
|
2012-02-19 20:07:30 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "composer",
|
|
|
|
"url": "http://packages.example.com"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "composer",
|
|
|
|
"url": "https://packages.example.com",
|
|
|
|
"options": {
|
|
|
|
"ssl": {
|
|
|
|
"verify_peer": "true"
|
2012-10-03 18:32:00 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "vcs",
|
|
|
|
"url": "https://github.com/Seldaek/monolog"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "package",
|
|
|
|
"package": {
|
|
|
|
"name": "smarty/smarty",
|
|
|
|
"version": "3.1.7",
|
|
|
|
"dist": {
|
2017-12-29 10:33:19 +00:00
|
|
|
"url": "https://www.smarty.net/files/Smarty-3.1.7.zip",
|
2014-05-19 10:17:07 +00:00
|
|
|
"type": "zip"
|
|
|
|
},
|
|
|
|
"source": {
|
2015-05-04 17:37:57 +00:00
|
|
|
"url": "https://smarty-php.googlecode.com/svn/",
|
2014-05-19 10:17:07 +00:00
|
|
|
"type": "svn",
|
|
|
|
"reference": "tags/Smarty_3_1_7/distribution/"
|
2012-02-19 20:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2012-02-19 20:07:30 +00:00
|
|
|
|
2012-03-15 00:13:10 +00:00
|
|
|
> **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.
|
|
|
|
By default Packagist is added last which means that custom repositories can
|
|
|
|
override packages from it.
|
2012-02-20 00:04:35 +00:00
|
|
|
|
2016-10-10 08:10:06 +00:00
|
|
|
Using JSON object notation is also possible. However, JSON key/value pairs
|
|
|
|
are to be considered unordered so consistent behaviour cannot be guaranteed.
|
2016-10-09 20:21:57 +00:00
|
|
|
|
2022-08-20 10:23:00 +00:00
|
|
|
```json
|
2016-10-09 20:21:57 +00:00
|
|
|
{
|
|
|
|
"repositories": {
|
2022-08-20 10:23:00 +00:00
|
|
|
"foo": {
|
|
|
|
"type": "composer",
|
|
|
|
"url": "http://packages.foo.com"
|
|
|
|
}
|
2016-10-09 20:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-20 10:23:00 +00:00
|
|
|
```
|
2016-10-09 20:21:57 +00:00
|
|
|
|
2015-06-22 08:02:27 +00:00
|
|
|
### config <span>([root-only](04-schema.md#root-package))</span>
|
|
|
|
|
2015-10-30 00:00:44 +00:00
|
|
|
A set of configuration options. It is only used for projects. See
|
2015-06-22 08:02:27 +00:00
|
|
|
[Config](06-config.md) for a description of each individual option.
|
|
|
|
|
2015-06-22 08:53:04 +00:00
|
|
|
### scripts <span>([root-only](04-schema.md#root-package))</span>
|
|
|
|
|
|
|
|
Composer allows you to hook into various parts of the installation process
|
|
|
|
through the use of scripts.
|
|
|
|
|
|
|
|
See [Scripts](articles/scripts.md) for events details and examples.
|
|
|
|
|
|
|
|
### extra
|
|
|
|
|
|
|
|
Arbitrary extra data for consumption by `scripts`.
|
|
|
|
|
|
|
|
This can be virtually anything. To access it from within a script event
|
|
|
|
handler, you can do:
|
|
|
|
|
|
|
|
```php
|
|
|
|
$extra = $event->getComposer()->getPackage()->getExtra();
|
|
|
|
```
|
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
|
|
|
### bin
|
|
|
|
|
2021-11-25 08:53:03 +00:00
|
|
|
A set of files that should be treated as binaries and made available
|
|
|
|
into the `bin-dir` (from config).
|
2015-06-22 08:53:04 +00:00
|
|
|
|
|
|
|
See [Vendor Binaries](articles/vendor-binaries.md) for more details.
|
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
|
|
|
### archive
|
|
|
|
|
|
|
|
A set of options for creating package archives.
|
|
|
|
|
|
|
|
The following options are supported:
|
|
|
|
|
2020-04-28 21:38:08 +00:00
|
|
|
* **name:** Allows configuring base name for archive.
|
|
|
|
By default (if not configured, and `--file` is not passed as command-line argument),
|
|
|
|
`preg_replace('#[^a-z0-9-_]#i', '-', name)` is used.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"name": "org/strangeName",
|
|
|
|
"archive": {
|
|
|
|
"name": "Strange_name"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-06-22 08:53:04 +00:00
|
|
|
* **exclude:** Allows configuring a list of patterns for excluded paths. The
|
|
|
|
pattern syntax matches .gitignore files. A leading exclamation mark (!) will
|
|
|
|
result in any matching files to be included even if a previous pattern
|
|
|
|
excluded them. A leading slash will only match at the beginning of the project
|
|
|
|
relative path. An asterisk will not expand to a directory separator.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"archive": {
|
|
|
|
"exclude": ["/foo/bar", "baz", "/*.test", "!/foo/bar/baz"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
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`.
|
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2018-02-22 16:02:47 +00:00
|
|
|
### abandoned
|
|
|
|
|
|
|
|
Indicates whether this package has been abandoned.
|
|
|
|
|
|
|
|
It can be boolean or a package name/URL pointing to a recommended alternative.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2021-12-19 14:15:21 +00:00
|
|
|
Use `"abandoned": true` to indicate this package is abandoned.
|
2022-06-07 13:27:43 +00:00
|
|
|
Use `"abandoned": "monolog/monolog"` to indicate this package is abandoned, and that
|
2022-01-13 15:00:10 +00:00
|
|
|
the recommended alternative is `monolog/monolog`.
|
2018-02-22 16:02:47 +00:00
|
|
|
|
|
|
|
Defaults to false.
|
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2015-06-22 08:53:04 +00:00
|
|
|
### non-feature-branches
|
|
|
|
|
2015-10-30 00:00:44 +00:00
|
|
|
A list of regex patterns of branch names that are non-numeric (e.g. "latest" or something),
|
2015-06-22 09:08:23 +00:00
|
|
|
that will NOT be handled as feature branches. This is an array of strings.
|
2015-06-22 08:53:04 +00:00
|
|
|
|
|
|
|
If you have non-numeric branch names, for example like "latest", "current", "latest-stable"
|
2015-06-22 09:08:23 +00:00
|
|
|
or something, that do not look like a version number, then Composer handles such branches
|
2015-06-22 08:53:04 +00:00
|
|
|
as feature branches. This means it searches for parent branches, that look like a version
|
2020-06-30 15:39:56 +00:00
|
|
|
or ends at special branches (like master), and the root package version number becomes the
|
2015-06-22 08:53:04 +00:00
|
|
|
version of the parent branch or at least master or something.
|
|
|
|
|
|
|
|
To handle non-numeric named branches as versions instead of searching for a parent branch
|
|
|
|
with a valid version or special branch name like master, you can set patterns for branch
|
2021-12-19 14:15:21 +00:00
|
|
|
names that should be handled as dev version branches.
|
2015-06-22 08:53:04 +00:00
|
|
|
|
|
|
|
This is really helpful when you have dependencies using "self.version", so that not dev-master,
|
|
|
|
but the same branch is installed (in the example: latest-testing).
|
|
|
|
|
|
|
|
An example:
|
|
|
|
|
|
|
|
If you have a testing branch, that is heavily maintained during a testing phase and is
|
2017-12-29 11:44:51 +00:00
|
|
|
deployed to your staging environment, normally `composer show -s` will give you `versions : * dev-master`.
|
2015-06-22 08:53:04 +00:00
|
|
|
|
|
|
|
If you configure `latest-.*` as a pattern for non-feature-branches like this:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"non-feature-branches": ["latest-.*"]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-12-29 11:44:51 +00:00
|
|
|
Then `composer show -s` will give you `versions : * dev-latest-testing`.
|
2015-06-22 08:53:04 +00:00
|
|
|
|
|
|
|
Optional.
|
|
|
|
|
2015-03-30 21:19:20 +00:00
|
|
|
← [Command-line interface](03-cli.md) | [Repositories](05-repositories.md) →
|