Skip to content

Commit 1b47f37

Browse files
committed
Merge branch '3.2' into 3.3
* 3.2: Revert "[symfony#7939] revert some changes (revert them for 3.2)" [symfony#7939] revert some changes (revert them for 3.2) Minor reword Update twig_reference.rst [symfony#7958] fix minor typo improve examples of how we create test doubles Minor reword Add default indication in input arguments/options description Improved the explanation about deployment + parameters.yml Explained how to run tests in multiple kernel apps Fixed the explanation about PHPUnit event listeners in PHPUnitBridge fixed typo in choice.rst regarding choice_loader File example update [symfony#8003] add XML and PHP config examples Reworded the help note adding note that CSRF protection has to be enabled in config follow best practices for template files Added a note about disabling FastCGI buffering in Nginx Add some doc on missing options of framework bundle configuration Reworded the explanation about the --router option
2 parents a6fd9a4 + 412f112 commit 1b47f37

17 files changed

+201
-67
lines changed

components/http_foundation.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,12 @@ represented by a PHP callable instead of a string::
468468
you must call ``ob_flush()`` before ``flush()``.
469469

470470
Additionally, PHP isn't the only layer that can buffer output. Your web
471-
server might also buffer based on its configuration. What's more, if you
472-
use FastCGI, buffering can't be disabled at all.
471+
server might also buffer based on its configuration. Some servers, such as
472+
Nginx, let you disable buffering at config level or adding a special HTTP
473+
header in the response::
474+
475+
// disables FastCGI buffering in Nginx only for this response
476+
$response->headers->set('X-Accel-Buffering', 'no')
473477

474478
.. _component-http-foundation-serving-files:
475479

components/phpunit_bridge.rst

+25-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ to register a new `test listener`_ called ``SymfonyTestsListener``:
5656
Usage
5757
-----
5858

59-
Once the component is installed, it automatically registers a
60-
`PHPUnit event listener`_ which in turn registers a `PHP error handler`_
61-
called :class:`Symfony\\Bridge\\PhpUnit\\DeprecationErrorHandler`. After
62-
running your PHPUnit tests, you will get a report similar to this one:
59+
Once the component is installed, a ``simple-phpunit`` script is created in the
60+
``vendor/`` directory to run tests. This script wraps the original PHPUnit binary
61+
to provide more features:
62+
63+
.. code-block:: terminal
64+
65+
$ cd my-project/
66+
$ ./vendor/bin/simple-phpunit
67+
68+
After running your PHPUnit tests, you will get a report similar to this one:
6369

6470
.. image:: /_images/components/phpunit_bridge/report.png
6571

@@ -76,6 +82,21 @@ The summary includes:
7682
Deprecation notices are all other (non-legacy) notices, grouped by message,
7783
test class and method.
7884

85+
.. note::
86+
87+
If you don't want to use the ``simple-phpunit`` script, register the following
88+
`PHPUnit event listener`_ in your PHPUnit configuration file to get the same
89+
report about deprecations (which is created by a `PHP error handler`_
90+
called :class:`Symfony\\Bridge\\PhpUnit\\DeprecationErrorHandler`):
91+
92+
.. code-block:: xml
93+
94+
<!-- phpunit.xml.dist -->
95+
<!-- ... -->
96+
<listeners>
97+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
98+
</listeners>
99+
79100
Trigger Deprecation Notices
80101
---------------------------
81102

configuration/multiple_kernels.rst

+37
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,43 @@ In order to solve this issue, add the following configuration to your kernel:
178178
# allows to use app/Resources/views/ templates in the ApiKernel
179179
"%kernel.project_dir%/app/Resources/views": ~
180180
181+
Running Tests Using a Different Kernel
182+
--------------------------------------
183+
184+
In Symfony applications, functional tests extend by default from the
185+
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase` class. Inside that
186+
class, a method called ``getKernelClass()`` tries to find the class of the kernel
187+
to use to run the application during tests. The logic of this method does not
188+
support multiple kernel applications, so your tests won't use the right kernel.
189+
190+
The solution is to create a custom base class for functional tests extending
191+
from ``WebTestCase`` class and overriding the ``getKernelClass()`` method to
192+
return the fully qualified class name of the kernel to use::
193+
194+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
195+
196+
// tests needing the ApiKernel to work, now must extend this
197+
// ApiTestCase class instead of the default WebTestCase class
198+
class ApiTestCase extends WebTestCase
199+
{
200+
protected static function getKernelClass()
201+
{
202+
return 'ApiKernel';
203+
}
204+
205+
// this is needed because the KernelTestCase class keeps a reference to
206+
// the previously created kernel in its static $kernel property. Thus,
207+
// if your functional tests do not run in isolated processes, a later run
208+
// test for a different kernel will reuse the previously created instance,
209+
// which points to a different kernel
210+
protected function tearDown()
211+
{
212+
parent::tearDown();
213+
214+
static::$class = null;
215+
}
216+
}
217+
181218
Adding more Kernels to the Application
182219
--------------------------------------
183220

console/input.rst

+8-3
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ There are three argument variants you can use:
9191
provided;
9292

9393
``InputArgument::OPTIONAL``
94-
The argument is optional and therefore can be omitted;
94+
The argument is optional and therefore can be omitted. This is the default
95+
behavior of arguments;
9596

9697
``InputArgument::IS_ARRAY``
9798
The argument can contain any number of values. For that reason, it must be
98-
used at the end of the argument list
99+
used at the end of the argument list.
99100

100101
You can combine ``IS_ARRAY`` with ``REQUIRED`` and ``OPTIONAL`` like this::
101102

@@ -177,11 +178,15 @@ There are four option variants you can use:
177178

178179
``InputOption::VALUE_IS_ARRAY``
179180
This option accepts multiple values (e.g. ``--dir=/foo --dir=/bar``);
181+
180182
``InputOption::VALUE_NONE``
181-
Do not accept input for this option (e.g. ``--yell``);
183+
Do not accept input for this option (e.g. ``--yell``). This is the default
184+
behavior of options;
185+
182186
``InputOption::VALUE_REQUIRED``
183187
This value is required (e.g. ``--iterations=5``), the option itself is
184188
still optional;
189+
185190
``InputOption::VALUE_OPTIONAL``
186191
This option may or may not have a value (e.g. ``--yell`` or
187192
``--yell=loud``).

controller/service.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ service and use it directly::
111111

112112
public function indexAction($name)
113113
{
114-
$content = $this->twig->renderResponse(
114+
$content = $this->twig->render(
115115
'hello/index.html.twig',
116116
array('name' => $name)
117117
);

deployment.rst

+13-4
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,20 @@ Check if your server meets the requirements by running:
120120
121121
$ php bin/symfony_requirements
122122
123-
B) Configure your ``app/config/parameters.yml`` File
124-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123+
.. _b-configure-your-app-config-parameters-yml-file:
125124

126-
This file should *not* be deployed, but managed through the automatic utilities
127-
provided by Symfony.
125+
B) Configure your Parameters File
126+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127+
128+
Most Symfony applications define configuration parameters in a file called
129+
``app/config/parameters.yml``. This file should *not* be deployed, because
130+
Symfony generates it automatically using the ``app/config/parameters.yml.dist``
131+
file as a template (that's why ``parameters.yml.dist`` must be committed and
132+
deployed).
133+
134+
If your application uses environment variables instead of these parameters, you
135+
must define those env vars in your production server using the tools provided by
136+
your hosting service.
128137

129138
C) Install/Update your Vendors
130139
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

form/dynamic_form_modification.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ your application. Assume that you have a sport meetup creation controller::
528528
}
529529

530530
return $this->render(
531-
'@App/Meetup/create.html.twig',
531+
'meetup/create.html.twig',
532532
array('form' => $form->createView())
533533
);
534534
}
@@ -543,7 +543,7 @@ field according to the current selection in the ``sport`` field:
543543

544544
.. code-block:: html+twig
545545

546-
{# app/Resources/views/Meetup/create.html.twig #}
546+
{# app/Resources/views/meetup/create.html.twig #}
547547
{{ form_start(form) }}
548548
{{ form_row(form.sport) }} {# <select id="meetup_sport" ... #}
549549
{{ form_row(form.position) }} {# <select id="meetup_position" ... #}

form/form_collections.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ In your controller, you'll create a new form from the ``TaskType``::
177177
// ... maybe do some form processing, like saving the Task and Tag objects
178178
}
179179

180-
return $this->render('@App/Task/new.html.twig', array(
180+
return $this->render('task/new.html.twig', array(
181181
'form' => $form->createView(),
182182
));
183183
}
@@ -193,7 +193,7 @@ zero tags when first created).
193193

194194
.. code-block:: html+twig
195195

196-
{# src/AppBundle/Resources/views/Task/new.html.twig #}
196+
{# app/Resources/views/task/new.html.twig #}
197197

198198
{# ... #}
199199

profiler/data_collector.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ block and set the value of two variables called ``icon`` and ``text``:
161161

162162
.. code-block:: twig
163163
164-
{{ include('@App/data_collector/icon.svg') }}
164+
{{ include('data_collector/icon.svg') }}
165165
166166
You are encouraged to use the latter technique for your own toolbar panels.
167167

reference/configuration/framework.rst

+26
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ Configuration
6363
* `gc_divisor`_
6464
* `gc_probability`_
6565
* `gc_maxlifetime`_
66+
* `use_strict_mode`_
6667
* `save_path`_
68+
* `metadata_update_threshold`_
6769
* `assets`_
6870
* `base_path`_
6971
* `base_urls`_
@@ -766,6 +768,17 @@ This determines the number of seconds after which data will be seen as "garbage"
766768
and potentially cleaned up. Garbage collection may occur during session
767769
start and depends on `gc_divisor`_ and `gc_probability`_.
768770

771+
use_strict_mode
772+
...............
773+
774+
**type**: ``boolean`` **default**: ``false``
775+
776+
This specifies whether the session module will use the strict session id mode.
777+
If this mode is enabled, the module does not accept uninitialized session IDs.
778+
If an uninitialized session ID is sent from browser, a new session ID is sent
779+
to browser. Applications are protected from session fixation via session
780+
adoption with strict mode.
781+
769782
save_path
770783
.........
771784

@@ -812,6 +825,19 @@ setting the value to ``null``:
812825
),
813826
));
814827
828+
metadata_update_threshold
829+
.........................
830+
831+
**type**: ``integer`` **default**: ``0``
832+
833+
This is how many seconds to wait between two session metadata updates. It will
834+
also prevent the session handler to write if the session has not changed.
835+
836+
.. seealso::
837+
838+
You can see an example of the usage of this in
839+
:doc:`/session/limit_metadata_writes`.
840+
815841
assets
816842
~~~~~~
817843

reference/configuration/twig.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ TwigBundle Configuration ("twig")
2525
- foundation_5_layout.html.twig
2626
2727
# Example:
28-
- @App/form.html.twig
28+
- form.html.twig
2929
3030
globals:
3131
@@ -77,7 +77,7 @@ TwigBundle Configuration ("twig")
7777
optimizations="true"
7878
>
7979
<twig:form-theme>form_div_layout.html.twig</twig:form-theme> <!-- Default -->
80-
<twig:form-theme>@App/form.html.twig</twig:form-theme>
80+
<twig:form-theme>form.html.twig</twig:form-theme>
8181
8282
<twig:global key="foo" id="bar" type="service" />
8383
<twig:global key="pi">3.14</twig:global>
@@ -93,7 +93,7 @@ TwigBundle Configuration ("twig")
9393
$container->loadFromExtension('twig', array(
9494
'form_themes' => array(
9595
'form_div_layout.html.twig', // Default
96-
'@App/form.html.twig',
96+
'form.html.twig',
9797
),
9898
'globals' => array(
9999
'foo' => '@bar',

reference/forms/types/choice.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ if you want to take advantage of lazy loading::
198198
$builder->add('constants', ChoiceType::class, array(
199199
'choice_loader' => new CallbackChoiceLoader(function() {
200200
return StaticClass::getConstants();
201-
},
201+
}),
202202
));
203203

204204
This will cause the call of ``StaticClass::getConstants()`` to not happen if the

reference/forms/types/file.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ be used to move the ``attachment`` file to a permanent location::
5252
if ($form->isSubmitted() && $form->isValid()) {
5353
$someNewFilename = ...
5454

55-
$form['attachment']->getData()->move($dir, $someNewFilename);
55+
$file = $form['attachment']->getData();
56+
$file->move($dir, $someNewFilename);
5657

5758
// ...
5859
}

reference/twig_reference.rst

+12-6
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,18 @@ file_excerpt
569569

570570
.. code-block:: twig
571571
572-
{{ file|file_excerpt(line = null) }}
572+
{{ file|file_excerpt(line, srcContext = 3) }}
573573
574574
``file``
575575
**type**: ``string``
576-
``line`` *(optional)*
576+
``line``
577+
**type**: ``integer``
578+
``srcContext`` *(optional)*
577579
**type**: ``integer``
578580

579-
Generates an excerpt of seven lines around the given ``line``.
581+
Generates an excerpt of a code file around the given ``line`` number. The
582+
``srcContext`` argument defines the total number of lines to display around the
583+
given line number (use ``-1`` to display the whole file).
580584

581585
format_file
582586
~~~~~~~~~~~
@@ -613,12 +617,14 @@ file_link
613617

614618
.. code-block:: twig
615619
616-
{{ file|file_link(line = null) }}
620+
{{ file|file_link(line) }}
617621
618-
``line`` *(optional)*
622+
``file``
623+
**type**: ``string``
624+
``line``
619625
**type**: ``integer``
620626

621-
Generates a link to the provided file (and optionally line number) using
627+
Generates a link to the provided file and line number using
622628
a preconfigured scheme.
623629

624630
.. _reference-twig-tags:

security/csrf_in_login_form.rst

+38-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,44 @@ for CSRF. In this article you'll learn how you can use it in your login form.
1616
Configuring CSRF Protection
1717
---------------------------
1818

19-
First, configure the Security component so it can use CSRF protection.
20-
The Security component needs a CSRF token provider. You can set this to use the default
21-
provider available in the Security component:
19+
First, make sure that the CSRF protection is enabled in the main cofiguration
20+
file:
21+
22+
.. configuration-block::
23+
24+
.. code-block:: yaml
25+
26+
# app/config/config.yml
27+
framework:
28+
# ...
29+
csrf_protection: ~
30+
31+
.. code-block:: xml
32+
33+
<!-- app/config/config.xml -->
34+
<?xml version="1.0" encoding="UTF-8" ?>
35+
<container xmlns="http://symfony.com/schema/dic/services"
36+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
37+
xmlns:framework="http://symfony.com/schema/dic/symfony"
38+
xsi:schemaLocation="http://symfony.com/schema/dic/services
39+
http://symfony.com/schema/dic/services/services-1.0.xsd
40+
http://symfony.com/schema/dic/symfony
41+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
42+
43+
<framework:config>
44+
<framework:csrf-protection enabled="true" />
45+
</framework:config>
46+
</container>
47+
48+
.. code-block:: php
49+
50+
// app/config/config.php
51+
$container->loadFromExtension('framework', array(
52+
'csrf_protection' => null,
53+
));
54+
55+
Then, the security component needs a CSRF token provider. You can set this to
56+
use the default provider available in the security component:
2257

2358
.. configuration-block::
2459

0 commit comments

Comments
 (0)