Skip to content

Commit bbdaba0

Browse files
committed
Merge branch '2.8' into 3.0
2 parents c4ebee2 + daaa466 commit bbdaba0

File tree

10 files changed

+58
-68
lines changed

10 files changed

+58
-68
lines changed

book/http_cache.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,11 +1198,6 @@ One great advantage of the ESI renderer is that you can make your application
11981198
as dynamic as needed and at the same time, hit the application as little as
11991199
possible.
12001200

1201-
.. tip::
1202-
1203-
The listener only responds to local IP addresses or
1204-
:doc:`trusted proxies </cookbook/request/load_balancer_reverse_proxy>`.
1205-
12061201
.. note::
12071202

12081203
Once you start using ESI, remember to always use the ``s-maxage``

components/event_dispatcher/container_aware_dispatcher.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ and the second argument is the service's class name (which must implement
6868
The ``EventSubscriberInterface`` is exactly as you would expect::
6969

7070
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
71+
use Symfony\Component\HttpKernel\KernelEvents;
7172
// ...
7273

7374
class StoreSubscriber implements EventSubscriberInterface
7475
{
7576
public static function getSubscribedEvents()
7677
{
7778
return array(
78-
'kernel.response' => array(
79+
KernelEvents::RESPONSE => array(
7980
array('onKernelResponsePre', 10),
8081
array('onKernelResponsePost', 0),
8182
),

components/form/introduction.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,12 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
199199
)));
200200
$formEngine = new TwigRendererEngine(array($defaultFormTheme));
201201
$formEngine->setEnvironment($twig);
202+
203+
// ... (see the previous CSRF Protection section for more information)
204+
202205
// add the FormExtension to Twig
203206
$twig->addExtension(
204-
new FormExtension(new TwigRenderer($formEngine, $csrfProvider))
207+
new FormExtension(new TwigRenderer($formEngine, $csrfManager))
205208
);
206209

207210
// create your form factory as normal

cookbook/bundles/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ can place it anywhere you like. You should return this path as the base path::
373373
}
374374
}
375375

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

379379
.. code-block:: xml

cookbook/composer.rst

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,24 @@ following sections.
1414
Install Composer on Linux and Mac OS X
1515
--------------------------------------
1616

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

19-
.. code-block:: bash
20+
.. code-block:: bash
2021
21-
$ curl -sS https://getcomposer.org/installer | php
22-
$ sudo mv composer.phar /usr/local/bin/composer
23-
24-
.. note::
25-
26-
If you don't have ``curl`` installed, you can also just download the
27-
``installer`` file manually at https://getcomposer.org/installer and
28-
then run:
29-
30-
.. code-block:: bash
31-
32-
$ php installer
33-
$ sudo mv composer.phar /usr/local/bin/composer
22+
$ sudo mv composer.phar /usr/local/bin/composer
3423
3524
Install Composer on Windows
3625
---------------------------
3726

38-
Download the installer from `getcomposer.org/download`_, execute it and follow
39-
the instructions.
27+
Download the installer from `getcomposer.org`_, execute it and follow the instructions.
4028

4129
Learn more
4230
----------
4331

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

4634
.. _`Composer`: https://getcomposer.org/
47-
.. _`getcomposer.org/download`: https://getcomposer.org/download
4835
.. _`Composer documentation`: https://getcomposer.org/doc/00-intro.md
36+
.. _`getcomposer.org`: https://getcomposer.org/Composer-Setup.exe
37+
.. _the official Composer documentation: https://getcomposer.org/download

cookbook/event_dispatcher/event_listener.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,15 @@ listen to the same ``kernel.exception`` event::
142142

143143
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
144144
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
145+
use Symfony\Component\HttpKernel\KernelEvents;
145146

