Skip to content

[Routing] Overriding route puts route on end of collection. #24748

Closed
@mimol91

Description

@mimol91
Q A
Bug report? no
Feature request? yes?
BC Break report? no
RFC? no
Symfony version all

I am working on application which define different route parameters depending on subdomain (for simplicity lets call them languages)

For example there are en, pl, gb sub domains. Which may override some global routes (defined in domain routing)

#routing.yml
_domain:
    resource: routing_domain.yml

_subdomain:
    resource: routing_subdomain.yml
#routing_domain.yml
app_default_index:
    path:     /{language}/index
    defaults: { _controller: AppBundle:Default:index }
    methods: ['GET']
    requirements:
        language: 'en'

app_default_catch_all:
    path:     /{language}/{slug}
    defaults: { _controller: AppBundle:Default:catchAll }
    methods: ['GET']
#routing_subdomain.yml
app_default_index:
    path:     /{language}/index
    defaults: { _controller: AppBundle:Default:index }
    methods: ['GET']
    requirements:
        language: 'en|gb'

Because of priority of sub domain routes it has to be imported last (To override app_default_index from routing_domain.yaml)

Problem with this approach is that it puts app_default_index on the bottom of routes priority, causing that app_default_catch_all is before app_default_index.

 ----------------------- -------- -------- ------ -------------------- 
  Name                    Method   Scheme   Host   Path                
 ----------------------- -------- -------- ------ -------------------- 
  app_default_catch_all   GET      ANY      ANY    /{language}/{slug}  
  app_default_index       GET      ANY      ANY    /{language}/index   
 ----------------------- -------- -------- ------ -------------------- 

It there any way that I am able to override app_default_index route, but keep its initial position?
I've found an place where this logic is set https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/RouteCollection.php#L125

// we need to remove all routes with the same names first because just replacing them
// would not place the new route at the end of the merged array.

What is an reason that route should be put on end of array? How can I solve this problem, without using dynamic route loader and keep everything as simple as possible?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions