Skip to content

Commit 8a8682f

Browse files
committed
[#2913] Minor tweaks to the built-out class loader component docs by @xabbuh
1 parent 997cd57 commit 8a8682f

File tree

6 files changed

+40
-41
lines changed

6 files changed

+40
-41
lines changed

book/performance.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ as comments in this file::
8888

8989
// ...
9090

91+
For more details, see :doc:`/components/class_loader/cache_class_loader`.
92+
9193
.. note::
9294

9395
When using the APC autoloader, if you add new classes, they will be found

components/class_loader/cache_class_loader.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ApcClassLoader
3434

3535
require_once '/path/to/src/Symfony/Component/ClassLoader/ApcClassLoader.php';
3636
37-
// instance of a class that implements a findFile() method
37+
// instance of a class that implements a findFile() method, like the ClassLoader
3838
$loader = ...;
3939
4040
// my_prefix is the APC namespace prefix to use
@@ -43,8 +43,7 @@ ApcClassLoader
4343
// register the cached class loader
4444
$cachedLoader->register();
4545
46-
// eventually deactivate the non-cached loader if it was registered
47-
// previously
46+
// deactivate the original, non-cached loader if it was registered previously
4847
$loader->unregister();
4948

5049
XcacheClassLoader
@@ -58,7 +57,7 @@ it is straightforward::
5857

5958
require_once '/path/to/src/Symfony/Component/ClassLoader/XcacheClassLoader.php';
6059
61-
// instance of a class that implements a findFile() method
60+
// instance of a class that implements a findFile() method, like the ClassLoader
6261
$loader = ...;
6362
6463
// my_prefix is the XCache namespace
@@ -67,8 +66,7 @@ it is straightforward::
6766
// register the cached class loader
6867
$cachedLoader->register();
6968
70-
// eventually deactivate the non-cached loader if it was registered
71-
// previously
69+
// deactivate the original, non-cached loader if it was registered previously
7270
$loader->unregister();
7371

7472
.. _APC: http://php.net/manual/en/book.apc.php

components/class_loader/class_loader.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
The PSR-0 Class Loader
55
======================
66

7-
Introduction
8-
------------
9-
107
.. versionadded:: 2.1
118
The ``ClassLoader`` class was added in Symfony 2.1.
129

13-
If your classes and third-party libraries follow the `PSR-0`_ standards, you
10+
If your classes and third-party libraries follow the `PSR-0`_ standard, you
1411
can use the :class:`Symfony\\Component\\ClassLoader\\ClassLoader` class to
1512
load all of your project's classes.
1613

@@ -79,9 +76,9 @@ projects::
7976

8077
In this example, if you try to use a class in the ``Doctrine\Common`` namespace
8178
or one of its children, the autoloader will first look for the class under the
82-
``doctrine-common`` directory, and it will then fallback to the default
83-
``Doctrine`` directory (the last one configured) if not found, before giving up.
84-
The order of the registrations is significant in this case.
79+
``doctrine-common`` directory. If not found, it will then fallback to the default
80+
``Doctrine`` directory (the last one configured) before giving up. The order
81+
of the prefix registrations is significant in this case.
8582

8683
.. _PEAR: http://pear.php.net/manual/en/standards.naming.php
8784
.. _PSR-0: http://symfony.com/PSR0

components/class_loader/debug_class_loader.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ Debugging a Class Loader
77
.. versionadded:: 2.1
88
The ``DebugClassLoader`` class was added in Symfony 2.1.
99

10-
When a class isn't found by the registered autoloaders you can use the
11-
:class:`Symfony\\Component\\ClassLoader\\DebugClassLoader`. All autoloaders
12-
which implement a ``findFile()`` method are replaced with a ``DebugClassLoader``
13-
wrapper. It throws an exception if a file is found but does not declare the
14-
class.
10+
The :class:`Symfony\\Component\\ClassLoader\\DebugClassLoader` attempts to
11+
throw more helpful exceptions when a class isn't found by the registered
12+
autoloaders. All autoloaders that implement a ``findFile()`` method are replaced
13+
with a ``DebugClassLoader`` wrapper.
1514

16-
Using the ``DebugClassLoader`` is as easy as calling its static :method:`DebugClassLoader::enable`
17-
method::
15+
Using the ``DebugClassLoader`` is as easy as calling its static
16+
:method:`Symfony\\Component\\ClassLoader\\DebugClassLoader::enable` method::
1817

1918
use Symfony\Component\ClassLoader\DebugClassLoader;
2019

components/class_loader/introduction.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
The Class Loader Component
55
==========================
66

7-
The Class Loader Component provides tools to load and cache your project
8-
classes automatically.
7+
The Class Loader Component provides tools to autoload your classes and
8+
cache their locations for performance.
99

1010
Usage
1111
-----
1212

13-
Whenever you use an undefined class, PHP uses the autoloading mechanism to
14-
delegate the loading of a file defining the class. Symfony2 provides two
15-
autoloaders, which are able to load your classes:
13+
Whenever you reference a class that has not been required or included yet,
14+
PHP uses the `autoloading mechanism`_ to delegate the loading of a file defining
15+
the class. Symfony2 provides two autoloaders, which are able to load your classes:
1616

17-
* :doc:`A PSR-0 class loader </components/class_loader/class_loader>`
18-
* :doc:`Load classes based on class-to-file mapping </components/class_loader/map_class_loader>`
17+
* :doc:`/components/class_loader/class_loader`: loads classes that follow
18+
the `PSR-0` class naming standard;
19+
20+
* :doc:`/components/class_loader/map_class_loader`: loads classes using
21+
a static map from class name to file path.
1922

2023
Additionally, the Symfony Class Loader Component ships with a set of wrapper
2124
classes which can be used to add additional functionality on top of existing
@@ -33,4 +36,5 @@ You can install the component in 2 different ways:
3336
* :doc:`Install it via Composer </components/using_components>` (``symfony/class-loader``
3437
on `Packagist`_).
3538

39+
.. _`autoloading mechanism`: http://php.net/manual/en/language.oop5.autoload.php
3640
.. _Packagist: https://packagist.org/packages/symfony/class-loader

components/class_loader/map_class_loader.rst

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
MapClassLoader
55
==============
66

7-
Introduction
8-
------------
7+
The :class:`Symfony\\Component\\ClassLoader\\MapClassLoader` allows you to
8+
autoload files via a static map from classes to files. This is useful if you
9+
use third-party libraries which don't follow the `PSR-0`_ standards and so
10+
can't use the :doc:`PSR-0 class loader </components/class_loader/class_loader>`.
911

10-
Additionally to any dynamic class loader (like the
11-
:doc:`PSR-0 class loader </components/class_loader/class_loader>`) you can use
12-
the :class:`Symfony\\Component\\ClassLoader\\MapClassLoader` to statically map
13-
classes to files. This is useful if you use third-party libraries which don't
14-
follow the `PSR-0`_ standards.
12+
The ``MapClassLoader`` can be used along with the :doc:`PSR-0 class loader </components/class_loader/class_loader>`
13+
by configuring and calling the ``register()`` method on both.
14+
15+
.. note::
16+
17+
The default behavior is to append the ``MapClassLoader`` on the autoload
18+
stack. If you want to use it as the first autoloader, pass ``true`` when
19+
calling the ``register()`` method. Your class loader will then be prepended
20+
on the autoload stack.
1521

1622
Usage
1723
-----
@@ -29,12 +35,5 @@ an instance of the ``MapClassLoader`` class::
2935
$loader = new MapClassLoader($mapping);
3036
3137
$loader->register();
32-
33-
.. note::
34-
35-
The default behavior is to append the ``MapClassLoader`` on the autoload
36-
stack. If you want to use it as the default autoloader, pass ``true``
37-
when calling the ``register()`` method. Your class loader will then be
38-
prepended on the autoload stack.
3938

4039
.. _PSR-0: http://symfony.com/PSR0

0 commit comments

Comments
 (0)