Skip to content

Commit

Permalink
Merge branch '2.3' into 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed May 21, 2016
2 parents f9edfd5 + c8f4583 commit e29b7ab
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 64 deletions.
5 changes: 0 additions & 5 deletions book/http_cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1207,11 +1207,6 @@ One great advantage of the ESI renderer is that you can make your application
as dynamic as needed and at the same time, hit the application as little as
possible.

.. tip::

The listener only responds to local IP addresses or
:doc:`trusted proxies </cookbook/request/load_balancer_reverse_proxy>`.

.. note::

Once you start using ESI, remember to always use the ``s-maxage``
Expand Down
3 changes: 2 additions & 1 deletion components/event_dispatcher/container_aware_dispatcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ and the second argument is the service's class name (which must implement
The ``EventSubscriberInterface`` is exactly as you would expect::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
// ...

class StoreSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(
'kernel.response' => array(
KernelEvents::RESPONSE => array(
array('onKernelResponsePre', 10),
array('onKernelResponsePost', 0),
),
Expand Down
2 changes: 1 addition & 1 deletion cookbook/bundles/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ can place it anywhere you like. You should return this path as the base path::
}
}

Assume the XSD file is called ``hello-1.0.xsd``, the schema location will be
Assuming the XSD file is called ``hello-1.0.xsd``, the schema location will be
``http://acme_company.com/schema/dic/hello/hello-1.0.xsd``:

.. code-block:: xml
Expand Down
25 changes: 7 additions & 18 deletions cookbook/composer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,24 @@ following sections.
Install Composer on Linux and Mac OS X
--------------------------------------

To install Composer on Linux or Mac OS X, execute the following two commands:
#. Run the installer as described in `the official Composer documentation`_;
#. Execute the following command to move the ``composer.phar`` to a directory that is in your path:

.. code-block:: bash
.. code-block:: bash
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
.. note::

If you don't have ``curl`` installed, you can also just download the
``installer`` file manually at https://getcomposer.org/installer and
then run:

.. code-block:: bash
$ php installer
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo mv composer.phar /usr/local/bin/composer
Install Composer on Windows
---------------------------

Download the installer from `getcomposer.org/download`_, execute it and follow
the instructions.
Download the installer from `getcomposer.org`_, execute it and follow the instructions.

Learn more
----------

Read the `Composer documentation`_ to learn more about its usage and features.

