Skip to content

Commit

Permalink
Merge branch '2.7'
Browse files Browse the repository at this point in the history
* 2.7: (47 commits)
  Removed duplicate "long"s
  terminate file with newline
  move title back and move description to separate file as suggested in PR #4892
  move title out of included file as suggested in PR #4892
  Add possible values for widget_type
  [#4842] Making 2 sentences
  changes as suggested by WouterJ in pull request #4842
  Add meaning of yellow icon for number of queries
  Fixing bad link name
  fix typo in event flow diagrams
  Many fixes thanks to stof, WouterJ, xabbuh and dupuchba
  added Jakub as a merger for the DomCrawler component
  Changes thanks to WouterJ and xabbuh
  [#5094] Removing mkdir - it's not needed (thanks xabbuh)
  some tweaks to #4601
  Moving index down to correct section
  [#4989] Language tweaks and making the example simpler
  Remove useless setLocale() call and add code block with locale setter
  Finaly touches on translation locale setting note
  Review note about setting the translator locale in a controller.
  ...
  • Loading branch information
weaverryan committed Mar 24, 2015
2 parents 3fb0d42 + 8566263 commit 7681e39
Show file tree
Hide file tree
Showing 36 changed files with 542 additions and 521 deletions.
18 changes: 18 additions & 0 deletions best_practices/forms.rst
Expand Up @@ -207,3 +207,21 @@ Second, we recommend using ``$form->isSubmitted()`` in the ``if`` statement
for clarity. This isn't technically needed, since ``isValid()`` first calls
``isSubmitted()``. But without this, the flow doesn't read well as it *looks*
like the form is *always* processed (even on the GET request).

Custom Form Field Types
-----------------------

.. best-practice::

Add the ``app_`` prefix to your custom form field types to avoid collisions.

Custom form field types inherit from the ``AbstractType`` class, which defines the
``getName()`` method to configure the name of that form type. These names must
be unique in the application.

If a custom form type uses the same name as any of the Symfony's built-in form
types, it will override it. The same happens when the custom form type matches
any of the types defined by the third-party bundles installed in your application.

Add the ``app_`` prefix to your custom form field types to avoid name collisions
that can lead to hard to debug errors.
2 changes: 1 addition & 1 deletion book/controller.rst
Expand Up @@ -451,7 +451,7 @@ Or, if you want to redirect externally, just use ``redirect()`` and pass it the
}

By default, the ``redirectToRoute()`` method performs a 302 (temporary) redirect. To
perform a 301 (permanent) redirect, modify the second argument::
perform a 301 (permanent) redirect, modify the third argument::

public function indexAction()
{
Expand Down
3 changes: 3 additions & 0 deletions book/doctrine.rst
Expand Up @@ -646,6 +646,9 @@ to easily fetch objects based on multiple conditions::

If you click the icon, the profiler will open, showing you the exact
queries that were made.

The icon will turn yellow if there were more than 50 queries on the
page. This could indicate that something is not correct.

Updating an Object
~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 10 additions & 3 deletions book/forms.rst
Expand Up @@ -1061,9 +1061,16 @@ that will house the logic for building the task form::
}
}

This new class contains all the directions needed to create the task form
(note that the ``getName()`` method should return a unique identifier for this
form "type"). It can be used to quickly build a form object in the controller::
.. caution::

The ``getName()`` method returns the identifier of this form "type". These
identifiers must be unique in the application. Unless you want to override
a built-in type, they should be different from the default Symfony types
and from any type defined by a third-party bundle installed in your application.
Consider prefixing your types with ``app_`` to avoid identifier collisions.

This new class contains all the directions needed to create the task form. It can
be used to quickly build a form object in the controller::

// src/AppBundle/Controller/DefaultController.php

Expand Down
2 changes: 1 addition & 1 deletion book/http_fundamentals.rst
Expand Up @@ -460,7 +460,7 @@ by adding an entry for ``/contact`` to your routing configuration file:
When someone visits the ``/contact`` page, this route is matched, and the
specified controller is executed. As you'll learn in the :doc:`routing chapter </book/routing>`,
the ``AcmeDemoBundle:Main:contact`` string is a short syntax that points to a
the ``AppBundle:Main:contact`` string is a short syntax that points to a
specific PHP method ``contactAction`` inside a class called ``MainController``::

// src/AppBundle/Controller/MainController.php
Expand Down
28 changes: 21 additions & 7 deletions book/translation.rst
Expand Up @@ -427,17 +427,28 @@ via the ``request`` object::
public function indexAction(Request $request)
{
$locale = $request->getLocale();

$request->setLocale('en_US');
}

.. tip::
To set the user's locale, you may want to create a custom event listener
so that it's set before any other parts of the system (i.e. the translator)
need it::

Read :doc:`/cookbook/session/locale_sticky_session` to learn how to store
the user's locale in the session.
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();

.. index::
single: Translations; Fallback and default locale
// some logic to determine the $locale
$request->getSession()->set('_locale', $locale);
}

Read :doc:`/cookbook/session/locale_sticky_session` for more on the topic.

.. note::

