Skip to content

Commit cbdf573

Browse files
committed
Merge branch '3.2'
* 3.2: (71 commits) Rewriting the service container docs Minor reword Adding a tip for validation in forms without class [#7217] add versionadded directives [#7203] merge note and versionadded directive Use the new configurator YAML syntax Added a note about the .htaccess files included by Symfony apps Made unmapped field example in forms chapter more descriptive [#7507] fix namespace [#7507] fix component name [#7490] minor typo fix Added a note about redirections to absolute URLs in tests [#7204] link to API doc Added docs for JsonResponse::fromJsonString Added the changes suggested by reviewers [#7620] use generate() in PHP templates before 2.8 Fixed the RST syntax Improve example context Minor formatting changes [#7519] some minor tweaks ...
2 parents 7006c48 + 1f12c74 commit cbdf573

31 files changed

+1010
-524
lines changed

_build/redirection_map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,4 @@
332332
/deployment/tools /deployment
333333
/install/bundles /setup/bundles
334334
/form /forms
335+
/testing/simulating_authentication /testing/http_authentication

bundles/configuration.rst

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,64 @@ This class can now be used in your ``load()`` method to merge configurations and
218218
force validation (e.g. if an additional option was passed, an exception will be
219219
thrown)::
220220

221+
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
222+
221223
public function load(array $configs, ContainerBuilder $container)
222224
{
223225
$configuration = new Configuration();
224226

225227
$config = $this->processConfiguration($configuration, $configs);
226-
// ...
228+
229+
// you now have these 2 config keys
230+
// $config['twitter']['client_id'] and $config['twitter']['client_secret']
227231
}
228232

229233
The ``processConfiguration()`` method uses the configuration tree you've defined
230234
in the ``Configuration`` class to validate, normalize and merge all the
231235
configuration arrays together.
232236

237+
Now, you can use the ``$config`` variable to modify a service provided by your bundle.
238+
For example, imagine your bundle has the following example config:
239+
240+
.. code-block:: xml
241+
242+
<!-- src/Acme/SocialBundle/Resources/config/services.xml -->
243+
<?xml version="1.0" encoding="UTF-8" ?>
244+
<container xmlns="http://symfony.com/schema/dic/services"
245+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
246+
xsi:schemaLocation="http://symfony.com/schema/dic/services
247+
http://symfony.com/schema/dic/services/services-1.0.xsd">
248+
249+
<services>
250+
<service id="acme.social.twitter_client" class="Acme\SocialBundle\TwitterClient">
251+
<argument></argument> <!-- will be filled in with client_id dynamically -->
252+
<argument></argument> <!-- will be filled in with client_secret dynamically -->
253+
</service>
254+
</services>
255+
</container>
256+
257+
In your extension, you can load this and dynamically set its arguments::
258+
259+
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
260+
// ...
261+
262+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
263+
use Symfony\Component\Config\FileLocator;
264+
265+
public function load(array $configs, ContainerBuilder $container)
266+
{
267+
$loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
268+
$loader->load('services.xml');
269+
270+
$configuration = new Configuration();
271+
$config = $this->processConfiguration($configuration, $configs);
272+
273+
$def = $container->getDefinition('acme.social.twitter_client');
274+
$def->replaceArgument(0, $config['twitter']['client_id']);
275+
$def->replaceArgument(1, $config['twitter']['client_secret']);
276+
}
277+
278+
233279
.. tip::
234280

235281
Instead of calling ``processConfiguration()`` in your extension each time you
@@ -253,9 +299,7 @@ configuration arrays together.
253299
}
254300

255301
This class uses the ``getConfiguration()`` method to get the Configuration
256-
instance. You should override it if your Configuration class is not called
257-
``Configuration`` or if it is not placed in the same namespace as the
258-
extension.
302+
instance.
259303

260304
.. sidebar:: Processing the Configuration yourself
261305

bundles/inheritance.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ The same goes for routing files and some other resources.
9393

9494
The overriding of resources only works when you refer to resources with
9595
the ``@FOSUserBundle/Resources/config/routing/security.xml`` method.
96-
If you refer to resources without using the ``@BundleName`` shortcut, they
97-
can't be overridden in this way.
96+
You need to use the ``@BundleName`` shortcut when referring to resources
97+
so they can be successfully overridden (except templates, which are
98+
overridden in a different way, as explained in :doc:`/templating/overriding`).
9899

99100
.. caution::
100101

bundles/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ version, include it as the second argument of the `composer require`_ command:
4848
B) Enable the Bundle
4949
--------------------
5050

