Skip to content

Commit 184f8dc

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: Update formatterhelper.rst Fix a code example [Logger] Switching to more modern config format [Form] Fix wrong return type for choice_loader
2 parents c04a3b3 + 47fdf40 commit 184f8dc

File tree

3 files changed

+54
-35
lines changed

3 files changed

+54
-35
lines changed

components/console/helpers/formatterhelper.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,15 @@ precision (default ``1``) of the result::
132132
Helper::formatTime(125); // 2 mins
133133
Helper::formatTime(125, 2); // 2 mins, 5 secs
134134
Helper::formatTime(172799, 4); // 1 day, 23 hrs, 59 mins, 59 secs
135+
136+
Formatting Memory
137+
-----------------
138+
139+
Sometimes you want to format memory to GiB, MiB, KiB and B. This is possible with the
140+
:method:`Symfony\\Component\\Console\\Helper\\Helper::formatMemory` method.
141+
The only argument is the memory size to format::
142+
143+
Helper::formatMemory(512); // 512 B
144+
Helper::formatMemory(1024); // 1 KiB
145+
Helper::formatMemory(1024 * 1024); // 1.0 MiB
146+
Helper::formatMemory(1024 * 1024 * 1024); // 1 GiB

logging/channels_handlers.rst

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ Switching a Channel to a different Handler
2323
Now, suppose you want to log the ``security`` channel to a different file.
2424
To do this, create a new handler and configure it to log only messages
2525
from the ``security`` channel. The following example does that only in the
26-
``prod`` :ref:`configuration environment <configuration-environments>` but you
27-
can do it in any (or all) environments:
26+
``prod`` :ref:`configuration environment <configuration-environments>`:
2827

2928
.. configuration-block::
3029

3130
.. code-block:: yaml
3231
33-
# config/packages/prod/monolog.yaml
34-
monolog:
35-
handlers:
36-
security:
37-
# log all messages (since debug is the lowest level)
38-
level: debug
39-
type: stream
40-
path: '%kernel.logs_dir%/security.log'
41-
channels: [security]
42-
43-
# an example of *not* logging security channel messages for this handler
44-
main:
45-
# ...
46-
# channels: ['!security']
32+
# config/packages/monolog.yaml
33+
when@prod:
34+
monolog:
35+
handlers:
36+
security:
37+
# log all messages (since debug is the lowest level)
38+
level: debug
39+
type: stream
40+
path: '%kernel.logs_dir%/security.log'
41+
channels: [security]
42+
43+
# an example of *not* logging security channel messages for this handler
44+
main:
45+
# ...
46+
# channels: ['!security']
4747
4848
.. code-block:: xml
4949
@@ -56,12 +56,15 @@ can do it in any (or all) environments:
5656
http://symfony.com/schema/dic/monolog
5757
https://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
5858
59-
<monolog:config>
60-
<monolog:handler name="security" type="stream" path="%kernel.logs_dir%/security.log">
61-
<monolog:channels>
62-
<monolog:channel>security</monolog:channel>
63-
</monolog:channels>
64-
</monolog:handler>
59+
<when env="prod">
60+
<monolog:config>
61+
<monolog:handler name="security" type="stream" path="%kernel.logs_dir%/security.log">
62+
<monolog:channels>
63+
<monolog:channel>security</monolog:channel>
64+
</monolog:channels>
65+
</monolog:handler>
66+
</monolog:config>
67+
</when>
6568
6669
<monolog:handler name="main" type="stream" path="%kernel.logs_dir%/main.log">
6770
<!-- ... -->
@@ -75,18 +78,21 @@ can do it in any (or all) environments:
7578
.. code-block:: php
7679
7780
// config/packages/prod/monolog.php
81+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
7882
use Symfony\Config\MonologConfig;
7983
80-
return static function (MonologConfig $monolog): void {
81-
$monolog->handler('security')
82-
->type('stream')
83-
->path('%kernel.logs_dir%/security.log')
84-
->channels()->elements(['security']);
84+
return static function (MonologConfig $monolog, ContainerConfigurator $container) {
85+
if ('prod' === $container->env()) {
86+
$monolog->handler('security')
87+
->type('stream')
88+
->path(param('kernel.logs_dir') . \DIRECTORY_SEPARATOR . 'security.log')
89+
->channels()->elements(['security']);
8590
86-
$monolog->handler('main')
87-
// ...
91+
$monolog->handler('main')
92+
// ...
8893
89-
->channels()->elements(['!security']);
94+
->channels()->elements(['!security']);
95+
}
9096
};
9197
9298
.. caution::
@@ -131,13 +137,13 @@ You can also configure additional channels without the need to tag your services
131137

132138
.. code-block:: yaml
133139
134-
# config/packages/prod/monolog.yaml
140+
# config/packages/monolog.yaml
135141
monolog:
136142
channels: ['foo', 'bar', 'foo_bar']
137143
138144
.. code-block:: xml
139145
140-
<!-- config/packages/prod/monolog.xml -->
146+
<!-- config/packages/monolog.xml -->
141147
<container xmlns="http://symfony.com/schema/dic/services"
142148
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
143149
xmlns:monolog="http://symfony.com/schema/dic/monolog"
@@ -155,7 +161,7 @@ You can also configure additional channels without the need to tag your services
155161
156162
.. code-block:: php
157163
158-
// config/packages/prod/monolog.php
164+
// config/packages/monolog.php
159165
use Symfony\Config\MonologConfig;
160166
161167
return static function (MonologConfig $monolog): void {

reference/forms/types/options/choice_loader.rst.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ better performance::
4646
use App\StaticClass;
4747
use Symfony\Component\Form\AbstractType;
4848
use Symfony\Component\Form\ChoiceList\ChoiceList;
49+
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
4950
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
5051
use Symfony\Component\OptionsResolver\Options;
5152
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -61,13 +62,13 @@ better performance::
6162
{
6263
$resolver->setDefaults([
6364
// the example below will create a CallbackChoiceLoader from the callable
64-
'choice_loader' => ChoiceList::lazy($this, function() {
65+
'choice_loader' => ChoiceList::lazy($this, function () {
6566
return StaticClass::getConstants();
6667
}),
6768

6869
// you can pass your own loader as well, depending on other options
6970
'some_key' => null,
70-
'choice_loader' => function (Options $options): array {
71+
'choice_loader' => function (Options $options): ChoiceLoaderInterface {
7172
return ChoiceList::loader(
7273
// pass the instance of the type or type extension which is
7374
// currently configuring the choice list as first argument

0 commit comments

Comments
 (0)