Skip to content

Commit

Permalink
Merge branch '2.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Jul 28, 2015
2 parents 7711e97 + 0281f61 commit 14b39c3
Show file tree
Hide file tree
Showing 43 changed files with 701 additions and 657 deletions.
4 changes: 2 additions & 2 deletions book/from_flat_php_to_symfony2.rst
Expand Up @@ -266,7 +266,7 @@ an individual blog result based on a given id::
$link = open_database_connection();

$id = intval($id);
$query = 'SELECT date, title, body FROM post WHERE id = '.$id;
$query = 'SELECT created_at, title, body FROM post WHERE id = '.$id;
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

Expand Down Expand Up @@ -297,7 +297,7 @@ the individual blog post:
<?php ob_start() ?>
<h1><?php echo $post['title'] ?></h1>

<div class="date"><?php echo $post['date'] ?></div>
<div class="date"><?php echo $post['created_at'] ?></div>
<div class="body">
<?php echo $post['body'] ?>
</div>
Expand Down
4 changes: 4 additions & 0 deletions book/templating.rst
Expand Up @@ -579,6 +579,10 @@ you set `with_context`_ to false).
maps (i.e. an array with named keys). If you needed to pass in multiple
elements, it would look like this: ``{'foo': foo, 'bar': bar}``.

.. versionadded:: 2.3
The `include() function`_ is a new Twig feature that's available in Symfony
2.3. Prior, the `{% include %} tag`_ tag was used.

.. index::
single: Templating; Embedding action

Expand Down
34 changes: 17 additions & 17 deletions components/class_loader/class_loader.rst
Expand Up @@ -4,14 +4,14 @@
The PSR-0 Class Loader
======================

If your classes and third-party libraries follow the `PSR-0`_ standard, 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`_ standard,
you can use the :class:`Symfony\\Component\\ClassLoader\\ClassLoader` class
to load all of your project's classes.

.. tip::

You can use both the ``ApcClassLoader`` and the ``XcacheClassLoader`` to
:doc:`cache </components/class_loader/cache_class_loader>` a ``ClassLoader``
You can use both the ``ApcClassLoader`` and the ``XcacheClassLoader``
to :doc:`cache </components/class_loader/cache_class_loader>` a ``ClassLoader``
instance.

Usage
Expand All @@ -35,12 +35,12 @@ is straightforward::

.. note::

The autoloader is automatically registered in a Symfony application (see
``app/autoload.php``).
The autoloader is automatically registered in a Symfony application
(see ``app/autoload.php``).

Use the :method:`Symfony\\Component\\ClassLoader\\ClassLoader::addPrefix` or
:method:`Symfony\\Component\\ClassLoader\\ClassLoader::addPrefixes` methods to
register your classes::
Use :method:`Symfony\\Component\\ClassLoader\\ClassLoader::addPrefix` or
:method:`Symfony\\Component\\ClassLoader\\ClassLoader::addPrefixes` to register
your classes::

// register a single namespaces
$loader->addPrefix('Symfony', __DIR__.'/vendor/symfony/symfony/src');
Expand All @@ -59,9 +59,9 @@ register your classes::
'Twig_' => __DIR__.'/vendor/twig/twig/lib',
));

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::
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->addPrefixes(array(
'Doctrine\\Common' => __DIR__.'/vendor/doctrine/common/lib',
Expand All @@ -71,10 +71,10 @@ projects::
));

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. If not found, it will then fallback to the default
``Doctrine`` directory (the last one configured) before giving up. The order
of the prefix registrations is significant in this case.
or one of its children, the autoloader will first look for the class under
the ``doctrine-common`` directory. If not found, it will then fallback to
the default ``Doctrine`` directory (the last one configured) before giving
up. The order of the prefix registrations is significant in this case.

.. _PEAR: http://pear.php.net/manual/en/standards.naming.php
.. _PSR-0: http://www.php-fig.org/psr/psr-0/
27 changes: 15 additions & 12 deletions components/class_loader/class_map_generator.rst
Expand Up @@ -5,10 +5,11 @@
The Class Map Generator
=======================

Loading a class usually is an easy task given the `PSR-0`_ and `PSR-4`_ standards.
Thanks to the Symfony ClassLoader component or the autoloading mechanism provided
by Composer, you don't have to map your class names to actual PHP files manually.
Nowadays, PHP libraries usually come with autoloading support through Composer.
Loading a class usually is an easy task given the `PSR-0`_ and `PSR-4`_
standards. Thanks to the Symfony ClassLoader component or the autoloading
mechanism provided by Composer, you don't have to map your class names to
actual PHP files manually. Nowadays, PHP libraries usually come with autoloading
support through Composer.

But from time to time you may have to use a third-party library that comes
without any autoloading support and therefore forces you to load each class
Expand Down Expand Up @@ -44,16 +45,17 @@ it possible to create a map of class names to files.
Generating a Class Map
----------------------

To generate the class map, simply pass the root directory of your class files
to the :method:`Symfony\\Component\\ClassLoader\\ClassMapGenerator::createMap`
To generate the class map, simply pass the root directory of your class
files to the
:method:`Symfony\\Component\\ClassLoader\\ClassMapGenerator::createMap`
method::

use Symfony\Component\ClassLoader\ClassMapGenerator;

var_dump(ClassMapGenerator::createMap(__DIR__.'/library'));

Given the files and class from the table above, you should see an output like
this:
Given the files and class from the table above, you should see an output
like this:

.. code-block:: text
Expand Down Expand Up @@ -87,8 +89,9 @@ file in the same directory with the following contents::
'Acme\\Bar' => '/var/www/library/bar/Foo.php',
);

Instead of loading each file manually, you'll only have to register the generated
class map with, for example, the :class:`Symfony\\Component\\ClassLoader\\MapClassLoader`::
Instead of loading each file manually, you'll only have to register the
generated class map with, for example, the
:class:`Symfony\\Component\\ClassLoader\\MapClassLoader`::

use Symfony\Component\ClassLoader\MapClassLoader;

Expand All @@ -110,8 +113,8 @@ class map with, for example, the :class:`Symfony\\Component\\ClassLoader\\MapCla
component.

