-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document new utf8 option of Routing component #6938
Conversation
See #6890 |
or merge both since they aren't on the same page |
@nicolas-grekas my bad, didnt thank you have started something... as you like, I wont be sad if you close this one, my only interest is to see this feature documented ^^ By the way, big thanks! From a business/e-commerce point of view, this feature is so useful :) |
@@ -346,6 +346,44 @@ automatically in the background if you want to use it. A basic example of the | |||
are saved in the ``cache_dir``. This means your script must have write | |||
permissions for that location. | |||
|
|||
Unicode routing support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unicode Routing Support
Unicode routing support | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The routing component supports UTF-8 characters in route paths and requirements. Thanks to the `utf8` route option, you can make Symfony match and generate routes with UTF-8 characters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Routing component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The option needs to be enclosed by double backticks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also wrap lines after the first word that crosses the 72nd character.
requirements: | ||
name: ".+" | ||
options: | ||
utf8: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add Annotations, XML, and PHP examples too.
options: | ||
utf8: true | ||
|
||
In this route, the `utf8` option set to true makes Symfony consider the `.` requirement to match any UTF-8 characters instead of just a single byte character, so the following URLs would match: `/category/日本語`, `/category/فارسی`, `/category/한국어`, etc. In case you are wondering, this option also allows to include and match emojis in URLs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use double backticks everywhere here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and please wrap lines after the first word that crosses the 72nd character
requirements: | ||
default: "日本語|فارسی" | ||
options: | ||
utf8: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need other format examples here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need ? I don't see the gain here when it's already well described here
I will do it if you insist, though (sounds like a simple copy/paste of the resource I've linked ^ ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how the doc is yes, config are always in all formats, repeating is teaching isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, let's go for it :)
options: | ||
utf8: true | ||
|
||
This second example describes how you can use utf8 string as a routing requirement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UTF-8
|
||
.. note:: | ||
|
||
In Symfony 3.2 there is no need to set this utf8 explicitly. As soon as Symfony finds a UTF-8 character in the route path or requirements, it will turn the UTF-8 support automatically. In addition to UTF-8 characters, the Routing component also supports all the `PCRE Unicode properties`_, which are escape sequences that match generic character types. For example, `\p{Lu}` matches any uppercase character in any language, `\p{Greek}` matches any Greek character, `\P{Han}` matches any character not included in the Chinese Han script. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
In Symfony 3.2 there is no need to set this utf8 explicitly. As soon as Symfony finds a UTF-8 character in the route path or requirements, it will turn the UTF-8 support automatically. In addition to UTF-8 characters, the Routing component also supports all the `PCRE Unicode properties`_, which are escape sequences that match generic character types. For example, `\p{Lu}` matches any uppercase character in any language, `\p{Greek}` matches any Greek character, `\P{Han}` matches any character not included in the Chinese Han script. | ||
|
||
.. versionadded:: 3.2 | ||
The UTF8 support in route paths and requirements were added in Symfony 3.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UTF-8 support for route paths and requirements were introduced in Symfony 3.2.
Wow ... I feel so bad :( thank you for this review, I will address comments tomorrow! |
No need to worry. There's not much to change. :) |
991b4b6
to
cf8ab0f
Compare
Hi @xabbuh, I've adressed almost all comments except the one about complete all formats, let me know if this need more work :) Mickaël |
👍 (except for the missing config formats) |
cf8ab0f
to
c542f01
Compare
|
||
<route id="route1" path="/category/{name}"> | ||
<default key="_controller">AppBundle:Default:category</default> | ||
<option key="utf8">true</option> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question here: how can we do to ensure true will be converted to boolean value ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the responsibility of the loader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So ... is it good, or does it need much work from me ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good as it is. :)
@@ -346,6 +346,181 @@ automatically in the background if you want to use it. A basic example of the | |||
are saved in the ``cache_dir``. This means your script must have write | |||
permissions for that location. | |||
|
|||
Unicode Routing support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support
path: /category/{name} | ||
defaults: { _controller: 'DefaultController::categoryAction' } | ||
options: | ||
utf8: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please indent this line with four spaces
# routes.yml | ||
route1: | ||
path: /category/{name} | ||
defaults: { _controller: 'DefaultController::categoryAction' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppBundle:Default:category
return $collection; | ||
|
||
|
||
In this route, the ``utf8`` option set to true makes Symfony consider the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please enclose true
in double backticks
|
||
In this route, the ``utf8`` option set to true makes Symfony consider the | ||
``.`` requirement to match any UTF-8 characters instead of just a single | ||
byte character, so the following URLs would match: ``/category/日本語``, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe split this here: "[...] character. This means that the following URL would match [...]"
|
||
.. configuration-block:: | ||
|
||
.. code-block:: php-annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please indent with four spaces
return $collection; | ||
|
||
|
||
This second example describes how you can use UTF-8 string as a routing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...] as routing requirements.
|
||
.. note:: | ||
|
||
In Symfony 3.2 there is no need to set this utf8 explicitly. As soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...] to explicitly set the utf8
option.
|
||
.. versionadded:: 3.2 | ||
UTF-8 support for route paths and requirements were introduced in | ||
Symfony 3.2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this up to the beginning of this section.
bbd2931
to
19a864f
Compare
@xabbuh thanks again for your time. Comments addressed ;) |
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. versionadded:: 3.2 | ||
UTF-8 support for route paths and requirements were introduced in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was
path: /category/{name} | ||
defaults: { _controller: 'AppBundle:Default:category' } | ||
options: | ||
utf8: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's the same in the other YAML example too.
@mickaelandrieu I left two last minor comments and indentation of the PHP code examples looks weird too. But overall this change looks ready to be merged. 👍 |
@xabbuh I won't give up now :D let me improve again my contribution ;) edit: comments addressed (and PHP code cs fixed) |
19a864f
to
2569aca
Compare
👍 Status: Reviewed |
…ndrieu) This PR was merged into the master branch. Discussion ---------- Document new utf8 option of Routing component Hi, all credits to @javiereguiluz and @nicolas-grekas, I've just copy/pasted the blog article http://symfony.com/blog/new-in-symfony-3-2-unicode-routing-support#comment-form Mickaël Commits ------- 2569aca Document new utf8 option of Routing component
Thanks @mickaelandrieu! After your quick responses to the reviews, this PR has now made it to the docs! Fyi, I've fixed some indentation issues and splitted the big note directive in c5328d7. |
@wouterj thank you, it's better now :) |
Hi,
all credits to @javiereguiluz and @nicolas-grekas, I've just copy/pasted the blog article http://symfony.com/blog/new-in-symfony-3-2-unicode-routing-support#comment-form
Mickaël