It would match by the regex, in case there are two placeholders which
match the regex, it would assign it to the either to the first
placeholder that matches it.
So let's say we have
pattern: /products/{category1}/{category2}/{category3}/{productslug}
if all categories would be optional placeholders, generated route would be:
#^/products(?:/(?P<category1>[^/\.]+?))?(?:/(?P<category2>[^/\.]+?))?(?:/(?P<category3>[^/\.]+?))?/(?P<productslug>[^/\.]+)$#x
So it would match these urls:
/products/slug/
/products/category1/slug
/products/category1/category2/slug
/products/category1/category2/category3/slug

By the way, there is already a support for an optional parameter if
there is only one statement (/{optional}). So it's an easy fix. I
could do a patch + few testcases if there is support for this kind of
feature.

--
Aurelijus Valeiša



On Fri, Feb 25, 2011 at 6:10 PM, stof <[email protected]> wrote:
> On Fri, 25 Feb 2011 17:59:17 +0200, [email protected] wrote:
>> I took a look into RouteCompiler.php code and noticed that
>> functionality could be implemented not that hard. Just by throwing in
>> some additional settings array, where you could set which placeholders
>> are optional, and instead wrapping them like that:
>> /(?P<placeholdername>placeholderregex)
>> do this way for optional placeholder:
>> (?:/(?P<placeholdername>placeholderindex))?
>>
>>
>> On Fri, Feb 25, 2011 at 12:30 PM,  <[email protected]> wrote:
>>> Hey,
>>> I encountered big limitation of routing patterns today.
>>>
>>> Use case:
>>> We need to be able to show article in 2 languages, with optional
>>> requirement to have culture placeholder in url.
>>> Right now pattern would look like this:
>>> /articles/{culture}/{year}/{title}.{_format} =>
>>> /articles/en/2011/nicearticle.html
>>> However this limits having culture in url, it is not possible to have
>>> url like this, and e.g. load culture from session/cookie or geoip
>>> database:
>>> /articles/2011/nicearticle.html
>>>
>>> I see 2 solutions now:
>>> 1. Regex support in pattern setting which would allow to solve this
>>> easily and would add more flexibility.
>>> 2. Fallback pattern support (this sounds ugly).
>>>
>>> --
>>> Aurelijus Valeiša
>>> +370-618-19765
>>>
>
> The issue would be routes with several optionnal placeholder. If you have
> two optionnal placeholders and provide only one, which one should match and
> which one should use its default value ?
>
> The current implementation allows to match optionnal placeholders at the
> end ( /articles/en/2011/nicearticle would match the pattern provided by
> Aurelijus without the dot spearator if the _format placeholder is
> optionnal) so the rule is easy to understand: the omitted placeholder is
> the last one. But allowing to omit any placeholder will make matching
> ambiguous.
>
> --
> Christophe | Stof
>
> --
> If you want to report a vulnerability issue on symfony, please send it to 
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
>

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to