From cc9d61845e89c640c0ab779a759c425d5ab1e217 Mon Sep 17 00:00:00 2001 From: Sebastian Goettschkes Date: Sun, 2 Dec 2012 22:10:57 +0100 Subject: [PATCH 1/7] Remove the reqire on app/autoload from code-example --- cookbook/debugging.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/cookbook/debugging.rst b/cookbook/debugging.rst index 31e5b324d6a..d5215de4a27 100644 --- a/cookbook/debugging.rst +++ b/cookbook/debugging.rst @@ -46,7 +46,6 @@ below:: // ... // require_once __DIR__.'/../app/bootstrap.php.cache'; - require_once __DIR__.'/../app/autoload.php'; require_once __DIR__.'/../app/AppKernel.php'; use Symfony\Component\HttpFoundation\Request; From 5986e2b7b08905328f53748e991b013ef24f3e3a Mon Sep 17 00:00:00 2001 From: Sebastian Goettschkes Date: Sun, 2 Dec 2012 22:12:02 +0100 Subject: [PATCH 2/7] Changing text which refers to the old autoloading mechanism This only include minor changes. --- book/performance.rst | 3 +-- contributing/code/tests.rst | 3 +-- cookbook/form/form_collections.rst | 5 ++--- quick_tour/the_architecture.rst | 3 +-- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/book/performance.rst b/book/performance.rst index 51324416454..35b7c337d31 100644 --- a/book/performance.rst +++ b/book/performance.rst @@ -46,7 +46,7 @@ Use Composer's Class Map Functionality -------------------------------------- By default, the Symfony2 standard edition uses Composer's autoloader -in the `autoload.php`_ file. This autoloader is easy to use, as it will +in the `vendor/autoload.php` file. This autoloader is easy to use, as it will automatically find any new classes that you've placed in the registered directories. @@ -138,5 +138,4 @@ is no longer a reason to use a bootstrap file. .. _`byte code caches`: http://en.wikipedia.org/wiki/List_of_PHP_accelerators .. _`APC`: http://php.net/manual/en/book.apc.php -.. _`autoload.php`: https://github.com/symfony/symfony-standard/blob/master/app/autoload.php .. _`bootstrap file`: https://github.com/sensio/SensioDistributionBundle/blob/master/Composer/ScriptHandler.php diff --git a/contributing/code/tests.rst b/contributing/code/tests.rst index 873f3c382eb..d99a1516722 100644 --- a/contributing/code/tests.rst +++ b/contributing/code/tests.rst @@ -19,8 +19,7 @@ Dependencies (optional) To run the entire test suite, including tests that depend on external dependencies, Symfony2 needs to be able to autoload them. By default, they are -autoloaded from `vendor/` under the main root directory (see -`autoload.php.dist`). +autoloaded from `vendor/` under the main root directory. The test suite needs the following third-party libraries: diff --git a/cookbook/form/form_collections.rst b/cookbook/form/form_collections.rst index c97b4014912..737e8dc836e 100755 --- a/cookbook/form/form_collections.rst +++ b/cookbook/form/form_collections.rst @@ -263,9 +263,8 @@ great, your user can't actually add any new tags yet. This directive limits recursion to 100 calls which may not be enough for rendering the form in the template if you render the whole form at once (e.g ``form_widget(form)``). To fix this you can set this directive - to a higher value (either via a PHP ini file or via :phpfunction:`ini_set`, - for example in ``app/autoload.php``) or render each form field by hand - using ``form_row``. + to a higher value (either via a PHP ini file or via :phpfunction:`ini_set`) + or render each form field by hand using ``form_row``. .. _cookbook-form-collections-new-prototype: diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index 16f7fbbcb14..ca098beae3c 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -59,8 +59,7 @@ This class must implement two methods: (more on this later). Autoloading is handled automatically via `Composer`_, which means that you -can use any PHP classes without doing anything at all! If you need more flexibility, -you can extend the autoloader in the ``app/autoload.php`` file. All dependencies +can use any PHP classes without doing anything at all! All dependencies are stored under the ``vendor/`` directory, but this is just a convention. You can store them wherever you want, globally on your server or locally in your projects. From fc3e6b91f9a87871d67dc37b146e8dbd231059b6 Mon Sep 17 00:00:00 2001 From: Sebastian Goettschkes Date: Sun, 2 Dec 2012 22:14:41 +0100 Subject: [PATCH 3/7] Changing text which refers to the old app/autoload.php to mention "the Composer" way. --- book/page_creation.rst | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/book/page_creation.rst b/book/page_creation.rst index a2f74db1f9d..4083bd27e81 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -506,13 +506,13 @@ You'll learn more about each of these directories in later chapters. .. sidebar:: Autoloading - When Symfony is loading, a special file - ``app/autoload.php`` - is included. - This file is responsible for configuring the autoloader, which will autoload - your application files from the ``src/`` directory and third-party libraries - from the ``vendor/`` directory. + When Symfony is loading, a special file - ``vendor/autoload.php`` - is + included. This file is created by Composer and will autoload all + application files living in the `src/` folder as well as all + third-party libraries mentioned in the ``composer.json`` file. Because of the autoloader, you never need to worry about using ``include`` - or ``require`` statements. Instead, Symfony2 uses the namespace of a class + or ``require`` statements. Instead, Composer uses the namespace of a class to determine its location and automatically includes the file on your behalf the instant you need a class. @@ -527,11 +527,6 @@ You'll learn more about each of these directories in later chapters. Path: src/Acme/HelloBundle/Controller/HelloController.php - Typically, the only time you'll need to worry about the ``app/autoload.php`` - file is when you're including a new third-party library in the ``vendor/`` - directory. For more information on autoloading, see - :doc:`How to autoload Classes`. - The Source (``src``) Directory ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -599,11 +594,6 @@ method of the ``AppKernel`` class:: With the ``registerBundles()`` method, you have total control over which bundles are used by your application (including the core Symfony bundles). -.. tip:: - - A bundle can live *anywhere* as long as it can be autoloaded (via the - autoloader configured at ``app/autoload.php``). - Creating a Bundle ~~~~~~~~~~~~~~~~~ From e3a9757303948e5c5e69854868ccdc5e0eeae3c5 Mon Sep 17 00:00:00 2001 From: Sebastian Goettschkes Date: Sun, 2 Dec 2012 22:20:51 +0100 Subject: [PATCH 4/7] Removing wrong mentioning of a `src/autload.php` --- book/internals.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/book/internals.rst b/book/internals.rst index dd67e44e508..8df6a1d0efd 100644 --- a/book/internals.rst +++ b/book/internals.rst @@ -22,8 +22,7 @@ on top of the previous one. .. tip:: Autoloading is not managed by the framework directly; it's done by using - Composer's autoloader (``vendor/autoload.php``), which is included in - the ``src/autoload.php`` file. + Composer's autoloader (``vendor/autoload.php``). ``HttpFoundation`` Component ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From fd7a3f4bc2ea70bb6183e9858801dd9f84f616eb Mon Sep 17 00:00:00 2001 From: Sebastian Goettschkes Date: Sun, 2 Dec 2012 22:34:21 +0100 Subject: [PATCH 5/7] Rewriting the autoload section to include composer --- cookbook/symfony1.rst | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/cookbook/symfony1.rst b/cookbook/symfony1.rst index 14ec51a0fca..4f35cd3f068 100644 --- a/cookbook/symfony1.rst +++ b/cookbook/symfony1.rst @@ -114,7 +114,7 @@ That array told symfony1 exactly which file contained each class. In the production environment, this caused you to need to clear the cache when classes were added or moved. -In Symfony2, a new class - ``UniversalClassLoader`` - handles this process. +In Symfony2, a tool named `Composer`_ handles this process. The idea behind the autoloader is simple: the name of your class (including the namespace) must match up with the path to the file containing that class. Take the ``FrameworkExtraBundle`` from the Symfony2 Standard Edition as an @@ -136,18 +136,7 @@ As you can see, the location of the file follows the namespace of the class. Specifically, the namespace, ``Sensio\Bundle\FrameworkExtraBundle``, spells out the directory that the file should live in (``vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/``). -This is because, in the ``app/autoload.php`` file, you'll configure Symfony to -look for the ``Sensio`` namespace in the ``vendor/sensio`` directory: - -.. code-block:: php - - // app/autoload.php - - // ... - $loader->registerNamespaces(array( - ..., - 'Sensio' => __DIR__.'/../vendor/sensio/framework-extra-bundle', - )); +Composer can then look for the file at this specific place and load it very fast. If the file did *not* live at this exact location, you'd receive a ``Class "Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle" does not exist.`` @@ -160,24 +149,24 @@ contains a different class). In order for a class to be autoloaded, you As mentioned before, for the autoloader to work, it needs to know that the ``Sensio`` namespace lives in the ``vendor/bundles`` directory and that, for example, the ``Doctrine`` namespace lives in the ``vendor/doctrine/orm/lib/`` -directory. This mapping is entirely controlled by you via the -``app/autoload.php`` file. +directory. This mapping is entirely controlled by Composer. Each +third-party library you load through composer has their settings defined +and Composer takes care of everything for you. + +For this to work, all third-party libraries used by your project must be +defined in the `composer.json` file. If you look at the ``HelloController`` from the Symfony2 Standard Edition you can see that it lives in the ``Acme\DemoBundle\Controller`` namespace. Yet, the -``Acme`` namespace is not defined in the ``app/autoload.php``. By default you -do not need to explicitly configure the location of bundles that live in the -``src/`` directory. The ``UniversalClassLoader`` is configured to fallback to -the ``src/`` directory using its ``registerNamespaceFallbacks`` method: +``AcmeDemoBundle`` is not defined in your `composer.json` file. Nonetheless are +the files autoloaded. This is because you can tell composer to autoload files +from specific directories without defining a dependency: -.. code-block:: php - - // app/autoload.php +.. code-block:: yaml - // ... - $loader->registerNamespaceFallbacks(array( - __DIR__.'/../src', - )); + "autoload": { + "psr-0": { "": "src/" } + } Using the Console ----------------- @@ -312,3 +301,4 @@ primarily to configure objects that you can use. For more information, see the chapter titled ":doc:`/book/service_container`". .. _`Symfony2 Standard`: https://github.com/symfony/symfony-standard +.. _`Composer`: http://getcomposer.org \ No newline at end of file From 2250f607bd842c628cd8034990ac0d4747d73f65 Mon Sep 17 00:00:00 2001 From: Sebastian Goettschkes Date: Mon, 3 Dec 2012 13:10:05 +0100 Subject: [PATCH 6/7] Reverting changes which remove mentioning of the app/autoload.php --- book/page_creation.rst | 4 ++++ book/performance.rst | 3 ++- cookbook/debugging.rst | 1 + cookbook/form/form_collections.rst | 5 +++-- quick_tour/the_architecture.rst | 3 ++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/book/page_creation.rst b/book/page_creation.rst index 4083bd27e81..0f3d639a888 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -594,6 +594,10 @@ method of the ``AppKernel`` class:: With the ``registerBundles()`` method, you have total control over which bundles are used by your application (including the core Symfony bundles). +.. tip:: + + A bundle can live *anywhere* as long as it can be autoloaded (via the + autoloader configured at ``app/autoload.php``). Creating a Bundle ~~~~~~~~~~~~~~~~~ diff --git a/book/performance.rst b/book/performance.rst index 35b7c337d31..51324416454 100644 --- a/book/performance.rst +++ b/book/performance.rst @@ -46,7 +46,7 @@ Use Composer's Class Map Functionality -------------------------------------- By default, the Symfony2 standard edition uses Composer's autoloader -in the `vendor/autoload.php` file. This autoloader is easy to use, as it will +in the `autoload.php`_ file. This autoloader is easy to use, as it will automatically find any new classes that you've placed in the registered directories. @@ -138,4 +138,5 @@ is no longer a reason to use a bootstrap file. .. _`byte code caches`: http://en.wikipedia.org/wiki/List_of_PHP_accelerators .. _`APC`: http://php.net/manual/en/book.apc.php +.. _`autoload.php`: https://github.com/symfony/symfony-standard/blob/master/app/autoload.php .. _`bootstrap file`: https://github.com/sensio/SensioDistributionBundle/blob/master/Composer/ScriptHandler.php diff --git a/cookbook/debugging.rst b/cookbook/debugging.rst index d5215de4a27..31e5b324d6a 100644 --- a/cookbook/debugging.rst +++ b/cookbook/debugging.rst @@ -46,6 +46,7 @@ below:: // ... // require_once __DIR__.'/../app/bootstrap.php.cache'; + require_once __DIR__.'/../app/autoload.php'; require_once __DIR__.'/../app/AppKernel.php'; use Symfony\Component\HttpFoundation\Request; diff --git a/cookbook/form/form_collections.rst b/cookbook/form/form_collections.rst index 737e8dc836e..c97b4014912 100755 --- a/cookbook/form/form_collections.rst +++ b/cookbook/form/form_collections.rst @@ -263,8 +263,9 @@ great, your user can't actually add any new tags yet. This directive limits recursion to 100 calls which may not be enough for rendering the form in the template if you render the whole form at once (e.g ``form_widget(form)``). To fix this you can set this directive - to a higher value (either via a PHP ini file or via :phpfunction:`ini_set`) - or render each form field by hand using ``form_row``. + to a higher value (either via a PHP ini file or via :phpfunction:`ini_set`, + for example in ``app/autoload.php``) or render each form field by hand + using ``form_row``. .. _cookbook-form-collections-new-prototype: diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index ca098beae3c..16f7fbbcb14 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -59,7 +59,8 @@ This class must implement two methods: (more on this later). Autoloading is handled automatically via `Composer`_, which means that you -can use any PHP classes without doing anything at all! All dependencies +can use any PHP classes without doing anything at all! If you need more flexibility, +you can extend the autoloader in the ``app/autoload.php`` file. All dependencies are stored under the ``vendor/`` directory, but this is just a convention. You can store them wherever you want, globally on your server or locally in your projects. From c2978e36ade903404a0d4a563c2233c8e4751fb4 Mon Sep 17 00:00:00 2001 From: Sebastian Goettschkes Date: Mon, 3 Dec 2012 17:52:03 +0100 Subject: [PATCH 7/7] Partially reverting some changes and improving the original content --- book/internals.rst | 3 ++- contributing/code/tests.rst | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/book/internals.rst b/book/internals.rst index 8df6a1d0efd..58f57d31dc2 100644 --- a/book/internals.rst +++ b/book/internals.rst @@ -22,7 +22,8 @@ on top of the previous one. .. tip:: Autoloading is not managed by the framework directly; it's done by using - Composer's autoloader (``vendor/autoload.php``). + Composer's autoloader (``vendor/autoload.php``), which is included in + the ``app/autoload.php`` file. ``HttpFoundation`` Component ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/contributing/code/tests.rst b/contributing/code/tests.rst index d99a1516722..873f3c382eb 100644 --- a/contributing/code/tests.rst +++ b/contributing/code/tests.rst @@ -19,7 +19,8 @@ Dependencies (optional) To run the entire test suite, including tests that depend on external dependencies, Symfony2 needs to be able to autoload them. By default, they are -autoloaded from `vendor/` under the main root directory. +autoloaded from `vendor/` under the main root directory (see +`autoload.php.dist`). The test suite needs the following third-party libraries: