@@ -6,58 +6,62 @@ The PSR-4 Class Loader
66
77Libraries that follow the `PSR-4 `_ standard can be loaded with the ``Psr4ClassLoader ``.
88
9+ .. versionadded :: 2.5
10+ The :class: `Symfony\\ Component\\ ClassLoader\\ Psr4ClassLoader ` was
11+ introduced in Symfony 2.5.
12+
913.. note ::
1014
1115 If you manage your dependencies via Composer, you get a PSR-4 compatible
1216 autoloader out of the box. Use this loader in environments where Composer
1317 is not available.
1418
1519.. tip ::
20+
1621 All Symfony Components follow PSR-4.
1722
1823Usage
1924-----
2025
21- The following example demonstrates, how you can use the
26+ The following example demonstrates how you can use the
2227:class: `Symfony\\ Component\\ ClassLoader\\ Psr4ClassLoader ` autoloader to use
23- Symfony's Yaml component. Let's imagine, you downloaded both components –
24- ClassLoader and Yaml – as ZIP packages and unpacked them to a libs directory.
25-
28+ Symfony's Yaml component. Imagine, you downloaded both the ``ClassLoader `` and
29+ ``Yaml `` component as ZIP packages and unpacked them to a ``libs `` directory.
2630The directory structure will look like this:
2731
2832.. code-block :: text
2933
30- /
31- +- libs
32- | +- ClassLoader
33- | | +- Psr4ClassLoader.php
34- | | +- …
35- | +- Yaml
36- | +- Yaml.php
37- | +- …
38- +- config.yml
39- +- test.php
34+ libs/
35+ ClassLoader/
36+ Psr4ClassLoader.php
37+ ...
38+ Yaml/
39+ Yaml.php
40+ ...
41+ config.yml
42+ test.php
4043
41- In ``demo.php ``, to parse the file ``config.yml ``, you can use the following
42- code.
44+ In ``demo.php `` you are going to parse the ``config.yml `` file. To do that, you
45+ first need to configure the `` Psr4ClassLoader ``:
4346
4447.. code-block :: php
4548
4649 use Symfony\Component\ClassLoader\Psr4ClassLoader;
4750 use Symfony\Component\Yaml\Yaml;
4851
49- require __DIR__ . '/lib/ClassLoader/Psr4ClassLoader.php';
52+ require __DIR__. '/lib/ClassLoader/Psr4ClassLoader.php';
5053
5154 $loader = new Psr4ClassLoader();
52- $loader->addPrefix('Symfony\\Component\\Yaml\\', __DIR__ . '/lib/Yaml');
55+ $loader->addPrefix('Symfony\\Component\\Yaml\\', __DIR__. '/lib/Yaml');
5356 $loader->register();
5457
55- $data = Yaml::parse(__DIR__ . '/demo.yml');
58+ $data = Yaml::parse(__DIR__. '/demo.yml');
5659
57- First of all, we've loaded our class loader manually using ``require `` since we
58- don't have an autoload mechanism, yet. With the ``addPrefix() `` call, we told
59- the class loader where to look for classes with the namespace prefix
60- ``Symfony\Component\Yaml\ ``. After registering the autoloader, the Yaml
61- component is ready to use.
60+ First of all, the class loader is loaded manually using a ``require ``
61+ statement, since there is no autoload mechanism yet. With the
62+ :method: `Symfony\C omponent\C lassLoader\P sr4ClassLoader::addPrefix ` call, you
63+ tell the class loader where to look for classes with the
64+ ``Symfony\Component\Yaml\ `` namespace prefix. After registering the autoloader,
65+ the Yaml component is ready to use.
6266
6367.. _PSR-4 : http://www.php-fig.org/psr/psr-4/
0 commit comments