Fixed Twig example of Composer page.

Also, commands don't need syntax. It's just a command.
This commit is contained in:
Phil Sturgeon
2012-07-10 11:14:05 +01:00
parent 086fd15c5f
commit 264137ab58

View File

@@ -12,7 +12,7 @@ There are already a lot of PHP libraries that are compatible with Composer, read
You can install Composer locally (in your current working directory; though this is no longer recommended) or globally (e.g. /usr/local/bin). Let's assume you want to install Composer locally. From your project's root directory:
> curl -s http://getcomposer.org/installer | php
curl -s http://getcomposer.org/installer | php
This will download `composer.phar` (a PHP binary archive). You can run this with `php` to manage your project dependencies. <strong>Please Note:</strong> If you pipe downloaded code directly into an interpreter, please read the code online first to confirm it is safe.
@@ -28,37 +28,36 @@ Manually installing composer is an advanced technique; however, there are variou
Since a manual installation performs none of these checks, you have to decide whether the trade-off is worth it for you. As such, below is how to obtain Composer manually:
> curl -s http://getcomposer.org/composer.phar -o $HOME/local/bin/composer ; chmod +x $HOME/local/bin/composer
curl -s http://getcomposer.org/composer.phar -o $HOME/local/bin/composer
chmod +x $HOME/local/bin/composer
`$HOME/local/bin` (or a directory of your choice) should be in your `$PATH` environment variable. This will result in a `composer` command being available.
The path `$HOME/local/bin` (or a directory of your choice) should be in your `$PATH` environment variable. This will result in a `composer` command being available.
When you come across documentation that states to run Composer as `php composer.phar install`, you can substitute that with:
> composer install
composer install
### How to Define and Install Dependencies
First, create a `composer.json` file in the same directory as `composer.phar`. Here's an example that lists [Twig][2] as a project dependency.
{% highlight json %}
{
"require": {
"twig/twig": ">=1.8.0,<2.0-dev"
}
{
"require": {
"twig/twig": "1.8.*"
}
}
{% endhighlight %}
Next, run this command from your project root directory.
{% highlight bash %}
> php composer.phar install
{% endhighlight %}
php composer.phar install
This will download and install the project dependencies into a `vendors/` directory. Next, add this line to your application's primary PHP file; this will tell PHP to use Composer's autoloader for your project dependencies.
{% highlight php %}
<?php
require 'vendor/autoload.php';
require 'vendor/autoload.php';
{% endhighlight %}
Now you can use your project dependencies, and they'll be autoloaded on demand.