Advise the use of absolute paths, fixes #4259
parent
00c26791fa
commit
c6cc6dd607
|
@ -3,7 +3,7 @@
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
For our basic usage introduction, we will be installing `monolog/monolog`,
|
For our basic usage introduction, we will be installing `monolog/monolog`,
|
||||||
a logging library. If you have not yet installed Composer, refer to the
|
a logging library. If you have not yet installed Composer, refer to the
|
||||||
[Intro](00-intro.md) chapter.
|
[Intro](00-intro.md) chapter.
|
||||||
|
|
||||||
> **Note:** for the sake of simplicity, this introduction will assume you
|
> **Note:** for the sake of simplicity, this introduction will assume you
|
||||||
|
@ -18,7 +18,7 @@ other metadata as well.
|
||||||
### The `require` Key
|
### The `require` Key
|
||||||
|
|
||||||
The first (and often only) thing you specify in `composer.json` is the
|
The first (and often only) thing you specify in `composer.json` is the
|
||||||
[`require`](04-schema.md#require) key. You're simply telling Composer which
|
[`require`](04-schema.md#require) key. You're simply telling Composer which
|
||||||
packages your project depends on.
|
packages your project depends on.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
@ -29,8 +29,8 @@ packages your project depends on.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
As you can see, [`require`](04-schema.md#require) takes an object that maps
|
As you can see, [`require`](04-schema.md#require) takes an object that maps
|
||||||
**package names** (e.g. `monolog/monolog`) to **version constraints** (e.g.
|
**package names** (e.g. `monolog/monolog`) to **version constraints** (e.g.
|
||||||
`1.0.*`).
|
`1.0.*`).
|
||||||
|
|
||||||
### Package Names
|
### Package Names
|
||||||
|
@ -53,7 +53,7 @@ In the previous example we were requiring version
|
||||||
Monolog. This means any version in the `1.0` development branch. It is the
|
Monolog. This means any version in the `1.0` development branch. It is the
|
||||||
equivalent of saying versions that match `>=1.0 <1.1`.
|
equivalent of saying versions that match `>=1.0 <1.1`.
|
||||||
|
|
||||||
Version constraints can be specified in several ways, read
|
Version constraints can be specified in several ways, read
|
||||||
[versions](articles/versions.md) for more in-depth information on this topic.
|
[versions](articles/versions.md) for more in-depth information on this topic.
|
||||||
|
|
||||||
### Stability
|
### Stability
|
||||||
|
@ -82,7 +82,7 @@ In case of Monolog it will put it into `vendor/monolog/monolog`.
|
||||||
> `vendor` in your `.gitignore`. You really don't want to add all of that
|
> `vendor` in your `.gitignore`. You really don't want to add all of that
|
||||||
> code to your repository.
|
> code to your repository.
|
||||||
|
|
||||||
You will notice the [`install`](03-cli.md#install) command also created a
|
You will notice the [`install`](03-cli.md#install) command also created a
|
||||||
`composer.lock` file.
|
`composer.lock` file.
|
||||||
|
|
||||||
## `composer.lock` - The Lock File
|
## `composer.lock` - The Lock File
|
||||||
|
@ -94,8 +94,8 @@ to those specific versions.
|
||||||
**Commit your application's `composer.lock` (along with `composer.json`)
|
**Commit your application's `composer.lock` (along with `composer.json`)
|
||||||
into version control.**
|
into version control.**
|
||||||
|
|
||||||
This is important because the [`install`](03-cli.md#install) command checks
|
This is important because the [`install`](03-cli.md#install) command checks
|
||||||
if a lock file is present, and if it is, it downloads the versions specified
|
if a lock file is present, and if it is, it downloads the versions specified
|
||||||
there (regardless of what `composer.json` says).
|
there (regardless of what `composer.json` says).
|
||||||
|
|
||||||
This means that anyone who sets up the project will download the exact same
|
This means that anyone who sets up the project will download the exact same
|
||||||
|
@ -111,9 +111,9 @@ versions from `composer.json` and create the lock file after executing the
|
||||||
[`update`](03-cli.md#update) or the [`install`](03-cli.md#install) command.
|
[`update`](03-cli.md#update) or the [`install`](03-cli.md#install) command.
|
||||||
|
|
||||||
This means that if any of the dependencies get a new version, you won't get the
|
This means that if any of the dependencies get a new version, you won't get the
|
||||||
updates automatically. To update to the new version, use the
|
updates automatically. To update to the new version, use the
|
||||||
[`update`](03-cli.md#update) command. This will fetch the latest matching
|
[`update`](03-cli.md#update) command. This will fetch the latest matching
|
||||||
versions (according to your `composer.json` file) and also update the lock file
|
versions (according to your `composer.json` file) and also update the lock file
|
||||||
with the new version.
|
with the new version.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -141,8 +141,8 @@ means that you can automatically `require` any package that is available there.
|
||||||
If you go to the [Packagist website](https://packagist.org/) (packagist.org),
|
If you go to the [Packagist website](https://packagist.org/) (packagist.org),
|
||||||
you can browse and search for packages.
|
you can browse and search for packages.
|
||||||
|
|
||||||
Any open source project using Composer is recommended to publish their packages
|
Any open source project using Composer is recommended to publish their packages
|
||||||
on Packagist. A library doesn't need to be on Packagist to be used by Composer,
|
on Packagist. A library doesn't need to be on Packagist to be used by Composer,
|
||||||
but it enables discovery and adoption by other developers more quickly.
|
but it enables discovery and adoption by other developers more quickly.
|
||||||
|
|
||||||
## Autoloading
|
## Autoloading
|
||||||
|
@ -152,7 +152,7 @@ For libraries that specify autoload information, Composer generates a
|
||||||
autoloading for free.
|
autoloading for free.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
require 'vendor/autoload.php';
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
```
|
```
|
||||||
|
|
||||||
This makes it really easy to use third party code. For example: If your project
|
This makes it really easy to use third party code. For example: If your project
|
||||||
|
@ -165,7 +165,7 @@ $log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::W
|
||||||
$log->addWarning('Foo');
|
$log->addWarning('Foo');
|
||||||
```
|
```
|
||||||
|
|
||||||
You can even add your own code to the autoloader by adding an
|
You can even add your own code to the autoloader by adding an
|
||||||
[`autoload`](04-schema.md#autoload) field to `composer.json`.
|
[`autoload`](04-schema.md#autoload) field to `composer.json`.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
@ -183,8 +183,8 @@ You define a mapping from namespaces to directories. The `src` directory would
|
||||||
be in your project root, on the same level as `vendor` directory is. An example
|
be in your project root, on the same level as `vendor` directory is. An example
|
||||||
filename would be `src/Foo.php` containing an `Acme\Foo` class.
|
filename would be `src/Foo.php` containing an `Acme\Foo` class.
|
||||||
|
|
||||||
After adding the [`autoload`](04-schema.md#autoload) field, you have to re-run
|
After adding the [`autoload`](04-schema.md#autoload) field, you have to re-run
|
||||||
[`dump-autoload`](03-cli.md#dump-autoload) to re-generate the
|
[`dump-autoload`](03-cli.md#dump-autoload) to re-generate the
|
||||||
`vendor/autoload.php` file.
|
`vendor/autoload.php` file.
|
||||||
|
|
||||||
Including that file will also return the autoloader instance, so you can store
|
Including that file will also return the autoloader instance, so you can store
|
||||||
|
@ -192,12 +192,12 @@ 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
|
```php
|
||||||
$loader = require 'vendor/autoload.php';
|
$loader = require __DIR__ . '/vendor/autoload.php';
|
||||||
$loader->add('Acme\\Test\\', __DIR__);
|
$loader->add('Acme\\Test\\', __DIR__);
|
||||||
```
|
```
|
||||||
|
|
||||||
In addition to PSR-4 autoloading, Composer also supports PSR-0, classmap and
|
In addition to PSR-4 autoloading, Composer also supports PSR-0, classmap and
|
||||||
files autoloading. See the [`autoload`](04-schema.md#autoload) reference for
|
files autoloading. See the [`autoload`](04-schema.md#autoload) reference for
|
||||||
more information.
|
more information.
|
||||||
|
|
||||||
> **Note:** Composer provides its own autoloader. If you don't want to use that
|
> **Note:** Composer provides its own autoloader. If you don't want to use that
|
||||||
|
|
Loading…
Reference in New Issue