Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information about Composer and example of using it's autoloader #3677

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions install/composer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<chapter xml:id="install.composer" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Installation of Composer and third-party packages</title>

<sect1 xml:id="install.composer.intro">
<title>Introduction to Composer</title>
<simpara>
&link.composer; is a dependency manager for PHP that makes it possible
to define third-party packages of code that a project uses that can
then be easily installed and updated. It leverages the the built-in
<link linkend="language.oop5.autoload">class autoloading features</link>
of PHP, repositories of PHP packages such as
<link xlink:href="&url.packagist;">Packagist</link>, and common project
layout and coding conventions.
</simpara>
<simpara>
For example, if a PHP application or website needs
to work with <abbrev>UUID</abbrev> values,
<link xlink:href="&url.packagist.package;ramsey/uuid">Ben Ramsey's
<literal>ramsey/uuid</literal> package</link> that implements the
widely known and used types of UUIDs that are defined by
<link xlink:href="&url.rfc;4122">RFC 4122</link> could be used.
</simpara>
<simpara>
Briefly, this is done by creating a <literal>composer.json</literal>
in the project, using Composer to install the latest version of the
package, and including Composer's autoload script to make it available
to the code. The <link xlink:href="&url.composer;/doc/01-basic-usage.md">Composer
"Basic Usage" documentation</link> goes into this in more depth.
</simpara>
<para>
<example>
<title>
<literal>composer.json</literal> that requires a single package
</title>
<programlisting role="javascript">
<![CDATA[
{
"require": {
"ramsey/uuid": "^4.7"
}
}
]]>
</programlisting>
</example>
</para>

</sect1>
</chapter>
20 changes: 20 additions & 0 deletions language/oop5/autoload.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ string(5) "ITest"
Fatal error: Interface 'ITest' not found in ...
*/
?>
]]>
</programlisting>
</example>
<example>
<title>Using Composer's autoloader</title>
<para>
&link.composer; generates a <literal>vendor/autoload.php</literal>
with is set up to automatically load packages that are being managed
by Composer. By including this file, those packages can be used without
any additional work.
</para>
<programlisting role="php">
<![CDATA[
<?php
require __DIR__ . '/vendor/autoload.php';

$uuid = new Ramsey\Uuid\Uuid::uuid7();

echo "Generated new UUID -> ", $uuid->toString(), "\n";
?>
]]>
</programlisting>
</example>
Expand Down
Loading