.. _`Composer`: https://getcomposer.org/
.. _`getcomposer.org/download`: https://getcomposer.org/download
.. _`Composer documentation`: https://getcomposer.org/doc/00-intro.md
.. _`getcomposer.org`: https://getcomposer.org/Composer-Setup.exe
.. _the official Composer documentation: https://getcomposer.org/download
3 changes: 2 additions & 1 deletion cookbook/event_dispatcher/event_listener.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ listen to the same ``kernel.exception`` event::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class ExceptionSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
// return the subscribed events, their methods and priorities
return array(
'kernel.exception' => array(
KernelEvents::EXCEPTION => array(
array('processException', 10),
array('logException', 0),
array('notifyException', -10),
Expand Down
51 changes: 23 additions & 28 deletions cookbook/form/data_transformers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ to render the form, and then back into a ``DateTime`` object on submit.
When a form field has the ``inherit_data`` option set, Data Transformers
won't be applied to that field.

Simple Example: Sanitizing HTML on User Input
---------------------------------------------
.. _simple-example-sanitizing-html-on-user-input:

Suppose you have a Task form with a description ``textarea`` type::
Simple Example: Transforming String Tags from User Input to an Array
--------------------------------------------------------------------

Suppose you have a Task form with a tags ``text`` type::

// src/AppBundle/Form/TaskType.php
namespace AppBundle\Form\Type;
Expand All @@ -32,7 +34,7 @@ Suppose you have a Task form with a description ``textarea`` type::
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('description', 'textarea');
$builder->add('tags', 'text')
}

public function configureOptions(OptionsResolver $resolver)
Expand All @@ -45,15 +47,10 @@ Suppose you have a Task form with a description ``textarea`` type::
// ...
}

But, there are two complications:

#. Your users are allowed to use *some* HTML tags, but not others: you need a way
to call :phpfunction:`strip_tags` after the form is submitted;
Internally the ``tags`` are stored as an array, but displayed to the user as a
simple comma seperated string to make them easier to edit.

#. To be friendly, you want to convert ``<br/>`` tags into line breaks (``\n``) before
rendering the field so the text is easier to edit.

This is a *perfect* time to attach a custom data transformer to the ``description``
This is a *perfect* time to attach a custom data transformer to the ``tags``
field. The easiest way to do this is with the :class:`Symfony\\Component\\Form\\CallbackTransformer`
class::

Expand All @@ -68,20 +65,17 @@ class::
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('description', 'textarea');
$builder->add('tags', 'text');

$builder->get('description')
$builder->get('tags')
->addModelTransformer(new CallbackTransformer(
// transform <br/> to \n so the textarea reads easier
function ($originalDescription) {
return preg_replace('#<br\s*/?>#i', "\n", $originalDescription);
function ($tagsAsArray) {
// transform the array to a string
return implode(', ', $tagsAsArray);
},
function ($submittedDescription) {
// remove most HTML tags (but not br,p)
$cleaned = strip_tags($submittedDescription, '<br><br/><p>');

// transform any \n to real <br/>
return str_replace("\n", '<br/>', $cleaned);
function ($tagsAsString) {
// transform the string back to an array
return explode(', ', $tagsAsString);
}
))
;
Expand All @@ -90,10 +84,10 @@ class::
// ...
}

The ``CallbackTransformer`` takes two callback functions as arguments. The first transforms
the original value into a format that'll be used to render the field. The second
does the reverse: it transforms the submitted value back into the format you'll use
in your code.
The ``CallbackTransformer`` takes two callback functions as arguments. The
first transforms the original value into a format that'll be used to render the
field. The second does the reverse: it transforms the submitted value back into
the format you'll use in your code.

.. tip::

Expand All @@ -105,7 +99,8 @@ You can also add the transformer, right when adding the field by changing the fo
slightly::

$builder->add(
$builder->create('description', 'textarea')
$builder
->create('tags', 'text')
->addModelTransformer(...)
);

Expand Down
19 changes: 12 additions & 7 deletions cookbook/form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ objects::

class Tag
{
public $name;
}
private $name;

.. tip::
public function getName()
{
return $this->name;
}

The ``name`` property is public here, but it can just as easily be protected
or private (but then it would need ``getName`` and ``setName`` methods).
public function setName($name)
{
$this->name = $name;
}
}

Then, create a form class so that a ``Tag`` object can be modified by the user::

Expand Down Expand Up @@ -162,10 +167,10 @@ In your controller, you'll now initialize a new instance of ``TaskType``::
// dummy code - this is here just so that the Task has some tags
// otherwise, this isn't an interesting example
$tag1 = new Tag();
$tag1->name = 'tag1';
$tag1->setName('tag1');
$task->getTags()->add($tag1);
$tag2 = new Tag();
$tag2->name = 'tag2';
$tag2->setName('tag2');
$task->getTags()->add($tag2);
// end dummy code

Expand Down
2 changes: 1 addition & 1 deletion cookbook/request/load_balancer_reverse_proxy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ In this case, you'll need to - *very carefully* - trust *all* proxies.
$response = $kernel->handle($request);
// ...

#. Ensure that the trusted_proxies setting in your ``app/config/config.yml``
#. Ensure that the trusted_proxies setting in your ``app/config/config.yml``
is not set or it will overwrite the ``setTrustedProxies`` call above.

That's it! It's critical that you prevent traffic from all non-trusted sources.
Expand Down
5 changes: 3 additions & 2 deletions create_framework/http_kernel_httpkernel_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ only if needed::
namespace Simplex;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class StringResponseListener implements EventSubscriberInterface
{
Expand All @@ -166,7 +167,7 @@ only if needed::

public static function getSubscribedEvents()
{
return array('kernel.view' => 'onView');
return array(KernelEvents::VIEW => 'onView');
}
}

Expand Down

0 comments on commit e29b7ab

Please sign in to comment.