Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f2a1a3

Browse filesBrowse files
committed
Adjustments from comments be @wouterj
1 parent 17166bd commit 6f2a1a3
Copy full SHA for 6f2a1a3

File tree

Expand file treeCollapse file tree

2 files changed

+29
-24
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-24
lines changed

‎components/class_loader/psr4_class_loader.rst

Copy file name to clipboardExpand all lines: components/class_loader/psr4_class_loader.rst
+28-24Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,62 @@ The PSR-4 Class Loader
66

77
Libraries 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

1823
Usage
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.
2630
The 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\Component\ClassLoader\Psr4ClassLoader::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/

‎components/map.rst.inc

Copy file name to clipboardExpand all lines: components/map.rst.inc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* :doc:`/components/class_loader/introduction`
66
* :doc:`/components/class_loader/class_loader`
7+
* :doc:`/components/class_loader/psr4_class_loader`
78
* :doc:`/components/class_loader/map_class_loader`
89
* :doc:`/components/class_loader/cache_class_loader`
910
* :doc:`/components/class_loader/debug_class_loader`

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.