2012-02-19 21:31:04 +00:00
|
|
|
# Repositories
|
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
This chapter will explain the concept of packages and repositories, what kinds
|
|
|
|
of repositories are available, and how they work.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
|
|
|
## Concepts
|
|
|
|
|
2012-02-26 11:40:35 +00:00
|
|
|
Before we look at the different types of repositories that exist, we need to
|
2015-06-22 09:08:23 +00:00
|
|
|
understand some of the basic concepts that Composer is built on.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
|
|
|
### Package
|
|
|
|
|
2012-02-26 11:40:35 +00:00
|
|
|
Composer is a dependency manager. It installs packages locally. A package is
|
2012-02-20 10:08:18 +00:00
|
|
|
essentially just a directory containing something. In this case it is PHP
|
|
|
|
code, but in theory it could be anything. And it contains a package
|
|
|
|
description which has a name and a version. The name and the version are used
|
|
|
|
to identify the package.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2015-06-22 09:08:23 +00:00
|
|
|
In fact, internally Composer sees every version as a separate package. While
|
|
|
|
this distinction does not matter when you are using Composer, it's quite
|
2012-02-20 10:08:18 +00:00
|
|
|
important when you want to change it.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2012-03-23 19:58:12 +00:00
|
|
|
In addition to the name and the version, there is useful metadata. The information
|
2012-02-26 11:40:35 +00:00
|
|
|
most relevant for installation is the source definition, which describes where
|
|
|
|
to get the package contents. The package data points to the contents of the
|
2012-02-20 10:08:18 +00:00
|
|
|
package. And there are two options here: dist and source.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
**Dist:** The dist is a packaged version of the package data. Usually a
|
|
|
|
released version, usually a stable release.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
**Source:** The source is used for development. This will usually originate
|
|
|
|
from a source code repository, such as git. You can fetch this when you want
|
|
|
|
to modify the downloaded package.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
Packages can supply either of these, or even both. Depending on certain
|
|
|
|
factors, such as user-supplied options and stability of the package, one will
|
|
|
|
be preferred.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
|
|
|
### Repository
|
|
|
|
|
2012-03-23 19:58:12 +00:00
|
|
|
A repository is a package source. It's a list of packages/versions. Composer
|
|
|
|
will look in all your repositories to find the packages your project requires.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2012-03-23 19:58:12 +00:00
|
|
|
By default only the Packagist repository is registered in Composer. You can
|
|
|
|
add more repositories to your project by declaring them in `composer.json`.
|
|
|
|
|
|
|
|
Repositories are only available to the root package and the repositories
|
|
|
|
defined in your dependencies will not be loaded. Read the
|
|
|
|
[FAQ entry](faqs/why-can't-composer-load-repositories-recursively.md) if you
|
|
|
|
want to learn why.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
|
|
|
## Types
|
|
|
|
|
|
|
|
### Composer
|
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
The main repository type is the `composer` repository. It uses a single
|
2012-04-26 15:19:39 +00:00
|
|
|
`packages.json` file that contains all of the package metadata.
|
|
|
|
|
|
|
|
This is also the repository type that packagist uses. To reference a
|
|
|
|
`composer` repository, just supply the path before the `packages.json` file.
|
|
|
|
In case of packagist, that file is located at `/packages.json`, so the URL of
|
|
|
|
the repository would be `packagist.org`. For `example.org/packages.json` the
|
|
|
|
repository URL would be `example.org`.
|
|
|
|
|
|
|
|
#### packages
|
|
|
|
|
|
|
|
The only required field is `packages`. The JSON structure is as follows:
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"packages": {
|
|
|
|
"vendor/package-name": {
|
|
|
|
"dev-master": { @composer.json },
|
|
|
|
"1.0.x-dev": { @composer.json },
|
|
|
|
"0.0.1": { @composer.json },
|
|
|
|
"1.0.0": { @composer.json }
|
2012-02-19 21:31:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
The `@composer.json` marker would be the contents of the `composer.json` from
|
|
|
|
that package version including as a minimum:
|
2012-02-19 21:31:04 +00:00
|
|
|
|
|
|
|
* name
|
|
|
|
* version
|
|
|
|
* dist or source
|
|
|
|
|
|
|
|
Here is a minimal package definition:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"name": "smarty/smarty",
|
|
|
|
"version": "3.1.7",
|
|
|
|
"dist": {
|
|
|
|
"url": "http://www.smarty.net/files/Smarty-3.1.7.zip",
|
|
|
|
"type": "zip"
|
2012-02-19 21:31:04 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2012-03-07 23:18:03 +00:00
|
|
|
It may include any of the other fields specified in the [schema](04-schema.md).
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2013-02-21 16:41:16 +00:00
|
|
|
#### notify-batch
|
2012-04-26 15:19:39 +00:00
|
|
|
|
2015-04-28 12:39:22 +00:00
|
|
|
The `notify-batch` field allows you to specify a URL that will be called
|
2012-11-30 16:29:56 +00:00
|
|
|
every time a user installs a package. The URL can be either an absolute path
|
|
|
|
(that will use the same domain as the repository) or a fully qualified URL.
|
2012-04-26 15:19:39 +00:00
|
|
|
|
|
|
|
An example value:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"notify-batch": "/downloads/"
|
|
|
|
}
|
|
|
|
```
|
2012-04-26 15:19:39 +00:00
|
|
|
|
|
|
|
For `example.org/packages.json` containing a `monolog/monolog` package, this
|
2012-11-30 15:55:04 +00:00
|
|
|
would send a `POST` request to `example.org/downloads/` with following
|
|
|
|
JSON request body:
|
2012-04-26 15:19:39 +00:00
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"downloads": [
|
2015-01-16 19:59:30 +00:00
|
|
|
{"name": "monolog/monolog", "version": "1.2.1.0"}
|
2014-05-19 10:17:07 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2012-11-30 15:55:04 +00:00
|
|
|
|
|
|
|
The version field will contain the normalized representation of the version
|
|
|
|
number.
|
|
|
|
|
2012-04-26 15:19:39 +00:00
|
|
|
This field is optional.
|
|
|
|
|
|
|
|
#### includes
|
|
|
|
|
2013-02-21 16:41:16 +00:00
|
|
|
For larger repositories it is possible to split the `packages.json` into
|
2012-04-26 17:04:06 +00:00
|
|
|
multiple files. The `includes` field allows you to reference these additional
|
|
|
|
files.
|
2012-04-26 15:19:39 +00:00
|
|
|
|
|
|
|
An example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"includes": {
|
|
|
|
"packages-2011.json": {
|
|
|
|
"sha1": "525a85fb37edd1ad71040d429928c2c0edec9d17"
|
|
|
|
},
|
|
|
|
"packages-2012-01.json": {
|
|
|
|
"sha1": "897cde726f8a3918faf27c803b336da223d400dd"
|
|
|
|
},
|
|
|
|
"packages-2012-02.json": {
|
|
|
|
"sha1": "26f911ad717da26bbcac3f8f435280d13917efa5"
|
2012-04-26 15:19:39 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-04-26 15:19:39 +00:00
|
|
|
|
|
|
|
The SHA-1 sum of the file allows it to be cached and only re-requested if the
|
2012-04-26 17:04:06 +00:00
|
|
|
hash changed.
|
2012-04-26 15:19:39 +00:00
|
|
|
|
|
|
|
This field is optional. You probably don't need it for your own custom
|
|
|
|
repository.
|
2012-02-19 21:31:04 +00:00
|
|
|
|
2013-02-21 16:41:16 +00:00
|
|
|
#### provider-includes and providers-url
|
|
|
|
|
|
|
|
For very large repositories like packagist.org using the so-called provider
|
|
|
|
files is the preferred method. The `provider-includes` field allows you to
|
|
|
|
list a set of files that list package names provided by this repository. The
|
|
|
|
hash should be a sha256 of the files in this case.
|
|
|
|
|
|
|
|
The `providers-url` describes how provider files are found on the server. It
|
|
|
|
is an absolute path from the repository root.
|
|
|
|
|
|
|
|
An example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"provider-includes": {
|
|
|
|
"providers-a.json": {
|
|
|
|
"sha256": "f5b4bc0b354108ef08614e569c1ed01a2782e67641744864a74e788982886f4c"
|
2013-02-21 16:41:16 +00:00
|
|
|
},
|
2014-05-19 10:17:07 +00:00
|
|
|
"providers-b.json": {
|
|
|
|
"sha256": "b38372163fac0573053536f5b8ef11b86f804ea8b016d239e706191203f6efac"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"providers-url": "/p/%package%$%hash%.json"
|
|
|
|
}
|
|
|
|
```
|
2013-02-21 16:41:16 +00:00
|
|
|
|
|
|
|
Those files contain lists of package names and hashes to verify the file
|
|
|
|
integrity, for example:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"providers": {
|
|
|
|
"acme/foo": {
|
|
|
|
"sha256": "38968de1305c2e17f4de33aea164515bc787c42c7e2d6e25948539a14268bb82"
|
|
|
|
},
|
|
|
|
"acme/bar": {
|
|
|
|
"sha256": "4dd24c930bd6e1103251306d6336ac813b563a220d9ca14f4743c032fb047233"
|
2013-02-21 16:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2013-02-21 16:41:16 +00:00
|
|
|
|
|
|
|
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
|
2014-01-27 23:27:15 +00:00
|
|
|
`%package%` by the package name and `%hash%` by the sha256 field. Those files
|
2013-02-21 16:41:16 +00:00
|
|
|
themselves just contain package definitions as described [above](#packages).
|
|
|
|
|
|
|
|
This field is optional. You probably don't need it for your own custom
|
|
|
|
repository.
|
|
|
|
|
2012-10-03 18:32:00 +00:00
|
|
|
#### stream options
|
|
|
|
|
|
|
|
The `packages.json` file is loaded using a PHP stream. You can set extra options
|
|
|
|
on that stream using the `options` parameter. You can set any valid PHP stream
|
2015-05-04 17:37:57 +00:00
|
|
|
context option. See [Context options and parameters](https://php.net/manual/en/context.php)
|
2012-10-03 18:32:00 +00:00
|
|
|
for more information.
|
|
|
|
|
2012-02-19 21:31:04 +00:00
|
|
|
### VCS
|
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
VCS stands for version control system. This includes versioning systems like
|
|
|
|
git, svn or hg. Composer has a repository type for installing packages from
|
|
|
|
these systems.
|
2012-02-20 00:04:35 +00:00
|
|
|
|
2012-11-08 14:18:13 +00:00
|
|
|
#### Loading a package from a VCS repository
|
2012-08-27 11:59:34 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
There are a few use cases for this. The most common one is maintaining your
|
|
|
|
own fork of a third party library. If you are using a certain library for your
|
|
|
|
project and you decide to change something in the library, you will want your
|
|
|
|
project to use the patched version. If the library is on GitHub (this is the
|
|
|
|
case most of the time), you can simply fork it there and push your changes to
|
|
|
|
your fork. After that you update the project's `composer.json`. All you have
|
|
|
|
to do is add your fork as a repository and update the version constraint to
|
2015-02-25 16:46:36 +00:00
|
|
|
point to your custom branch. Your custom branch name must be prefixed with `"dev-"`. For version constraint naming conventions see
|
2012-08-15 10:04:32 +00:00
|
|
|
[Libraries](02-libraries.md) for more information.
|
2012-02-20 00:04:35 +00:00
|
|
|
|
|
|
|
Example assuming you patched monolog to fix a bug in the `bugfix` branch:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "vcs",
|
|
|
|
"url": "https://github.com/igorw/monolog"
|
2012-02-20 00:04:35 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
],
|
|
|
|
"require": {
|
|
|
|
"monolog/monolog": "dev-bugfix"
|
2012-02-20 00:04:35 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-02-20 00:04:35 +00:00
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
When you run `php composer.phar update`, you should get your modified version
|
|
|
|
of `monolog/monolog` instead of the one from packagist.
|
2012-02-20 00:04:35 +00:00
|
|
|
|
2013-04-03 07:17:46 +00:00
|
|
|
Note that you should not rename the package unless you really intend to fork
|
|
|
|
it in the long term, and completely move away from the original package.
|
|
|
|
Composer will correctly pick your package over the original one since the
|
|
|
|
custom repository has priority over packagist. If you want to rename the
|
|
|
|
package, you should do so in the default (often master) branch and not in a
|
|
|
|
feature branch, since the package name is taken from the default branch.
|
|
|
|
|
2015-08-09 14:09:34 +00:00
|
|
|
Also note that the override will not work if you change the `name` property
|
2016-03-25 11:17:29 +00:00
|
|
|
in your forked repository's `composer.json` file as this needs to match the
|
2015-08-09 14:09:34 +00:00
|
|
|
original for the override to work.
|
2015-08-04 20:54:43 +00:00
|
|
|
|
2013-04-03 07:17:46 +00:00
|
|
|
If other dependencies rely on the package you forked, it is possible to
|
|
|
|
inline-alias it so that it matches a constraint that it otherwise would not.
|
|
|
|
For more information [see the aliases article](articles/aliases.md).
|
2012-11-07 12:11:09 +00:00
|
|
|
|
2012-11-08 14:18:13 +00:00
|
|
|
#### Using private repositories
|
|
|
|
|
2012-11-07 16:04:44 +00:00
|
|
|
Exactly the same solution allows you to work with your private repositories at
|
|
|
|
GitHub and BitBucket:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"require": {
|
|
|
|
"vendor/my-private-repo": "dev-master"
|
|
|
|
},
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "vcs",
|
|
|
|
"url": "git@bitbucket.org:vendor/my-private-repo.git"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2012-11-07 16:04:44 +00:00
|
|
|
|
|
|
|
The only requirement is the installation of SSH keys for a git client.
|
|
|
|
|
2012-08-27 11:59:34 +00:00
|
|
|
#### Git alternatives
|
|
|
|
|
2012-02-20 10:08:18 +00:00
|
|
|
Git is not the only version control system supported by the VCS repository.
|
|
|
|
The following are supported:
|
2012-02-20 00:04:35 +00:00
|
|
|
|
2015-05-04 17:37:57 +00:00
|
|
|
* **Git:** [git-scm.com](https://git-scm.com)
|
|
|
|
* **Subversion:** [subversion.apache.org](https://subversion.apache.org)
|
2012-02-20 00:04:35 +00:00
|
|
|
* **Mercurial:** [mercurial.selenic.com](http://mercurial.selenic.com)
|
|
|
|
|
2012-02-26 11:40:35 +00:00
|
|
|
To get packages from these systems you need to have their respective clients
|
2012-02-26 13:16:08 +00:00
|
|
|
installed. That can be inconvenient. And for this reason there is special
|
2012-02-26 11:40:35 +00:00
|
|
|
support for GitHub and BitBucket that use the APIs provided by these sites, to
|
|
|
|
fetch the packages without having to install the version control system. The
|
|
|
|
VCS repository provides `dist`s for them that fetch the packages as zips.
|
2012-02-20 00:04:35 +00:00
|
|
|
|
|
|
|
* **GitHub:** [github.com](https://github.com) (Git)
|
|
|
|
* **BitBucket:** [bitbucket.org](https://bitbucket.org) (Git and Mercurial)
|
|
|
|
|
2012-03-09 17:32:49 +00:00
|
|
|
The VCS driver to be used is detected automatically based on the URL. However,
|
|
|
|
should you need to specify one for whatever reason, you can use `git`, `svn` or
|
|
|
|
`hg` as the repository type instead of `vcs`.
|
2012-02-20 00:04:35 +00:00
|
|
|
|
2014-02-24 18:22:32 +00:00
|
|
|
If you set the `no-api` key to `true` on a github repository it will clone the
|
|
|
|
repository as it would with any other git repository instead of using the
|
2015-06-22 09:08:23 +00:00
|
|
|
GitHub API. But unlike using the `git` driver directly, Composer will still
|
2014-02-24 18:22:32 +00:00
|
|
|
attempt to use github's zip files.
|
|
|
|
|
2012-10-19 10:31:05 +00:00
|
|
|
#### Subversion Options
|
|
|
|
|
|
|
|
Since Subversion has no native concept of branches and tags, Composer assumes
|
|
|
|
by default that code is located in `$url/trunk`, `$url/branches` and
|
|
|
|
`$url/tags`. If your repository has a different layout you can change those
|
|
|
|
values. For example if you used capitalized names you could configure the
|
|
|
|
repository like this:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "vcs",
|
|
|
|
"url": "http://svn.example.org/projectA/",
|
|
|
|
"trunk-path": "Trunk",
|
|
|
|
"branches-path": "Branches",
|
|
|
|
"tags-path": "Tags"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2012-10-19 10:31:05 +00:00
|
|
|
|
2012-12-08 16:41:21 +00:00
|
|
|
If you have no branches or tags directory you can disable them entirely by
|
|
|
|
setting the `branches-path` or `tags-path` to `false`.
|
|
|
|
|
2013-04-27 15:39:12 +00:00
|
|
|
If the package is in a sub-directory, e.g. `/trunk/foo/bar/composer.json` and
|
2015-06-22 09:08:23 +00:00
|
|
|
`/tags/1.0/foo/bar/composer.json`, then you can make Composer access it by
|
2013-04-27 15:39:12 +00:00
|
|
|
setting the `"package-path"` option to the sub-directory, in this example it
|
|
|
|
would be `"package-path": "foo/bar/"`.
|
|
|
|
|
2014-09-24 13:30:48 +00:00
|
|
|
If you have a private Subversion repository you can save credentials in the
|
2014-09-16 13:16:55 +00:00
|
|
|
http-basic section of your config (See [Schema](04-schema.md)):
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"http-basic": {
|
|
|
|
"svn.example.org": {
|
|
|
|
"username": "username",
|
|
|
|
"password": "password"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
If your Subversion client is configured to store credentials by default these
|
|
|
|
credentials will be saved for the current user and existing saved credentials
|
|
|
|
for this server will be overwritten. To change this behavior by setting the
|
2014-09-24 11:24:54 +00:00
|
|
|
`"svn-cache-credentials"` option in your repository configuration:
|
2014-09-16 13:16:55 +00:00
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "vcs",
|
|
|
|
"url": "http://svn.example.org/projectA/",
|
2014-09-24 11:24:54 +00:00
|
|
|
"svn-cache-credentials": false
|
2014-09-16 13:16:55 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2012-02-19 21:31:04 +00:00
|
|
|
### PEAR
|
|
|
|
|
2012-02-20 13:22:16 +00:00
|
|
|
It is possible to install packages from any PEAR channel by using the `pear`
|
|
|
|
repository. Composer will prefix all package names with `pear-{channelName}/` to
|
2012-06-24 23:03:05 +00:00
|
|
|
avoid conflicts. All packages are also aliased with prefix `pear-{channelAlias}/`
|
2012-02-20 13:22:16 +00:00
|
|
|
|
|
|
|
Example using `pear2.php.net`:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "pear",
|
2015-05-04 17:37:57 +00:00
|
|
|
"url": "https://pear2.php.net"
|
2012-02-20 13:22:16 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
],
|
|
|
|
"require": {
|
|
|
|
"pear-pear2.php.net/PEAR2_Text_Markdown": "*",
|
|
|
|
"pear-pear2/PEAR2_HTTP_Request": "*"
|
2012-02-20 13:22:16 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-02-20 13:22:16 +00:00
|
|
|
|
|
|
|
In this case the short name of the channel is `pear2`, so the
|
|
|
|
`PEAR2_HTTP_Request` package name becomes `pear-pear2/PEAR2_HTTP_Request`.
|
|
|
|
|
|
|
|
> **Note:** The `pear` repository requires doing quite a few requests per
|
|
|
|
> package, so this may considerably slow down the installation process.
|
|
|
|
|
2012-10-16 18:32:07 +00:00
|
|
|
#### Custom vendor alias
|
2012-08-29 20:30:47 +00:00
|
|
|
|
2012-10-16 18:32:07 +00:00
|
|
|
It is possible to alias PEAR channel packages with a custom vendor name.
|
2012-06-24 23:03:05 +00:00
|
|
|
|
|
|
|
Example:
|
2012-08-29 20:30:47 +00:00
|
|
|
|
2012-10-16 18:32:07 +00:00
|
|
|
Suppose you have a private PEAR repository and wish to use Composer to
|
|
|
|
incorporate dependencies from a VCS. Your PEAR repository contains the
|
|
|
|
following packages:
|
2012-08-29 20:30:47 +00:00
|
|
|
|
2012-10-16 18:32:07 +00:00
|
|
|
* `BasePackage`
|
|
|
|
* `IntermediatePackage`, which depends on `BasePackage`
|
|
|
|
* `TopLevelPackage1` and `TopLevelPackage2` which both depend on `IntermediatePackage`
|
2012-07-02 12:11:37 +00:00
|
|
|
|
2012-10-16 18:32:07 +00:00
|
|
|
Without a vendor alias, Composer will use the PEAR channel name as the
|
|
|
|
vendor portion of the package name:
|
2012-08-29 20:30:47 +00:00
|
|
|
|
2012-10-16 18:32:07 +00:00
|
|
|
* `pear-pear.foobar.repo/BasePackage`
|
|
|
|
* `pear-pear.foobar.repo/IntermediatePackage`
|
|
|
|
* `pear-pear.foobar.repo/TopLevelPackage1`
|
|
|
|
* `pear-pear.foobar.repo/TopLevelPackage2`
|
2012-07-02 12:11:37 +00:00
|
|
|
|
2012-10-16 18:32:07 +00:00
|
|
|
Suppose at a later time you wish to migrate your PEAR packages to a
|
|
|
|
Composer repository and naming scheme, and adopt the vendor name of `foobar`.
|
|
|
|
Projects using your PEAR packages would not see the updated packages, since
|
|
|
|
they have a different vendor name (`foobar/IntermediatePackage` vs
|
|
|
|
`pear-pear.foobar.repo/IntermediatePackage`).
|
|
|
|
|
|
|
|
By specifying `vendor-alias` for the PEAR repository from the start, you can
|
|
|
|
avoid this scenario and future-proof your package names.
|
|
|
|
|
|
|
|
To illustrate, the following example would get the `BasePackage`,
|
|
|
|
`TopLevelPackage1`, and `TopLevelPackage2` packages from your PEAR repository
|
|
|
|
and `IntermediatePackage` from a Github repository:
|
2012-07-01 23:10:23 +00:00
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "git",
|
|
|
|
"url": "https://github.com/foobar/intermediate.git"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "pear",
|
|
|
|
"url": "http://pear.foobar.repo",
|
|
|
|
"vendor-alias": "foobar"
|
2012-06-24 23:03:05 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
],
|
|
|
|
"require": {
|
|
|
|
"foobar/TopLevelPackage1": "*",
|
|
|
|
"foobar/TopLevelPackage2": "*"
|
2012-06-24 23:03:05 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-06-24 23:03:05 +00:00
|
|
|
|
2012-02-19 21:31:04 +00:00
|
|
|
### Package
|
|
|
|
|
2015-06-22 09:08:23 +00:00
|
|
|
If you want to use a project that does not support Composer through any of the
|
2012-02-26 11:40:35 +00:00
|
|
|
means above, you still can define the package yourself by using a `package`
|
2012-02-20 13:22:16 +00:00
|
|
|
repository.
|
|
|
|
|
|
|
|
Basically, you define the same information that is included in the `composer`
|
|
|
|
repository's `packages.json`, but only for a single package. Again, the
|
2012-02-26 11:40:35 +00:00
|
|
|
minimum required fields are `name`, `version`, and either of `dist` or
|
2012-02-20 13:22:16 +00:00
|
|
|
`source`.
|
|
|
|
|
|
|
|
Here is an example for the smarty template engine:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "package",
|
|
|
|
"package": {
|
|
|
|
"name": "smarty/smarty",
|
|
|
|
"version": "3.1.7",
|
|
|
|
"dist": {
|
|
|
|
"url": "http://www.smarty.net/files/Smarty-3.1.7.zip",
|
|
|
|
"type": "zip"
|
|
|
|
},
|
|
|
|
"source": {
|
|
|
|
"url": "http://smarty-php.googlecode.com/svn/",
|
|
|
|
"type": "svn",
|
|
|
|
"reference": "tags/Smarty_3_1_7/distribution/"
|
|
|
|
},
|
|
|
|
"autoload": {
|
|
|
|
"classmap": ["libs/"]
|
2012-02-20 13:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
],
|
|
|
|
"require": {
|
|
|
|
"smarty/smarty": "3.1.*"
|
2012-02-20 13:22:16 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-02-20 13:22:16 +00:00
|
|
|
|
|
|
|
Typically you would leave the source part off, as you don't really need it.
|
|
|
|
|
2013-06-18 12:43:21 +00:00
|
|
|
> **Note**: This repository type has a few limitations and should be avoided
|
|
|
|
> whenever possible:
|
|
|
|
>
|
|
|
|
> - Composer will not update the package unless you change the `version` field.
|
|
|
|
> - Composer will not update the commit references, so if you use `master` as
|
|
|
|
> reference you will have to delete the package to force an update, and will
|
|
|
|
> have to deal with an unstable lock file.
|
|
|
|
|
2012-02-20 00:04:35 +00:00
|
|
|
## Hosting your own
|
2012-02-20 14:32:22 +00:00
|
|
|
|
2012-02-20 14:41:05 +00:00
|
|
|
While you will probably want to put your packages on packagist most of the time,
|
|
|
|
there are some use cases for hosting your own repository.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
2015-06-22 09:08:23 +00:00
|
|
|
* **Private company packages:** If you are part of a company that uses Composer
|
2012-02-20 14:41:05 +00:00
|
|
|
for their packages internally, you might want to keep those packages private.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
2012-02-20 14:41:05 +00:00
|
|
|
* **Separate ecosystem:** If you have a project which has its own ecosystem,
|
|
|
|
and the packages aren't really reusable by the greater PHP community, you
|
|
|
|
might want to keep them separate to packagist. An example of this would be
|
|
|
|
wordpress plugins.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
2014-09-16 13:16:55 +00:00
|
|
|
For hosting your own packages, a native `composer` type of repository is
|
2013-10-28 21:28:26 +00:00
|
|
|
recommended, which provides the best performance.
|
2012-02-20 14:41:05 +00:00
|
|
|
|
2012-02-26 11:40:35 +00:00
|
|
|
There are a few tools that can help you create a `composer` repository.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
|
|
|
### Packagist
|
|
|
|
|
2012-02-20 14:41:05 +00:00
|
|
|
The underlying application used by packagist is open source. This means that you
|
2015-02-24 12:49:14 +00:00
|
|
|
can technically install your own copy of packagist. However it is not a
|
|
|
|
supported use case and changes will happen without caring for third parties
|
|
|
|
using the code.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
2012-02-20 14:41:05 +00:00
|
|
|
Packagist is a Symfony2 application, and it is [available on
|
2015-06-22 09:08:23 +00:00
|
|
|
GitHub](https://github.com/composer/packagist). It uses Composer internally and
|
|
|
|
acts as a proxy between VCS repositories and the Composer users. It holds a list
|
|
|
|
of all VCS packages, periodically re-crawls them, and exposes them as a Composer
|
2012-02-20 14:41:05 +00:00
|
|
|
repository.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
2015-02-24 12:49:14 +00:00
|
|
|
### Toran Proxy
|
|
|
|
|
|
|
|
[Toran Proxy](https://toranproxy.com/) is a web app much like Packagist but
|
2015-11-22 16:39:17 +00:00
|
|
|
providing private package hosting as well as mirroring/proxying of GitHub and
|
2015-06-22 09:08:23 +00:00
|
|
|
packagist.org. Check its homepage and the [Satis/Toran Proxy article](articles/handling-private-packages-with-satis.md)
|
2015-02-24 12:49:14 +00:00
|
|
|
for more information.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
|
|
|
### Satis
|
|
|
|
|
2012-02-26 11:40:35 +00:00
|
|
|
Satis is a static `composer` repository generator. It is a bit like an ultra-
|
|
|
|
lightweight, static file-based version of packagist.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
2012-02-26 11:40:35 +00:00
|
|
|
You give it a `composer.json` containing repositories, typically VCS and
|
|
|
|
package repository definitions. It will fetch all the packages that are
|
|
|
|
`require`d and dump a `packages.json` that is your `composer` repository.
|
2012-02-20 14:32:22 +00:00
|
|
|
|
2012-03-23 19:58:12 +00:00
|
|
|
Check [the satis GitHub repository](https://github.com/composer/satis) and
|
|
|
|
the [Satis article](articles/handling-private-packages-with-satis.md) for more
|
2012-02-20 14:41:05 +00:00
|
|
|
information.
|
2012-03-06 23:16:24 +00:00
|
|
|
|
2013-03-25 00:00:12 +00:00
|
|
|
### Artifact
|
|
|
|
|
|
|
|
There are some cases, when there is no ability to have one of the previously
|
|
|
|
mentioned repository types online, even the VCS one. Typical example could be
|
2013-04-03 21:45:31 +00:00
|
|
|
cross-organisation library exchange through built artifacts. Of course, most
|
2013-04-27 15:32:35 +00:00
|
|
|
of the times they are private. To simplify maintenance, one can simply use a
|
2013-03-25 00:00:12 +00:00
|
|
|
repository of type `artifact` with a folder containing ZIP archives of those
|
|
|
|
private packages:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "artifact",
|
|
|
|
"url": "path/to/directory/with/zips/"
|
2013-03-25 00:00:12 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
],
|
|
|
|
"require": {
|
|
|
|
"private-vendor-one/core": "15.6.2",
|
|
|
|
"private-vendor-two/connectivity": "*",
|
|
|
|
"acme-corp/parser": "10.3.5"
|
2013-03-25 00:00:12 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2013-03-25 00:00:12 +00:00
|
|
|
|
|
|
|
Each zip artifact is just a ZIP archive with `composer.json` in root folder:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```sh
|
|
|
|
unzip -l acme-corp-parser-10.3.5.zip
|
|
|
|
|
|
|
|
composer.json
|
|
|
|
...
|
|
|
|
```
|
2013-03-25 00:00:12 +00:00
|
|
|
|
2013-04-27 15:32:35 +00:00
|
|
|
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
|
|
|
|
and you run `update`, that version will be imported as well and Composer will
|
|
|
|
update to the latest version.
|
2013-03-25 00:00:12 +00:00
|
|
|
|
2015-09-14 08:48:15 +00:00
|
|
|
### Path
|
|
|
|
|
2015-09-15 15:39:55 +00:00
|
|
|
In addition to the artifact repository, you can use the path one, which allows
|
|
|
|
you to depend on a relative directory. This can be especially useful when dealing
|
2015-09-14 08:48:15 +00:00
|
|
|
with monolith repositories.
|
|
|
|
|
|
|
|
For instance, if you have the following directory structure in your repository:
|
|
|
|
```
|
|
|
|
- apps
|
|
|
|
\_ my-app
|
|
|
|
\_ composer.json
|
|
|
|
- packages
|
|
|
|
\_ my-package
|
|
|
|
\_ composer.json
|
|
|
|
```
|
|
|
|
|
|
|
|
Then, to add the package `my/package` as a dependency, in your `apps/my-app/composer.json`
|
|
|
|
file, you can use the following configuration:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "path",
|
|
|
|
"url": "../../packages/my-package"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"require": {
|
2015-11-22 16:39:17 +00:00
|
|
|
"my/package": "*"
|
2015-09-14 08:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-01-19 02:34:55 +00:00
|
|
|
If the package is a local VCS repository, the version may be inferred by
|
|
|
|
the branch or tag that is currently checked out. Otherwise, the version should
|
|
|
|
be explicitly defined in the package's `composer.json` file. If the version
|
|
|
|
cannot be resolved by these means, it is assumed to be `dev-master`.
|
|
|
|
|
2015-11-22 16:39:17 +00:00
|
|
|
The local package will be symlinked if possible, in which case the output in
|
|
|
|
the console will read `Symlinked from ../../packages/my-package`. If symlinking
|
|
|
|
is _not_ possible the package will be copied. In that case, the console will
|
2015-11-18 19:14:36 +00:00
|
|
|
output `Mirrored from ../../packages/my-package`.
|
2015-11-15 10:26:00 +00:00
|
|
|
|
2016-02-22 12:41:28 +00:00
|
|
|
Instead of default fallback strategy you can force to use symlink with `"symlink": true` or
|
|
|
|
mirroring with `"symlink": false` option.
|
|
|
|
Forcing mirroring can be useful when deploying or generating package from a monolithic repository.
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"type": "path",
|
|
|
|
"url": "../../packages/my-package",
|
|
|
|
"options": {
|
|
|
|
"symlink": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-18 19:14:36 +00:00
|
|
|
Instead of using a relative path, an absolute path can also be used.
|
2015-11-15 10:26:00 +00:00
|
|
|
|
2015-09-18 12:23:54 +00:00
|
|
|
> **Note:** Repository paths can also contain wildcards like ``*`` and ``?``.
|
|
|
|
> For details, see the [PHP glob function](http://php.net/glob).
|
2015-09-15 15:39:55 +00:00
|
|
|
|
2012-03-23 19:58:12 +00:00
|
|
|
## Disabling Packagist
|
2012-03-06 23:16:24 +00:00
|
|
|
|
2012-03-23 19:58:12 +00:00
|
|
|
You can disable the default Packagist repository by adding this to your
|
2012-03-06 23:16:24 +00:00
|
|
|
`composer.json`:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"repositories": [
|
|
|
|
{
|
|
|
|
"packagist": false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2012-03-07 16:35:53 +00:00
|
|
|
|
2015-06-22 08:00:04 +00:00
|
|
|
← [Schema](04-schema.md) | [Config](06-config.md) →
|