Setting the locale using ``$request->setLocale()`` in the controller
is too late to affect the translator. Either set the locale via a listener
(like above), the URL (see next) or call ``setLocale()`` directly on
the ``translator`` service.

See the :ref:`book-translation-locale-url` section below about setting the
locale via routing.
Expand Down Expand Up @@ -518,6 +529,9 @@ in your application.
Read :doc:`/cookbook/routing/service_container_parameters` to learn how to
avoid hardcoding the ``_locale`` requirement in all your routes.

.. index::
single: Translations; Fallback and default locale

Setting a default Locale
~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
95 changes: 65 additions & 30 deletions components/asset/introduction.rst
Expand Up @@ -26,15 +26,16 @@ simple. Hardcoding URLs can be a disadvantage because:
asset. When using the Asset component, you can group assets in packages to
avoid repeating the common part of their path;
* **Versioning is difficult**: it has to be custom managed for each
application. Adding a version to the asset URLs is essential for some applications
because it allows to control how the assets are cached. The Asset component
allows to define different versioning strategies for each package;
application. Adding a version (e.g. ``main.css?v=5``) to the asset URLs
is essential for some applications because it allows you to control how
the assets are cached. The Asset component allows you to define different
versioning strategies for each package;
* **Moving assets location** is cumbersome and error-prone: it requires you to
carefully update the URLs of all assets included in all templates. The Asset
component allows to move assets effortlessly just by changing the base path
value associated with the package of assets;
* **It's nearly impossible to use multiple CDNs**: this technique requires to
change the URL of the asset randomly for each request. The Asset component
* **It's nearly impossible to use multiple CDNs**: this technique requires
you to change the URL of the asset randomly for each request. The Asset component
provides out-of-the-box support for any number of multiple CDNs, both regular
(``http://``) and secure (``https://``).

Expand Down Expand Up @@ -65,7 +66,7 @@ any versioning::
echo $package->getUrl('/image.png');
// result: /image.png

Packages implement the :class:`Symfony\\Component\\Asset\\PackageInterface`,
Packages implement :class:`Symfony\\Component\\Asset\\PackageInterface`,
which defines the following two methods:

:method:`Symfony\\Component\\Asset\\PackageInterface::getVersion`
Expand All @@ -74,18 +75,27 @@ which defines the following two methods:
:method:`Symfony\\Component\\Asset\\PackageInterface::getUrl`
Returns an absolute or root-relative public path.

With a package, you can:

A) :ref:`version the assets <component-assets-versioning>`;
B) set a :ref:`common base path <component-assets-path-package>` (e.g. ``/css``)
for the assets;
C) :ref:`configure a CDN <component-assets-cdn>` for the assets

.. _component-assets-versioning:

Versioned Assets
~~~~~~~~~~~~~~~~

One of the main features of the Asset component is to manage the versioning of
the application's assets. Asset versions are commonly used to control how these
assets are cached.
One of the main features of the Asset component is the ability to manage
the versioning of the application's assets. Asset versions are commonly used
to control how these assets are cached.

Instead of relying on a simple version mechanism, the Asset component allows to
define advanced versioning strategies via PHP classes. The two built-in strategies
provided by the component are :class:`Symfony\\Component\\Asset\\VersionStrategy\\EmptyVersionStrategy`,
Instead of relying on a simple version mechanism, the Asset component allows
you to define advanced versioning strategies via PHP classes. The two built-in
strategies are the :class:`Symfony\\Component\\Asset\\VersionStrategy\\EmptyVersionStrategy`,
which doesn't add any version to the asset and :class:`Symfony\\Component\\Asset\\VersionStrategy\\StaticVersionStrategy`,
which allows to set the version with a format string.
which allows you to set the version with a format string.

In this example, the ``StaticVersionStrategy`` is used to append the ``v1``
suffix to any asset path::
Expand Down Expand Up @@ -143,13 +153,15 @@ every day::
}
}

.. _component-assets-path-package:

Grouped Assets
~~~~~~~~~~~~~~

It's common for applications to store their assets in a common path. If that's
your case, replace the default :class:`Symfony\\Component\\Asset\\Package` class
by :class:`Symfony\\Component\\Asset\\PathPackage` to avoid repeating the same
path time and again::
Often, many assets live under a common path (e.g. ``/static/images``). If
that's your case, replace the default :class:`Symfony\\Component\\Asset\\Package`
class with :class:`Symfony\\Component\\Asset\\PathPackage` to avoid repeating
that path over and over again::

use Symfony\Component\Asset\PathPackage;
// ...
Expand All @@ -162,9 +174,9 @@ path time and again::
Request Context Aware Assets
............................

If you are also using the HttpFoundation component in your project, for example
in a Symfony application, the ``PathPackage`` class can take into account the
context of the current request::
If you are also using the :doc:`HttpFoundation </components/http_foundation/introduction>`
component in your project (for instance, in a Symfony application), the ``PathPackage``
class can take into account the context of the current request::

use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\Context\RequestStackContext;
Expand All @@ -179,10 +191,13 @@ context of the current request::
echo $package->getUrl('/logo.png');
// result: /somewhere/static/images/logo.png?v1

