11.08.2017 Views

codebright

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The Primers 31<br />

1 Loading composer repositories with package information<br />

2 Installing dependencies<br />

3<br />

4 - Installing xmen/beast (1.1.0)<br />

5 Cloning bc0e1f0c34343347a38c232132132121a2fd53e94<br />

6<br />

7 Writing lock file<br />

8 Generating autoload files<br />

Now xmen/beast has been installed and we can use it right away. Smashing!<br />

You may have noticed the following line in the output from the composer install command.<br />

1 Writing lock file<br />

You might also have noticed that Composer has created a file called composer.lock at the root of<br />

your application. What’s that for I hear you cry?<br />

The composer.lock file contains the information about your package at the time that the last<br />

composer install or composer update was performed. It also contains a list of the *exact version<br />

of each dependency that has been installed.<br />

Why is that? It’s simple. Whenever you use composer install when a composer.lock file is present<br />

in the directory, it will use the versions contained within the file instead of pulling down fresh<br />

versions of each dependency.<br />

This means that if you version your composer.lock file along with your application source (and<br />

I highly recommend this), when you deploy to your production environment it will be using the<br />

exact same versions of dependencies that have been tried and tested in your local development<br />

environment. This means you can be sure that Composer won’t install any dependency versions<br />

that might break your application.<br />

Note that you should never edit the composer.lock file manually.<br />

While we are on the topic of dependency versions, why not find out about updating them? For<br />

example if we had the following requirement in our composer.json file.<br />

1 "xmen/gambit": "1.0.*"<br />

Composer might install version 1.0.0 for us. However, what if the package was updated to 1.0.1 a<br />

few days later?<br />

Well, we can use the composer update command to update all of our dependencies to their latest<br />

versions. Let’s have a look at the output.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!