本文共 1951 字,大约阅读时间需要 6 分钟。
First, update the package manager cache by running:
$sudo apt-get update
Now, let’s install the dependencies. We’ll need curl in order to download Composer and php5-cli for installing and running it. git is used by Composer for downloading project dependencies. Everything can be installed with the following command:
$sudo apt-get install curl php5-cli git
Composer installation is really simple and can be done with a single command:
$curl -sS | sudo php – –install-dir=/usr/local/bin –filename=composer
To test your installation, run:
$composer
Requiring a Package
$composer require cocur/slugify
OutputUsing version ^1.3 for cocur/slugify./composer.json has been createdLoading composer repositories with package informationUpdating dependencies (including require-dev) - Installing cocur/slugify (v1.3) Downloading: 100% Writing lock fileGenerating autoload files
As you can see from the output, Composer automatically decided which version of the package should be used. If you check your project’s directory now, it will contain two new files: composer.json and composer.lock, and a vendor directory:
When installing a project that already contains a composer.json file, you need to run composer install in order to download the project’s dependencies.
Composer also provides an autoload script that you can include in your project to get autoloading for free. This makes it much easier to work with your dependencies and define your own namespaces.
The only thing you need to do is include the vendor/autoload.php file in your PHP scripts, before any class instantiation.
slugify('Hello World, this is a long sentence and I need to make a slug from it!');
composerupdate composer update vendor/package vendor2/package2
参考:
转载地址:http://cnadi.baihongyu.com/