146147
class ExceptionSubscriber implements EventSubscriberInterface
147148
{
148149
public static function getSubscribedEvents()
149150
{
150151
// return the subscribed events, their methods and priorities
151152
return array(
152-
'kernel.exception' => array(
153+
KernelEvents::EXCEPTION => array(
153154
array('processException', 10),
154155
array('logException', 0),
155156
array('notifyException', -10),

cookbook/form/data_transformers.rst

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@ to render the form, and then back into a ``DateTime`` object on submit.
1616
When a form field has the ``inherit_data`` option set, Data Transformers
1717
won't be applied to that field.
1818

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

22-
Suppose you have a Task form with a description ``textarea`` type::
21+
Simple Example: Transforming String Tags from User Input to an Array
22+
--------------------------------------------------------------------
23+
24+
Suppose you have a Task form with a tags ``text`` type::
2325

2426
// src/AppBundle/Form/TaskType.php
2527
namespace AppBundle\Form\Type;
2628

2729
use Symfony\Component\Form\FormBuilderInterface;
2830
use Symfony\Component\OptionsResolver\OptionsResolver;
29-
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
31+
use Symfony\Component\Form\Extension\Core\Type\TextType;
3032

3133
// ...
3234
class TaskType extends AbstractType
3335
{
3436
public function buildForm(FormBuilderInterface $builder, array $options)
3537
{
36-
$builder->add('description', TextareaType::class);
38+
$builder->add('tags', TextType::class)
3739
}
3840

3941
public function configureOptions(OptionsResolver $resolver)
@@ -46,15 +48,10 @@ Suppose you have a Task form with a description ``textarea`` type::
4648
// ...
4749
}
4850

49-
But, there are two complications:
50-
51-
#. Your users are allowed to use *some* HTML tags, but not others: you need a way
52-
to call :phpfunction:`strip_tags` after the form is submitted;
53-
54-
#. To be friendly, you want to convert ``<br/>`` tags into line breaks (``\n``) before
55-
rendering the field so the text is easier to edit.
51+
Internally the ``tags`` are stored as an array, but displayed to the user as a
52+
simple comma seperated string to make them easier to edit.
5653

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

@@ -63,27 +60,24 @@ class::
6360

6461
use Symfony\Component\Form\CallbackTransformer;
6562
use Symfony\Component\Form\FormBuilderInterface;
66-
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
63+
use Symfony\Component\Form\Extension\Core\Type\TextType;
6764
// ...
6865

6966
class TaskType extends AbstractType
7067
{
7168
public function buildForm(FormBuilderInterface $builder, array $options)
7269
{
73-
$builder->add('description', TextareaType::class);
70+
$builder->add('tags', TextType::class);
7471

75-
$builder->get('description')
72+
$builder->get('tags')
7673
->addModelTransformer(new CallbackTransformer(
77-
// transform <br/> to \n so the textarea reads easier
78-
function ($originalDescription) {
79-
return preg_replace('#<br\s*/?>#i', "\n", $originalDescription);
74+
function ($tagsAsArray) {
75+
// transform the array to a string
76+
return implode(', ', $tagsAsArray);
8077
},
81-
function ($submittedDescription) {
82-
// remove most HTML tags (but not br,p)
83-
$cleaned = strip_tags($submittedDescription, '<br><br/><p>');
84-
85-
// transform any \n to real <br/>
86-
return str_replace("\n", '<br/>', $cleaned);
78+
function ($tagsAsString) {
79+
// transform the string back to an array
80+
return explode(', ', $tagsAsString);
8781
}
8882
))
8983
;
@@ -92,10 +86,10 @@ class::
9286
// ...
9387
}
9488

95-
The ``CallbackTransformer`` takes two callback functions as arguments. The first transforms
96-
the original value into a format that'll be used to render the field. The second
97-
does the reverse: it transforms the submitted value back into the format you'll use
98-
in your code.
89+
The ``CallbackTransformer`` takes two callback functions as arguments. The
90+
first transforms the original value into a format that'll be used to render the
91+
field. The second does the reverse: it transforms the submitted value back into
92+
the format you'll use in your code.
9993

10094
.. tip::
10195

@@ -106,10 +100,11 @@ in your code.
106100
You can also add the transformer, right when adding the field by changing the format
107101
slightly::
108102

109-
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
103+
use Symfony\Component\Form\Extension\Core\Type\TextType;
110104

111105
$builder->add(
112-
$builder->create('description', TextareaType::class)
106+
$builder
107+
->create('tags', TextType::class)
113108
->addModelTransformer(...)
114109
);
115110

cookbook/form/form_collections.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ objects::
6969

7070
class Tag
7171
{
72-
public $name;
73-
}
72+
private $name;
7473

75-
.. tip::
74+
public function getName()
75+
{
76+
return $this->name;
77+
}
7678

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

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

@@ -155,10 +160,10 @@ In your controller, you'll create a new form from the ``TaskType``::
155160
// dummy code - this is here just so that the Task has some tags
156161
// otherwise, this isn't an interesting example
157162
$tag1 = new Tag();
158-
$tag1->name = 'tag1';
163+
$tag1->setName('tag1');
159164
$task->getTags()->add($tag1);
160165
$tag2 = new Tag();
161-
$tag2->name = 'tag2';
166+
$tag2->setName('tag2');
162167
$task->getTags()->add($tag2);
163168
// end dummy code
164169

cookbook/request/load_balancer_reverse_proxy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ In this case, you'll need to - *very carefully* - trust *all* proxies.
8989
$response = $kernel->handle($request);
9090
// ...
9191

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

9595
That's it! It's critical that you prevent traffic from all non-trusted sources.

create_framework/http_kernel_httpkernel_class.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ only if needed::
151151
namespace Simplex;
152152

153153
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
154-
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
155154
use Symfony\Component\HttpFoundation\Response;
155+
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
156+
use Symfony\Component\HttpKernel\KernelEvents;
156157

157158
class StringResponseListener implements EventSubscriberInterface
158159
{
@@ -167,7 +168,7 @@ only if needed::
167168

168169
public static function getSubscribedEvents()
169170
{
170-
return array('kernel.view' => 'onView');
171+
return array(KernelEvents::VIEW => 'onView');
171172
}
172173
}
173174

0 commit comments

Comments
 (0)