Besides dumping the class map for one directory, you can also pass an array
of directories for which to generate the class map (the result actually is
the same as in the example above)::
of directories for which to generate the class map (the result actually
is the same as in the example above)::

use Symfony\Component\ClassLoader\ClassMapGenerator;

Expand Down
8 changes: 5 additions & 3 deletions components/class_loader/introduction.rst
Expand Up @@ -11,11 +11,12 @@ Usage
-----

Whenever you reference a class that has not been required or included yet,
PHP uses the `autoloading mechanism`_ to delegate the loading of a file defining
the class. Symfony provides three autoloaders, which are able to load your classes:
PHP uses the `autoloading mechanism`_ to delegate the loading of a file
defining the class. Symfony provides three autoloaders, which are able to
load your classes:

* :doc:`/components/class_loader/class_loader`: loads classes that follow
the `PSR-0` class naming standard;
the `PSR-0`_ class naming standard;

* :doc:`/components/class_loader/psr4_class_loader`: loads classes that follow
the `PSR-4` class naming standard;
Expand Down Expand Up @@ -43,5 +44,6 @@ You can install the component in 2 different ways:

.. include:: /components/require_autoload.rst.inc

.. _PSR-0: http://www.php-fig.org/psr/psr-0/
.. _`autoloading mechanism`: http://php.net/manual/en/language.oop5.autoload.php
.. _Packagist: https://packagist.org/packages/symfony/class-loader
20 changes: 11 additions & 9 deletions components/class_loader/map_class_loader.rst
Expand Up @@ -4,20 +4,22 @@
MapClassLoader
==============

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

The ``MapClassLoader`` can be used along with the :doc:`PSR-0 class loader </components/class_loader/class_loader>`
by configuring and calling the ``register()`` method on both.
The ``MapClassLoader`` can be used along with the
:doc:`PSR-0 class loader </components/class_loader/class_loader>` by
configuring and calling the ``register()`` method on both.

.. note::

The default behavior is to append the ``MapClassLoader`` on the autoload
stack. If you want to use it as the first autoloader, pass ``true`` when
calling the ``register()`` method. Your class loader will then be prepended
on the autoload stack.
stack. If you want to use it as the first autoloader, pass ``true``
when calling the ``register()`` method. Your class loader will then
be prepended on the autoload stack.

Usage
-----
Expand Down
39 changes: 20 additions & 19 deletions components/config/caching.rst
@@ -1,26 +1,27 @@
.. index::
single: Config; Caching based on resources

Caching Based on Resources
Caching based on Resources
==========================

When all configuration resources are loaded, you may want to process the configuration
values and combine them all in one file. This file acts like a cache. Its
contents don’t have to be regenerated every time the application runs – only
when the configuration resources are modified.
When all configuration resources are loaded, you may want to process the
configuration values and combine them all in one file. This file acts
like a cache. Its contents don’t have to be regenerated every time the
application runs – only when the configuration resources are modified.

For example, the Symfony Routing component allows you to load all routes,
and then dump a URL matcher or a URL generator based on these routes. In
this case, when one of the resources is modified (and you are working in a
development environment), the generated file should be invalidated and regenerated.
This can be accomplished by making use of the :class:`Symfony\\Component\\Config\\ConfigCache`
class.

The example below shows you how to collect resources, then generate some code
based on the resources that were loaded, and write this code to the cache. The
cache also receives the collection of resources that were used for generating
the code. By looking at the "last modified" timestamp of these resources,
the cache can tell if it is still fresh or that its contents should be regenerated::
this case, when one of the resources is modified (and you are working
in a development environment), the generated file should be invalidated
and regenerated. This can be accomplished by making use of the
:class:`Symfony\\Component\\Config\\ConfigCache` class.

The example below shows you how to collect resources, then generate some
code based on the resources that were loaded and write this code to the
cache. The cache also receives the collection of resources that were used
for generating the code. By looking at the "last modified" timestamp of
these resources, the cache can tell if it is still fresh or that its contents
should be regenerated::

use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Resource\FileResource;
Expand Down Expand Up @@ -52,8 +53,8 @@ the cache can tell if it is still fresh or that its contents should be regenerat
// you may want to require the cached code:
require $cachePath;

In debug mode, a ``.meta`` file will be created in the same directory as the
cache file itself. This ``.meta`` file contains the serialized resources,
whose timestamps are used to determine if the cache is still fresh. When not
in debug mode, the cache is considered to be "fresh" as soon as it exists,
In debug mode, a ``.meta`` file will be created in the same directory as
the cache file itself. This ``.meta`` file contains the serialized resources,
whose timestamps are used to determine if the cache is still fresh. When
not in debug mode, the cache is considered to be "fresh" as soon as it exists,
and therefore no ``.meta`` file will be generated.

0 comments on commit 14b39c3

Please sign in to comment.