When the request context is set (via an optional third argument), in addition to
the configured base path, ``PathPackage`` also prepends the current request base
URL (``/somewhere/`` in this example) to assets. This allows your website to be
hosted anywhere under the web server root directory.
Now that the request context is set, the ``PathPackage`` will prepend the
current request base URL. So, for example, if your entire site is hosted under
the ``/somewhere`` directory of your web server root directory and the configured
base path is ``/static/images``, all paths will be prefixed with
``/somewhere/static/images``.

.. _component-assets-cdn:

Absolute Assets and CDNs
~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -202,25 +217,44 @@ class to generate absolute URLs for their assets::
echo $package->getUrl('/logo.png');
// result: http://static.example.com/images/logo.png?v1

You can also pass a schema-agnostic URL::

use Symfony\Component\Asset\UrlPackage;
// ...

$package = new UrlPackage(
'//static.example.com/images/',
new StaticVersionStrategy('v1')
);

echo $package->getUrl('/logo.png');
// result: //static.example.com/images/logo.png?v1

This is useful because assets will automatically be requested via HTTPS if
a visitor is viewing your site in https. Just make sure that your CDN host
supports https.

In case you serve assets from more than one domain to improve application
performance, pass an array of URLs as the first argument of ``UrlPackage``
performance, pass an array of URLs as the first argument to the ``UrlPackage``
constructor::

use Symfony\Component\Asset\UrlPackage;
// ...

$urls = array(
'http://static1.example.com/images/',
'http://static2.example.com/images/',
'//static1.example.com/images/',
'//static2.example.com/images/',
);
$package = new UrlPackage($urls, new StaticVersionStrategy('v1'));

echo $package->getUrl('/logo.png');
// result: http://static1.example.com/images/logo.png?v1
echo $package->getUrl('/icon.png');
// result: http://static2.example.com/images/icon.png?v1

The selection of the domain which will serve the asset is deterministic, meaning
that each asset will be always served by the same domain. This behavior simplifies
the management of HTTP cache.
For each asset, one of the URLs will be randomly used. But, the selection
is deterministic, meaning that each asset will be always served by the same
domain. This behavior simplifies the management of HTTP cache.

Request Context Aware Assets
............................
Expand All @@ -241,6 +275,7 @@ protocol-relative URLs for HTTPs requests, any base URL for HTTP requests)::
);

echo $package->getUrl('/logo.png');
// assuming the RequestStackContext says that we are on a secure host
// result: https://example.com/logo.png?v1

Named Packages
Expand Down
9 changes: 2 additions & 7 deletions components/using_components.rst
Expand Up @@ -36,12 +36,6 @@ whatever component you want.
file in your directory. In that case, no worries! Just run
``php composer.phar require symfony/finder``.

If you know you need a specific version of the library, add that to the command:

.. code-block:: bash
$ composer require symfony/finder
**3.** Write your code!

Once Composer has downloaded the component(s), all you need to do is include
Expand All @@ -51,7 +45,8 @@ immediately::

// File example: src/script.php

// update this to the path to the "vendor/" directory, relative to this file
// update this to the path to the "vendor/"
// directory, relative to this file
require_once __DIR__.'/../vendor/autoload.php';

use Symfony\Component\Finder\Finder;
Expand Down
14 changes: 11 additions & 3 deletions contributing/code/core_team.rst
Expand Up @@ -60,14 +60,19 @@ Active Core Members
MonologBridge_, and TwigBridge_ components;

* **Kévin Dunglas** (`dunglas`_) can merge into the Serializer_
component.
component;

* **Abdellatif AitBoudad** (`aitboudad`_) can merge into the Translation_
component;

* **Jakub Zalas** (`jakzal`_) can merge into the DomCrawler_ component.

* **Deciders** (``@symfony/deciders`` on GitHub):

* **Jakub Zalas** (`jakzal`_);
* **Jordi Boggiano** (`seldaek`_);
* **Lukas Kahwe Smith** (`lsmith77`_);
* **Ryan Weaver** (`weaverryan`_).
* **Ryan Weaver** (`weaverryan`_);
* **Christian Flothmann** (`xabbuh`_).

Core Membership Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -165,6 +170,7 @@ discretion of the **Project Leader**.
.. _PropertyAccess: https://github.com/symfony/PropertyAccess
.. _Routing: https://github.com/symfony/Routing
.. _Serializer: https://github.com/symfony/Serializer
.. _Translation: https://github.com/symfony/Translation
.. _Stopwatch: https://github.com/symfony/Stopwatch
.. _TwigBridge: https://github.com/symfony/TwigBridge
.. _Validator: https://github.com/symfony/Validator
Expand All @@ -181,3 +187,5 @@ discretion of the **Project Leader**.
.. _`Seldaek`: https://github.com/Seldaek/
.. _`lsmith77`: https://github.com/lsmith77/
.. _`weaverryan`: https://github.com/weaverryan/
.. _`aitboudad`: https://github.com/aitboudad/
.. _`xabbuh`: https://github.com/xabbuh/

0 comments on commit 7681e39

Please sign in to comment.