51-
At this point, the bundle is installed in your Symfony project (in
51+
At this point, the bundle is installed in your Symfony project (e.g.
5252
``vendor/friendsofsymfony/``) and the autoloader recognizes its classes.
5353
The only thing you need to do now is register the bundle in ``AppKernel``::
5454

bundles/override.rst

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Services & Configuration
3939

4040
If you want to modify service definitions of another bundle, you can use a compiler
4141
pass to change the class of the service or to modify method calls. In the following
42-
example, the implementing class for the ``original-service-id`` is changed to
42+
example, the implementing class for the ``original-service-id`` is changed to
4343
``Acme\DemoBundle\YourService``::
4444

4545
// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
@@ -72,16 +72,8 @@ associations. Learn more about this feature and its limitations in
7272
Forms
7373
-----
7474

75-
Form types are referred to by their fully-qualified class name::
76-
77-
$builder->add('name', CustomType::class);
78-
79-
This means that you cannot override this by creating a sub-class of ``CustomType``
80-
and registering it as a service and tagging it with ``form.type`` (you *could*
81-
do this in earlier version).
82-
83-
Instead, you should use a "form type extension" to modify the existing form type.
84-
For more information, see :doc:`/form/create_form_type_extension`.
75+
Existing form types can be modified defining
76+
:doc:`form type extensions </form/create_form_type_extension>`.
8577

8678
.. _override-validation:
8779

@@ -92,7 +84,7 @@ Symfony loads all validation configuration files from every bundle and
9284
combines them into one validation metadata tree. This means you are able to
9385
add new constraints to a property, but you cannot override them.
9486

95-
To override this, the 3rd party bundle needs to have configuration for
87+
To overcome this, the 3rd party bundle needs to have configuration for
9688
:doc:`validation groups </validation/groups>`. For instance, the FOSUserBundle
9789
has this configuration. To create your own validation, add the constraints
9890
to a new validation group:

bundles/prepend_extension.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
single: Configuration; Semantic
33
single: Bundle; Extension configuration
44

5-
How to Simplify Configuration of multiple Bundles
5+
How to Simplify Configuration of Multiple Bundles
66
=================================================
77

88
When building reusable and extensible applications, developers are often
@@ -12,9 +12,9 @@ users to choose to remove functionality they are not using. Creating multiple
1212
bundles has the drawback that configuration becomes more tedious and settings
1313
often need to be repeated for various bundles.
1414

15-
Using the below approach, it is possible to remove the disadvantage of the
16-
multiple bundle approach by enabling a single Extension to prepend the settings
17-
for any bundle. It can use the settings defined in the ``app/config/config.yml``
15+
It is possible to remove the disadvantage of the multiple bundle approach
16+
by enabling a single Extension to prepend the settings for any bundle.
17+
It can use the settings defined in the ``app/config/config.yml``
1818
to prepend settings just as if they had been written explicitly by
1919
the user in the application configuration.
2020

components/http_foundation.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,23 @@ class, which can make this even easier::
562562

563563
use Symfony\Component\HttpFoundation\JsonResponse;
564564

565+
// if you know the data to send when creating the response
566+
$response = new JsonResponse(array('data' => 123));
567+
568+
// if you don't know the data to send when creating the response
565569
$response = new JsonResponse();
566-
$response->setData(array(
567-
'data' => 123
568-
));
570+
// ...
571+
$response->setData(array('data' => 123));
572+
573+
// if the data to send is already encoded in JSON
574+
$response = JsonResponse::fromJsonString('{ "data": 123 }');
575+
576+
.. versionadded:: 3.2
577+
The :method:`Symfony\\Component\\HttpFoundation\\JsonResponse::fromJsonString`
578+
method was added in Symfony 3.2.
569579

570-
This encodes your array of data to JSON and sets the ``Content-Type`` header
571-
to ``application/json``.
580+
The ``JsonResponse`` class sets the ``Content-Type`` header to
581+
``application/json`` and encodes your data to JSON when needed.
572582

573583
.. caution::
574584

components/phpunit_bridge.rst

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,25 @@ The :class:`Symfony\\Bridge\\PhpUnit\\ClockMock` class provided by this bridge
229229
allows you to mock the PHP's built-in time functions ``time()``,
230230
``microtime()``, ``sleep()`` and ``usleep()``.
231231

232-
To use the ``ClockMock`` class in your test, you can:
232+
To use the ``ClockMock`` class in your test, add the ``@group time-sensitive``
233+
annotation to its class or methods. This annotation only works when executing
234+
PHPUnit using the ``vendor/bin/simple-phpunit`` script or when registering the
235+
following listener in your PHPUnit configuration:
233236

234-
* (**Recommended**) Add the ``@group time-sensitive`` annotation to its class or
235-
method;
237+
.. code-block:: xml
238+
239+
<!-- phpunit.xml.dist -->
240+
<!-- ... -->
241+
<listeners>
242+
<listener class="\Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
243+
</listeners>
244+
245+
.. note::
236246

237-
* Register it manually by calling ``ClockMock::register(__CLASS__)`` and
238-
``ClockMock::withClockMock(true)`` before the test and
239-
``ClockMock::withClockMock(false)`` after the test.
247+
If you don't want to use the ``@group time-sensitive`` annotation, you can
248+
register the ``ClockMock`` class manually by calling
249+
``ClockMock::register(__CLASS__)`` and ``ClockMock::withClockMock(true)``
250+
before the test and ``ClockMock::withClockMock(false)`` after the test.
240251

241252
As a result, the following is guaranteed to work and is no longer a transient
242253
test::

components/var_dumper/advanced.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,102 @@ method. They also typically implement the
181181
them from re-implementing the logic required to walk through a
182182
:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object's internal structure.
183183

184+
The :class:`Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper` limits string
185+
length and nesting depth of the output to make it more readable. These options
186+
can be overriden by the third optional parameter of the
187+
:method:`dump(Data $data) <Symfony\\Component\\VarDumper\\Dumper\\DataDumperInterface::dump>`
188+
method::
189+
190+
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
191+
192+
$output = fopen('php://memory', 'r+b');
193+
194+
$dumper = new HtmlDumper();
195+
$dumper->dump($var, $output, array(
196+
// 1 and 160 are the default values for these options
197+
'maxDepth' => 1,
198+
'maxStringLength' => 160
199+
));
200+
201+
.. versionadded:: 3.2
202+
Support for passing display options to the ``dump()`` method was introduced
203+
in Symfony 3.2.
204+
205+
The output format of a dumper can be fine tuned by the two flags
206+
``DUMP_STRING_LENGTH`` and ``DUMP_LIGHT_ARRAY`` which are passed as a bitmap
207+
in the third constructor argument. They can also be set via environment
208+
variables when using
209+
:method:`assertDumpEquals($dump, $data, $message) <Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait::assertDumpEquals>`
210+
during unit testing.
211+
212+
.. versionadded:: 3.1
213+
The ``DUMP_STRING_LENGTH`` and ``DUMP_LIGHT_ARRAY`` flags were introduced
214+
in Symfony 3.1.
215+
216+
If ``DUMP_STRING_LENGTH`` is set, then the length of a string is displayed
217+
next to its content:
218+
219+
.. code-block:: php
220+
221+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
222+
use Symfony\Component\VarDumper\Dumper\CliDumper;
223+
224+
$var = array('test');
225+
$dumper = new CliDumper();
226+
echo $dumper->dump($var, true);
227+
228+
// array:1 [
229+
// 0 => "test"
230+
// ]
231+
232+
$dumper = new CliDumper(null, null, AbstractDumper::DUMP_STRING_LENGTH);
233+
echo $dumper->dump($var, true);
234+
235+
// (added string length before the string)
236+
// array:1 [
237+
// 0 => (4) "test"
238+
// ]
239+
240+
If ``DUMP_LIGHT_ARRAY`` is set, then arrays are dumped in a shortened format
241+
similar to PHP's short array notation:
242+
243+
.. code-block:: php
244+
245+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
246+
use Symfony\Component\VarDumper\Dumper\CliDumper;
247+
248+
$var = array('test');
249+
$dumper = new CliDumper();
250+
echo $dumper->dump($var, true);
251+
252+
// array:1 [
253+
// 0 => "test"
254+
// ]
255+
256+
$dumper = new CliDumper(null, null, AbstractDumper::DUMP_LIGHT_ARRAY);
257+
echo $dumper->dump($var, true);
258+
259+
// (no more array:1 prefix)
260+
// [
261+
// 0 => "test"
262+
// ]
263+
264+
If you would like to use both options, then you can just combine them by
265+
using a the logical OR operator ``|``:
266+
267+
.. code-block:: php
268+
269+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
270+
use Symfony\Component\VarDumper\Dumper\CliDumper;
271+
272+
$var = array('test');
273+
$dumper = new CliDumper(null, null, AbstractDumper::DUMP_STRING_LENGTH | AbstractDumper::DUMP_LIGHT_ARRAY);
274+
echo $dumper->dump($var, true);
275+
276+
// [
277+
// 0 => (4) "test"
278+
// ]
279+
184280
Casters
185281
-------
186282

console/coloring.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ You can also set these colors and options directly inside the tagname::
6868
// bold text with underscore
6969
$output->writeln('<options=bold,underscore>foo</>');
7070

71+
.. note::
72+
73+
If you need to render a tag literally, escape it with a backslash: ``\<info>``
74+
or use the :method:`Symfony\\Component\\Console\\Formatter\\OutputFormatter::escape`
75+
method to escape all the tags included in the given string.
76+
7177
.. _Cmder: http://cmder.net/
7278
.. _ConEmu: https://conemu.github.io/
7379
.. _ANSICON: https://github.com/adoxa/ansicon/releases

contributing/code/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Contributing Code
55
:maxdepth: 2
66

77
bugs
8+
reproducer
89
patches
910
maintenance
1011
core_team

0 commit comments

Comments
 (0)