From 02f31ac96e9a079e2305188423b64475c6b3be79 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Mon, 14 Aug 2017 11:38:08 +0100 Subject: [PATCH 0001/7665] [Translation] create custom message formatter. --- components/translation.rst | 3 +- .../translation/custom_message_formatter.rst | 55 +++++++++++++++++++ reference/configuration/framework.rst | 15 +++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 components/translation/custom_message_formatter.rst diff --git a/components/translation.rst b/components/translation.rst index dfbf9fd6259..30b69797414 100644 --- a/components/translation.rst +++ b/components/translation.rst @@ -34,9 +34,8 @@ The constructor of the ``Translator`` class needs one argument: The locale. .. code-block:: php use Symfony\Component\Translation\Translator; - use Symfony\Component\Translation\MessageSelector; - $translator = new Translator('fr_FR', new MessageSelector()); + $translator = new Translator('fr_FR'); .. note:: diff --git a/components/translation/custom_message_formatter.rst b/components/translation/custom_message_formatter.rst new file mode 100644 index 00000000000..22a650ea23c --- /dev/null +++ b/components/translation/custom_message_formatter.rst @@ -0,0 +1,55 @@ +.. index:: + single: Translation; Create Custom Message formatter + +Create Custom Message Formatter +=============================== + +The default Message Formatter provide a simple and easy way that deals with the most common use-cases +such as message placeholders and pluralization. But in some cases, you may want to use a custom message formatter +that fit to your specific needs, for example, handle nested conditions of pluralization or select sub-messages +via a fixed set of keywords (e.g. gender). + +Suppose in your application you want to displays different text depending on arbitrary conditions, +for example upon whether the guest is male or female. To do this, we will use the `ICU Message Format`_ +which the most suitable ones you first need to create a `IntlMessageFormatter` and pass it to the `Translator`. + +.. _components-translation-message-formatter: + +Creating a Custom Message Formatter +----------------------------------- + +To define a custom message formatter that is able to read these kinds of rules, you must create a +new class that implements the +:class:`Symfony\\Component\\Translation\\Formatter\\MessageFormatterInterface`:: + + use Symfony\Component\Translation\Formatter\MessageFormatterInterface; + + class IntlMessageFormatter implements MessageFormatterInterface + { + public function format($message, $locale, array $parameters = array()) + { + $formatter = new \MessageFormatter($locale, $message); + if (null === $formatter) { + throw new \InvalidArgumentException(sprintf('Invalid message format. Reason: %s (error #%d)', intl_get_error_message(), intl_get_error_code())); + } + + $message = $formatter->format($parameters); + if ($formatter->getErrorCode() !== U_ZERO_ERROR) { + throw new \InvalidArgumentException(sprintf('Unable to format message. Reason: %s (error #%s)', $formatter->getErrorMessage(), $formatter->getErrorCode())); + } + + return $message; + } + } + +Once created, simply pass it as the second argument to the `Translator`:: + + use Symfony\Component\Translation\Translator; + + $translator = new Translator('fr_FR', new IntlMessageFormatter()); + + var_dump($translator->trans('The guest is {gender, select, m {male} f {female}}', [ 'gender' => 'm' ])); + +It will print *"The guest is male"*. + +.. _`ICU Message Format`: http://userguide.icu-project.org/formatparse/messages diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 50c5ac2cde0..5cc0aa04b4d 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -85,6 +85,7 @@ Configuration * :ref:`enabled ` * `fallbacks`_ * `logging`_ + * `formatter`_ * :ref:`paths ` * `property_access`_ * `magic_call`_ @@ -1481,6 +1482,20 @@ for a given key. The logs are made to the ``translation`` channel and at the ``debug`` for level for keys where there is a translation in the fallback locale and the ``warning`` level if there is no translation to use at all. +.. _reference-framework-translator-formatter: + +formatter +......... + +**type**: ``string`` **default**: ``translator.formatter.default`` + +The service that is used to format message. The service +has to implement the :class:`Symfony\\Component\\Translation\\Formatter\\MessageFormatterInterface`. + +.. seealso:: + + For more details, see :doc:`/components/translation/custom_message_formatter`. + .. _reference-translator-paths: paths From dc91bfd7dfd8d61a053e01bbafe69286e3e880c4 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Fri, 19 Apr 2019 19:59:08 +0300 Subject: [PATCH 0002/7665] #21571 updated "Authentication Success and Failure Events" section --- components/security/authentication.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/security/authentication.rst b/components/security/authentication.rst index 9430808c825..ddf2ec3b993 100644 --- a/components/security/authentication.rst +++ b/components/security/authentication.rst @@ -289,9 +289,9 @@ Authentication Success and Failure Events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When a provider authenticates the user, a ``security.authentication.success`` -event is dispatched. But beware - this event will fire, for example, on *every* -request if you have session-based authentication. See ``security.interactive_login`` -below if you need to do something when a user *actually* logs in. +event is dispatched. But beware - this event may fire, for example, on *every* +request if you have session-based authentication, if ``always_authenticate_before_granting`` is enabled or if token is not authenticated before AccessListener is invoked. +See ``security.interactive_login`` below if you need to do something when a user *actually* logs in. When a provider attempts authentication but fails (i.e. throws an ``AuthenticationException``), a ``security.authentication.failure`` event is dispatched. You could listen on From d0161b468386be35db3947fba83961300ca75161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berislav=20Balogovi=C4=87?= Date: Mon, 22 Apr 2019 22:20:01 +0200 Subject: [PATCH 0003/7665] Extend framework lock configuration reference --- components/lock.rst | 2 + reference/configuration/framework.rst | 132 +++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 2 deletions(-) diff --git a/components/lock.rst b/components/lock.rst index 529696e082c..08c5177dfa0 100644 --- a/components/lock.rst +++ b/components/lock.rst @@ -69,6 +69,8 @@ method can be safely called repeatedly, even if the lock is already acquired. across several requests. To disable the automatic release behavior, set the third argument of the ``createLock()`` method to ``false``. +.. _lock-blocking-locks: + Blocking Locks -------------- diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index de74aedfc8c..60fadc0b0d8 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -87,6 +87,12 @@ Configuration * `http_method_override`_ * `ide`_ * :ref:`lock ` + + * :ref:`enabled ` + * :ref:`resources ` + + * :ref:`name ` + * `php_errors`_ * `log`_ @@ -164,7 +170,7 @@ Configuration * `engines`_ * :ref:`form ` - * `resources`_ + * :ref:`resources ` * `hinclude_default_template`_ * `loaders`_ @@ -1518,6 +1524,8 @@ is disabled. This can be either a template name or the content itself. form .... +.. _reference-templating-form-resources: + resources """"""""" @@ -2175,11 +2183,131 @@ example, when warming caches offline). lock ~~~~ -**type**: ``string`` +**type**: ``string`` | ``array`` The default lock adapter. If not defined, the value is set to ``semaphore`` when available, or to ``flock`` otherwise. Store's DSN are also allowed. +.. _reference-lock-enabled: + +enabled +....... + +**type**: ``boolean`` **default**: ``true`` + +Whether to enable the support for lock or not. This setting is +automatically set to ``true`` when one of the child settings is configured. + +.. _reference-lock-resources: + +resources +......... + +**type**: ``array`` + +A list of lock stores to be created by the framework extension. + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + # these are all the supported lock stores + lock: ~ + lock: 'flock' + lock: 'semaphore' + lock: 'memcached://m1.docker' + lock: ['memcached://m1.docker', 'memcached://m2.docker'] + lock: 'redis://r1.docker' + lock: ['redis://r1.docker', 'redis://r2.docker'] + lock: '%env(MEMCACHED_OR_REDIS_URL)%' + + # named locks + lock: + invoice: ['redis://r1.docker', 'redis://r2.docker'] + report: 'semaphore' + + .. code-block:: xml + + + + + + + + + flock + + semaphore + + memcached://m1.docker + + memcached://m1.docker + memcached://m2.docker + + redis://r1.docker + + redis://r1.docker + redis://r2.docker + + %env(REDIS_URL)% + + + redis://r1.docker + redis://r2.docker + semaphore + + + + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('framework', [ + // these are all the supported lock stores + 'lock' => null, + 'lock' => 'flock', + 'lock' => 'semaphore', + 'lock' => 'memcached://m1.docker', + 'lock' => ['memcached://m1.docker', 'memcached://m2.docker'], + 'lock' => 'redis://r1.docker', + 'lock' => ['redis://r1.docker', 'redis://r2.docker'], + 'lock' => '%env(MEMCACHED_OR_REDIS_URL)%', + + // named locks + 'lock' => [ + 'invoice' => ['redis://r1.docker', 'redis://r2.docker'], + 'report' => 'semaphore', + ], + ]); + +.. _reference-lock-resources-name: + +name +"""" + +**type**: ``prototype`` + +Name of the lock you want to create. + +.. tip:: + + If you want to use the `RetryTillSaveStore` for :ref:`non-blocking locks `, + you can do it by :doc:`decorating the store ` service: + + .. code-block:: yaml + + lock.invoice.retry_till_save.store: + class: Symfony\Component\Lock\Store\RetryTillSaveStore + decorates: lock.invoice.store + arguments: ['@lock.invoice.retry.till.save.store.inner', 100, 50] + workflows ~~~~~~~~~ From c8a6ec5543bdfb5e63cf690727e0cfc99eaebb1b Mon Sep 17 00:00:00 2001 From: Dmitry Simushev Date: Sat, 8 Jun 2019 23:30:33 +0300 Subject: [PATCH 0004/7665] [DomCrawler] Add hint about Form::getName method --- components/dom_crawler.rst | 2 ++ testing.rst | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/components/dom_crawler.rst b/components/dom_crawler.rst index c6163f0fbcb..6d2745066b2 100644 --- a/components/dom_crawler.rst +++ b/components/dom_crawler.rst @@ -478,6 +478,8 @@ useful methods for working with forms:: $method = $form->getMethod(); + $name = $form->getName(); + The :method:`Symfony\\Component\\DomCrawler\\Form::getUri` method does more than just return the ``action`` attribute of the form. If the form method is GET, then it mimics the browser's behavior and returns the ``action`` diff --git a/testing.rst b/testing.rst index 3163d57721a..2b86ef7bd5e 100644 --- a/testing.rst +++ b/testing.rst @@ -801,6 +801,12 @@ their type:: $form['my_form[field][O]']->upload('/path/to/lucas.jpg'); $form['my_form[field][1]']->upload('/path/to/lisa.jpg'); +.. tip:: + + All field names in forms generated by Symfony are prefixed with the form's name. + If the name is autogenerated you can get it using + :method:`Symfony\\Component\\DomCrawler\\Form::getName` method. + .. tip:: If you purposefully want to select "invalid" select/radio values, see From e1521a00e6bba542191db38e3ce0ddfcc60f2563 Mon Sep 17 00:00:00 2001 From: Edouard Lescot Date: Thu, 27 Jun 2019 15:47:28 +0200 Subject: [PATCH 0005/7665] Update controllers.rst Do not add annotation routing configuration if your project uses Symfony Flex since the recipe already created the annotations.yaml file with the config inside. --- best_practices/controllers.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index c2e9827b32e..6288a303db7 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -47,14 +47,14 @@ this suffix is neither required nor recommended, so you can safely remove it. Routing Configuration --------------------- -To load routes defined as annotations in your controllers, add the following -configuration to the main routing configuration file: +To load routes defined as annotations in your controllers and if you are not using Symfony Flex, add the following +configuration to the annotation routing configuration file: .. code-block:: yaml - # config/routes.yaml + # config/routes/annotations.yaml controllers: - resource: '../src/Controller/' + resource: '../../src/Controller/' type: annotation This configuration will load annotations from any controller stored inside the From 5190b5e43eb1e22eaccd1c9ff421332c2f3b962c Mon Sep 17 00:00:00 2001 From: elescot Date: Mon, 1 Jul 2019 07:39:27 +0200 Subject: [PATCH 0006/7665] Refactor documentation assuming we use Symfony Flex --- best_practices/controllers.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 6288a303db7..ab3c353caee 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -47,8 +47,13 @@ this suffix is neither required nor recommended, so you can safely remove it. Routing Configuration --------------------- -To load routes defined as annotations in your controllers and if you are not using Symfony Flex, add the following -configuration to the annotation routing configuration file: +To load routes defined as annotations in your controllers, run the following command : + +.. code-block:: terminal + + $ composer require doctrine/annotations + +Thanks to the :doc:`Flex recipe`, a ``config/routes/annotations.yaml`` file will be created: .. code-block:: yaml From 8557b34301910710752998a0ca422c5ad410ac5a Mon Sep 17 00:00:00 2001 From: Edouard Lescot Date: Wed, 3 Jul 2019 09:47:12 +0200 Subject: [PATCH 0007/7665] Removing space before colon --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index ab3c353caee..c0fac9848fb 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -47,7 +47,7 @@ this suffix is neither required nor recommended, so you can safely remove it. Routing Configuration --------------------- -To load routes defined as annotations in your controllers, run the following command : +To load routes defined as annotations in your controllers, run the following command: .. code-block:: terminal From 28140816fd459739d85ad30f68b4bd7477092932 Mon Sep 17 00:00:00 2001 From: MarvinBlstrli <45764446+MarvinBlstrli@users.noreply.github.com> Date: Wed, 10 Jul 2019 13:55:02 +0200 Subject: [PATCH 0008/7665] fix data-widget-counter --- reference/forms/types/collection.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/forms/types/collection.rst b/reference/forms/types/collection.rst index ba61e8ca3c3..65e89202c94 100644 --- a/reference/forms/types/collection.rst +++ b/reference/forms/types/collection.rst @@ -182,7 +182,7 @@ And update the template as follows: