|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<!-- $Revision$ --> |
| 3 | + |
| 4 | +<chapter xml:id="install.composer" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> |
| 5 | + <title>Installation of Composer and third-party packages</title> |
| 6 | + |
| 7 | + <sect1 xml:id="install.composer.intro"> |
| 8 | + <title>Introduction to Composer</title> |
| 9 | + <simpara> |
| 10 | + &link.composer; is a dependency manager for PHP that makes it possible |
| 11 | + to define third-party code packages used by a project that can |
| 12 | + then be easily installed and updated. It leverages the built-in |
| 13 | + <link linkend="language.oop5.autoload">class autoloading features</link> |
| 14 | + of PHP, repositories of PHP packages such as |
| 15 | + <link xlink:href="&url.packagist;">Packagist</link>, and common project |
| 16 | + layout and coding conventions. |
| 17 | + </simpara> |
| 18 | + <simpara> |
| 19 | + For example, if a PHP application or website needs |
| 20 | + to work with <abbrev>UUID</abbrev> values, |
| 21 | + <link xlink:href="&url.packagist.package;ramsey/uuid">Ben Ramsey's |
| 22 | + <literal>ramsey/uuid</literal> package</link> that implements the |
| 23 | + widely known and used types of UUIDs that are defined by |
| 24 | + <link xlink:href="&url.rfc;4122">RFC 4122</link> could be used. |
| 25 | + </simpara> |
| 26 | + <simpara> |
| 27 | + Briefly, this is done by creating a <literal>composer.json</literal> |
| 28 | + in the project, using Composer to install the latest version of the |
| 29 | + package, and including Composer's autoload script to make it available |
| 30 | + to the code. The <link xlink:href="&url.composer;/doc/01-basic-usage.md">Composer |
| 31 | + "Basic Usage" documentation</link> goes into this in more depth. |
| 32 | + </simpara> |
| 33 | + <example> |
| 34 | + <title> |
| 35 | + <literal>composer.json</literal> that requires a single package |
| 36 | + </title> |
| 37 | + <programlisting role="javascript"> |
| 38 | +<![CDATA[ |
| 39 | +{ |
| 40 | + "require": { |
| 41 | + "ramsey/uuid": "^4.7" |
| 42 | + } |
| 43 | +} |
| 44 | +]]> |
| 45 | + </programlisting> |
| 46 | + </example> |
| 47 | + |
| 48 | + </sect1> |
| 49 | +</chapter> |
0 commit comments