From 0b315102a9d5c258ef81257ea94f0c0e32533342 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 19 Aug 2013 11:37:27 +0200 Subject: [PATCH 1/8] document both cache class loader the ApcClassLoader and the XcacheClassLoader --- .../class_loader/cache_class_loader.rst | 70 +++++++++++++++++++ .../{ => class_loader}/class_loader.rst | 0 components/class_loader/index.rst | 8 +++ components/index.rst | 2 +- components/map.rst.inc | 3 +- quick_tour/the_architecture.rst | 2 +- 6 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 components/class_loader/cache_class_loader.rst rename components/{ => class_loader}/class_loader.rst (100%) create mode 100644 components/class_loader/index.rst diff --git a/components/class_loader/cache_class_loader.rst b/components/class_loader/cache_class_loader.rst new file mode 100644 index 00000000000..23f57d3d95b --- /dev/null +++ b/components/class_loader/cache_class_loader.rst @@ -0,0 +1,70 @@ +.. index:: + single: APC; ApcClassLoader + single: Class Loader; ApcClassLoader + single: Class Loader; Cache + single: Class Loader; XcacheClassLoader + single: XCache; XcacheClassLoader + +Cache a Class Loader +==================== + +Introduction +------------ + +Finding the file for a particular class can be an expensive task. Luckily, +the Class Loader Component comes with two classes to cache the mapping +from a class to its containing file. Both the :class:`Symfonfy\\Component\\ClassLoader\\ApcClassLoader` +and the :class:`Symfony\\Component\\ClassLoader\\XcacheClassLoader` wrap +around an object which implements a ``findFile()`` method to find the file +for a class. + +.. note:: + + Both the ``ApcClassLoader`` and the ``XcacheClassLoader`` can be used + to cache Composer's `autoloader`_. + +ApcClassLoader +-------------- + +``ApcClassLoader`` wraps an existing class loader and caches calls to its +``findFile()`` method using `APC`_:: + + require_once '/path/to/src/Symfony/Component/ClassLoader/ApcClassLoader.php'; + + // instance of a class that implements a findFile() method + $loader = ...; + + // my_prefix is the APC namespace prefix to use + $cachedLoader = new ApcClassLoader('my_prefix', $loader); + + // register the cached class loader + $cachedLoader->register(); + + // eventually deactivate the non-cached loader if it was registered + // previously + $loader->unregister(); + +XcacheClassLoader +----------------- + +``XcacheClassLoader`` uses `XCache`_ to cache a class loader. Registering +it is straightforward:: + + require_once '/path/to/src/Symfony/Component/ClassLoader/XcacheClassLoader.php'; + + // instance of a class that implements a findFile() method + $loader = ...; + + // my_prefix is the XCache namespace + $cachedLoader = new XcacheClassLoader('my_prefix', $loader); + + // register the cached class loader + $cachedLoader->register(); + + // eventually deactivate the non-cached loader if it was registered + // previously + $loader->unregister(); + +.. _APC: http://php.net/manual/en/book.apc.php +.. _autoloader: http://getcomposer.org/doc/01-basic-usage.md#autoloading +.. _XCache: http://xcache.lighttpd.net diff --git a/components/class_loader.rst b/components/class_loader/class_loader.rst similarity index 100% rename from components/class_loader.rst rename to components/class_loader/class_loader.rst diff --git a/components/class_loader/index.rst b/components/class_loader/index.rst new file mode 100644 index 00000000000..a01ec77eb80 --- /dev/null +++ b/components/class_loader/index.rst @@ -0,0 +1,8 @@ +Class Loader +============ + +.. toctree:: + :maxdepth: 2 + + class_loader + cache_class_loader diff --git a/components/index.rst b/components/index.rst index 865b2b274e6..e1b11dbb942 100644 --- a/components/index.rst +++ b/components/index.rst @@ -5,7 +5,7 @@ The Components :hidden: using_components - class_loader + class_loader/index config/index console/index css_selector diff --git a/components/map.rst.inc b/components/map.rst.inc index acd892e0c67..15e044f715a 100644 --- a/components/map.rst.inc +++ b/components/map.rst.inc @@ -2,7 +2,8 @@ * **Class Loader** - * :doc:`/components/class_loader` + * :doc:`/components/class_loader/class_loader` + * :doc:`/components/class_loader/cache_class_loader` * :doc:`/components/config/index` diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index 30cffa72fb3..bce41d873a8 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -68,7 +68,7 @@ in your projects. .. note:: If you want to learn more about Composer's autoloader, read `Composer-Autoloader`_. - Symfony also has an autoloading component - read ":doc:`/components/class_loader`". + Symfony also has an autoloading component - read ":doc:`/components/class_loader/class_loader`". Understanding the Bundle System ------------------------------- From 3c8b8747b3ca17d6ce310a66bff6ab2bcd4a15b5 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 19 Aug 2013 11:48:13 +0200 Subject: [PATCH 2/8] documentation for the DebugClassLoader --- components/class_loader/debug_class_loader.rst | 18 ++++++++++++++++++ components/class_loader/index.rst | 1 + components/map.rst.inc | 1 + 3 files changed, 20 insertions(+) create mode 100644 components/class_loader/debug_class_loader.rst diff --git a/components/class_loader/debug_class_loader.rst b/components/class_loader/debug_class_loader.rst new file mode 100644 index 00000000000..a8cab155aae --- /dev/null +++ b/components/class_loader/debug_class_loader.rst @@ -0,0 +1,18 @@ +.. index:: + single: Class Loader; DebugClassLoader + +Debugging a Class Loader +======================== + +When a class isn't found by the registered autoloaders you can use the +:class:`Symfony\\Component\\ClassLoader\\DebugClassLoader`. All autoloaders +which implement a ``findFile()`` method are replaced with a ``DebugClassLoader`` +wrapper. It throws an exception if a file is found but does not declare the +class. + +Using the ``DebugClassLoader`` is as easy as calling its static :method:`DebugClassLoader::enable` +method:: + + use Symfony\Component\ClassLoader\DebugClassLoader; + + DebugClassLoader::enable(); diff --git a/components/class_loader/index.rst b/components/class_loader/index.rst index a01ec77eb80..f99cb7ab634 100644 --- a/components/class_loader/index.rst +++ b/components/class_loader/index.rst @@ -6,3 +6,4 @@ Class Loader class_loader cache_class_loader + debug_class_loader diff --git a/components/map.rst.inc b/components/map.rst.inc index 15e044f715a..e2889f9ae33 100644 --- a/components/map.rst.inc +++ b/components/map.rst.inc @@ -4,6 +4,7 @@ * :doc:`/components/class_loader/class_loader` * :doc:`/components/class_loader/cache_class_loader` + * :doc:`/components/class_loader/debug_class_loader` * :doc:`/components/config/index` From 0c17e5b70070e204735eec95d4ba9bbc6415b443 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 19 Aug 2013 12:16:26 +0200 Subject: [PATCH 3/8] documentation for the MapClassLoader class --- components/class_loader/index.rst | 1 + components/class_loader/map_class_loader.rst | 28 ++++++++++++++++++++ components/map.rst.inc | 1 + 3 files changed, 30 insertions(+) create mode 100644 components/class_loader/map_class_loader.rst diff --git a/components/class_loader/index.rst b/components/class_loader/index.rst index f99cb7ab634..b0c07467054 100644 --- a/components/class_loader/index.rst +++ b/components/class_loader/index.rst @@ -5,5 +5,6 @@ Class Loader :maxdepth: 2 class_loader + map_class_loader cache_class_loader debug_class_loader diff --git a/components/class_loader/map_class_loader.rst b/components/class_loader/map_class_loader.rst new file mode 100644 index 00000000000..63631f76a9d --- /dev/null +++ b/components/class_loader/map_class_loader.rst @@ -0,0 +1,28 @@ +.. index:: + single: Class Loader; MapClassLoader + +MapClassLoader +============== + +Additionally to any dynamic class loader (like the :doc:`PSR-0 class loader `) +you can use the :class:`Symfony\\Component\\ClassLoader\\MapClassLoader` to statically +map classes to files. Using it is as easy as passing your mapping to its constructor +when creating an instance of the ``MapClassLoader`` class:: + + require_once '/path/to/src/Symfony/Component/ClassLoader/MapClassLoader'; + + $mapping = array( + 'Foo' => '/path/to/Foo', + 'Bar' => '/path/to/Bar', + ); + + $loader = new MapClassLoader($mapping); + + $loader->register(); + +.. note:: + + The default behavior is to append the ``MapClassLoader`` on the autoload + stack. If you want to use it as the default autoloader, pass ``true`` + when calling the ``register()`` method. Your class loader will then be + prepended on the autoload stack. diff --git a/components/map.rst.inc b/components/map.rst.inc index e2889f9ae33..d956228a52b 100644 --- a/components/map.rst.inc +++ b/components/map.rst.inc @@ -3,6 +3,7 @@ * **Class Loader** * :doc:`/components/class_loader/class_loader` + * :doc:`/components/class_loader/map_class_loader` * :doc:`/components/class_loader/cache_class_loader` * :doc:`/components/class_loader/debug_class_loader` From b98f2e636dfb99c81961d3684fbb50cf88c68728 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 19 Aug 2013 16:36:18 +0200 Subject: [PATCH 4/8] add an introduction and documentation for the ClassLoader class --- components/class_loader/class_loader.rst | 109 +++++++---------------- components/class_loader/index.rst | 1 + components/class_loader/introduction.rst | 31 +++++++ components/map.rst.inc | 3 +- 4 files changed, 66 insertions(+), 78 deletions(-) create mode 100644 components/class_loader/introduction.rst diff --git a/components/class_loader/class_loader.rst b/components/class_loader/class_loader.rst index eb64f41dbbe..6a6f0f8660a 100644 --- a/components/class_loader/class_loader.rst +++ b/components/class_loader/class_loader.rst @@ -1,129 +1,84 @@ .. index:: - pair: Autoloader; Configuration - single: Components; ClassLoader + single: Class Loader; MapClassLoader -The ClassLoader Component -========================= +The PSR-0 Class Loader +====================== - The ClassLoader Component loads your project classes automatically if they - follow some standard PHP conventions. - -Whenever you use an undefined class, PHP uses the autoloading mechanism to -delegate the loading of a file defining the class. Symfony2 provides a -"universal" autoloader, which is able to load classes from files that -implement one of the following conventions: - -* The technical interoperability `standards`_ for PHP 5.3 namespaces and class - names; - -* The `PEAR`_ naming convention for classes. - -If your classes and the third-party libraries you use for your project follow -these standards, the Symfony2 autoloader is the only autoloader you will ever -need. - -Installation +Introduction ------------ -You can install the component in 2 different ways: +If your classes and third-party libraries follow the `PSR-0`_ standards or the +`PEAR`_ naming conventions, you can use the :class:`Symfony\\Component\\ClassLoader\\ClassLoader` +class to load all of your project's classes. + +.. note:: -* Use the official Git repository (https://github.com/symfony/ClassLoader); -* :doc:`Install it via Composer ` (``symfony/class-loader`` on `Packagist`_). + You can use both the ``ApcClassLoader`` and the ``XcacheClassLoader`` to + :doc:`cache` a ``ClassLoader`` + instance or the ``DebugClassLoader`` to :doc:`debug` + it. Usage ----- -.. versionadded:: 2.1 - The ``useIncludePath`` method was added in Symfony 2.1. - -Registering the :class:`Symfony\\Component\\ClassLoader\\UniversalClassLoader` -autoloader is straightforward:: +Registering the :class:`Symfony\\Component\\ClassLoader\\ClassLoader` autoloader +is straightforward:: - require_once '/path/to/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; + require_once '/path/to/src/Symfony/Component/ClassLoader/ClassLoader.php'; - use Symfony\Component\ClassLoader\UniversalClassLoader; + use Symfony\Component\ClassLoader\ClassLoader; - $loader = new UniversalClassLoader(); + $loader = new ClassLoader(); - // You can search the include_path as a last resort. + // to enable searching the include path (eg. for PEAR packages) $loader->useIncludePath(true); // ... register namespaces and prefixes here - see below $loader->register(); -For minor performance gains class paths can be cached in memory using APC by -registering the :class:`Symfony\\Component\\ClassLoader\\ApcUniversalClassLoader`:: - - require_once '/path/to/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; - require_once '/path/to/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php'; - - use Symfony\Component\ClassLoader\ApcUniversalClassLoader; - - $loader = new ApcUniversalClassLoader('apc.prefix.'); - $loader->register(); - -The autoloader is useful only if you add some libraries to autoload. - .. note:: The autoloader is automatically registered in a Symfony2 application (see ``app/autoload.php``). -If the classes to autoload use namespaces, use the -:method:`Symfony\\Component\\ClassLoader\\UniversalClassLoader::registerNamespace` -or -:method:`Symfony\\Component\\ClassLoader\\UniversalClassLoader::registerNamespaces` -methods:: +Use the :method:`Symfony\\Component\\ClassLoader\\ClassLoader::addPrefix` or +:method:`Symfony\\Component\\ClassLoader\\ClassLoader::addPrefixes` methods to +register your classes:: - $loader->registerNamespace('Symfony', __DIR__.'/vendor/symfony/symfony/src'); + // register a single namespaces + $loader->addPrefix('Symfony', __DIR__.'/vendor/symfony/symfony/src'); - $loader->registerNamespaces(array( + // register several namespaces at once + $loader->addPrefixes(array( 'Symfony' => __DIR__.'/../vendor/symfony/symfony/src', 'Monolog' => __DIR__.'/../vendor/monolog/monolog/src', )); - $loader->register(); - -For classes that follow the PEAR naming convention, use the -:method:`Symfony\\Component\\ClassLoader\\UniversalClassLoader::registerPrefix` -or -:method:`Symfony\\Component\\ClassLoader\\UniversalClassLoader::registerPrefixes` -methods:: - - $loader->registerPrefix('Twig_', __DIR__.'/vendor/twig/twig/lib'); + // register a prefix for a class following the PEAR naming conventions + $loader->addPrefix('Twig_', __DIR__.'/vendor/twig/twig/lib'); - $loader->registerPrefixes(array( + $loader->addPrefixes(array( 'Swift_' => __DIR__.'/vendor/swiftmailer/swiftmailer/lib/classes', 'Twig_' => __DIR__.'/vendor/twig/twig/lib', )); - $loader->register(); - -.. note:: - - Some libraries also require their root path be registered in the PHP - include path (``set_include_path()``). - Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be looked for in a location list to ease the vendoring of a sub-set of classes for large projects:: - $loader->registerNamespaces(array( + $loader->addPrefixes(array( 'Doctrine\\Common' => __DIR__.'/vendor/doctrine/common/lib', 'Doctrine\\DBAL\\Migrations' => __DIR__.'/vendor/doctrine/migrations/lib', 'Doctrine\\DBAL' => __DIR__.'/vendor/doctrine/dbal/lib', 'Doctrine' => __DIR__.'/vendor/doctrine/orm/lib', )); - $loader->register(); - In this example, if you try to use a class in the ``Doctrine\Common`` namespace or one of its children, the autoloader will first look for the class under the ``doctrine-common`` directory, and it will then fallback to the default ``Doctrine`` directory (the last one configured) if not found, before giving up. The order of the registrations is significant in this case. -.. _standards: http://symfony.com/PSR0 -.. _PEAR: http://pear.php.net/manual/en/standards.php -.. _Packagist: https://packagist.org/packages/symfony/class-loader +.. _PEAR: http://pear.php.net/manual/en/standards.naming.php +.. _PSR-0: http://symfony.com/PSR0 diff --git a/components/class_loader/index.rst b/components/class_loader/index.rst index b0c07467054..7538957fc65 100644 --- a/components/class_loader/index.rst +++ b/components/class_loader/index.rst @@ -4,6 +4,7 @@ Class Loader .. toctree:: :maxdepth: 2 + introduction class_loader map_class_loader cache_class_loader diff --git a/components/class_loader/introduction.rst b/components/class_loader/introduction.rst new file mode 100644 index 00000000000..07f09d1d941 --- /dev/null +++ b/components/class_loader/introduction.rst @@ -0,0 +1,31 @@ +The Class Loader Component +========================== + + The Class Loader Component loads your project classes automatically. + +Whenever you use an undefined class, PHP uses the autoloading mechanism to +delegate the loading of a file defining the class. Symfony2 provides two +autoloaders, which are able to load your classes: + +* :doc:`A PSR-0 class loader` + +* :doc:`Load classes based on class-to-file mapping` + +Additionally, the Symfony Class Loader Component ships with a set of wrapper +classes which can be used to add additional functionality on top of existing +autoloaders: + +* :doc:`cache_class_loader` + +* :doc:`debug_class_loader` + +Installation +------------ + +You can install the component in 2 different ways: + +* Use the official Git repository (https://github.com/symfony/ClassLoader); +* :doc:`Install it via Composer ` (``symfony/class-loader`` + on `Packagist`_). + +.. _Packagist: https://packagist.org/packages/symfony/class-loader diff --git a/components/map.rst.inc b/components/map.rst.inc index d956228a52b..9f507aa5cdc 100644 --- a/components/map.rst.inc +++ b/components/map.rst.inc @@ -1,7 +1,8 @@ * :doc:`/components/using_components` -* **Class Loader** +* :doc:`/components/class_loader/index` + * :doc:`/components/class_loader/introduction` * :doc:`/components/class_loader/class_loader` * :doc:`/components/class_loader/map_class_loader` * :doc:`/components/class_loader/cache_class_loader` From 34dc7126f491e2c8d3b25866fefc0522e234129e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 19 Aug 2013 16:49:57 +0200 Subject: [PATCH 5/8] add versionadded directives for new classes --- components/class_loader/cache_class_loader.rst | 6 ++++++ components/class_loader/class_loader.rst | 3 +++ components/class_loader/debug_class_loader.rst | 3 +++ 3 files changed, 12 insertions(+) diff --git a/components/class_loader/cache_class_loader.rst b/components/class_loader/cache_class_loader.rst index 23f57d3d95b..550968c778d 100644 --- a/components/class_loader/cache_class_loader.rst +++ b/components/class_loader/cache_class_loader.rst @@ -26,6 +26,9 @@ for a class. ApcClassLoader -------------- +.. versionadded:: 2.1 + The ``ApcClassLoader`` class was added in Symfony 2.1. + ``ApcClassLoader`` wraps an existing class loader and caches calls to its ``findFile()`` method using `APC`_:: @@ -47,6 +50,9 @@ ApcClassLoader XcacheClassLoader ----------------- +.. versionadded:: 2.1 + The ``XcacheClassLoader`` class was added in Symfony 2.1. + ``XcacheClassLoader`` uses `XCache`_ to cache a class loader. Registering it is straightforward:: diff --git a/components/class_loader/class_loader.rst b/components/class_loader/class_loader.rst index 6a6f0f8660a..41a3d2fb7f1 100644 --- a/components/class_loader/class_loader.rst +++ b/components/class_loader/class_loader.rst @@ -7,6 +7,9 @@ The PSR-0 Class Loader Introduction ------------ +.. versionadded:: 2.1 + The ``ClassLoader`` class was added in Symfony 2.1. + If your classes and third-party libraries follow the `PSR-0`_ standards or the `PEAR`_ naming conventions, you can use the :class:`Symfony\\Component\\ClassLoader\\ClassLoader` class to load all of your project's classes. diff --git a/components/class_loader/debug_class_loader.rst b/components/class_loader/debug_class_loader.rst index a8cab155aae..c861afcc7d4 100644 --- a/components/class_loader/debug_class_loader.rst +++ b/components/class_loader/debug_class_loader.rst @@ -4,6 +4,9 @@ Debugging a Class Loader ======================== +.. versionadded:: 2.1 + The ``DebugClassLoader`` class was added in Symfony 2.1. + When a class isn't found by the registered autoloaders you can use the :class:`Symfony\\Component\\ClassLoader\\DebugClassLoader`. All autoloaders which implement a ``findFile()`` method are replaced with a ``DebugClassLoader`` From d3cd48cd3be8ce6e406f716b5f3df0086cc25f3e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 19 Aug 2013 17:39:50 +0200 Subject: [PATCH 6/8] fixes thanks to @WouterJ --- components/class_loader/class_loader.rst | 12 ++++++------ components/class_loader/introduction.rst | 19 ++++++++++++------- components/class_loader/map_class_loader.rst | 20 ++++++++++++++++---- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/components/class_loader/class_loader.rst b/components/class_loader/class_loader.rst index 41a3d2fb7f1..c8178862e94 100644 --- a/components/class_loader/class_loader.rst +++ b/components/class_loader/class_loader.rst @@ -1,5 +1,5 @@ .. index:: - single: Class Loader; MapClassLoader + single: Class Loader; PSR-0 Class Loader The PSR-0 Class Loader ====================== @@ -10,11 +10,11 @@ Introduction .. versionadded:: 2.1 The ``ClassLoader`` class was added in Symfony 2.1. -If your classes and third-party libraries follow the `PSR-0`_ standards or the -`PEAR`_ naming conventions, you can use the :class:`Symfony\\Component\\ClassLoader\\ClassLoader` -class to load all of your project's classes. +If your classes and third-party libraries follow the `PSR-0`_ standards, you +can use the :class:`Symfony\\Component\\ClassLoader\\ClassLoader` class to +load all of your project's classes. -.. note:: +.. tip:: You can use both the ``ApcClassLoader`` and the ``XcacheClassLoader`` to :doc:`cache` a ``ClassLoader`` @@ -66,7 +66,7 @@ register your classes:: 'Twig_' => __DIR__.'/vendor/twig/twig/lib', )); -Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be looked +Classes from a sub-namespace or a sub-hierarchy of `PEAR`_ classes can be looked for in a location list to ease the vendoring of a sub-set of classes for large projects:: diff --git a/components/class_loader/introduction.rst b/components/class_loader/introduction.rst index 07f09d1d941..bc91a35dd5b 100644 --- a/components/class_loader/introduction.rst +++ b/components/class_loader/introduction.rst @@ -1,23 +1,28 @@ +.. index:: + single: Components; Class Loader + The Class Loader Component ========================== - The Class Loader Component loads your project classes automatically. + The Class Loader Component provides tools to load and cache your project + classes automatically. + +Usage +----- Whenever you use an undefined class, PHP uses the autoloading mechanism to delegate the loading of a file defining the class. Symfony2 provides two autoloaders, which are able to load your classes: -* :doc:`A PSR-0 class loader` - -* :doc:`Load classes based on class-to-file mapping` +* :doc:`A PSR-0 class loader` +* :doc:`Load classes based on class-to-file mapping` Additionally, the Symfony Class Loader Component ships with a set of wrapper classes which can be used to add additional functionality on top of existing autoloaders: -* :doc:`cache_class_loader` - -* :doc:`debug_class_loader` +* :doc:`/components/class_loader/cache_class_loader` +* :doc:`/components/class_loader/debug_class_loader` Installation ------------ diff --git a/components/class_loader/map_class_loader.rst b/components/class_loader/map_class_loader.rst index 63631f76a9d..e007b26a06d 100644 --- a/components/class_loader/map_class_loader.rst +++ b/components/class_loader/map_class_loader.rst @@ -4,10 +4,20 @@ MapClassLoader ============== -Additionally to any dynamic class loader (like the :doc:`PSR-0 class loader `) -you can use the :class:`Symfony\\Component\\ClassLoader\\MapClassLoader` to statically -map classes to files. Using it is as easy as passing your mapping to its constructor -when creating an instance of the ``MapClassLoader`` class:: +Introduction +------------ + +Additionally to any dynamic class loader (like the +:doc:`PSR-0 class loader`) you can use +the :class:`Symfony\\Component\\ClassLoader\\MapClassLoader` to statically map +classes to files. This is useful if you use third-party libraries which don't +follow the `PSR-0`_ standards. + +Usage +----- + +Using it is as easy as passing your mapping to its constructor when creating +an instance of the ``MapClassLoader`` class:: require_once '/path/to/src/Symfony/Component/ClassLoader/MapClassLoader'; @@ -26,3 +36,5 @@ when creating an instance of the ``MapClassLoader`` class:: stack. If you want to use it as the default autoloader, pass ``true`` when calling the ``register()`` method. Your class loader will then be prepended on the autoload stack. + +.. _PSR-0: http://symfony.com/PSR0 From c8fd22f9ff65e0c5fb29aa56e0a19c4b5bd83020 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 19 Aug 2013 23:16:47 +0200 Subject: [PATCH 7/8] fix markup of links --- components/class_loader/class_loader.rst | 4 ++-- components/class_loader/introduction.rst | 4 ++-- components/class_loader/map_class_loader.rst | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/class_loader/class_loader.rst b/components/class_loader/class_loader.rst index c8178862e94..390ef5161d8 100644 --- a/components/class_loader/class_loader.rst +++ b/components/class_loader/class_loader.rst @@ -17,8 +17,8 @@ load all of your project's classes. .. tip:: You can use both the ``ApcClassLoader`` and the ``XcacheClassLoader`` to - :doc:`cache` a ``ClassLoader`` - instance or the ``DebugClassLoader`` to :doc:`debug` + :doc:`cache ` a ``ClassLoader`` + instance or the ``DebugClassLoader`` to :doc:`debug ` it. Usage diff --git a/components/class_loader/introduction.rst b/components/class_loader/introduction.rst index bc91a35dd5b..0f905e7a228 100644 --- a/components/class_loader/introduction.rst +++ b/components/class_loader/introduction.rst @@ -14,8 +14,8 @@ Whenever you use an undefined class, PHP uses the autoloading mechanism to delegate the loading of a file defining the class. Symfony2 provides two autoloaders, which are able to load your classes: -* :doc:`A PSR-0 class loader` -* :doc:`Load classes based on class-to-file mapping` +* :doc:`A PSR-0 class loader ` +* :doc:`Load classes based on class-to-file mapping ` Additionally, the Symfony Class Loader Component ships with a set of wrapper classes which can be used to add additional functionality on top of existing diff --git a/components/class_loader/map_class_loader.rst b/components/class_loader/map_class_loader.rst index e007b26a06d..12b1791e9bd 100644 --- a/components/class_loader/map_class_loader.rst +++ b/components/class_loader/map_class_loader.rst @@ -8,7 +8,7 @@ Introduction ------------ Additionally to any dynamic class loader (like the -:doc:`PSR-0 class loader`) you can use +:doc:`PSR-0 class loader `) you can use the :class:`Symfony\\Component\\ClassLoader\\MapClassLoader` to statically map classes to files. This is useful if you use third-party libraries which don't follow the `PSR-0`_ standards. From f162f3e2f21e0fef4932b664edd5a083aad58987 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 11 Sep 2013 17:44:11 +0200 Subject: [PATCH 8/8] fix link to Class Loader docs --- book/http_fundamentals.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/http_fundamentals.rst b/book/http_fundamentals.rst index 8ead7a1299b..6bc0e6d1970 100644 --- a/book/http_fundamentals.rst +++ b/book/http_fundamentals.rst @@ -520,7 +520,7 @@ regardless of how your project is developed. To name a few: * `Validator`_ A system for creating rules about data and then validating whether or not user-submitted data follows those rules; -* :doc:`ClassLoader` An autoloading library that allows +* :doc:`ClassLoader` An autoloading library that allows PHP classes to be used without needing to manually ``require`` the files containing those classes;