Routing issue with installation in a sub-directory #7129

Closed
DHorchler opened this Issue Feb 19, 2013 · 11 comments

4 participants

@DHorchler

Symfony 2.1:

In parameters.yml I have
sub_dir: /mnc

In config.yml:

sonata:
resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: %sub_dir%/secured/admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /mnc/secured/admin

Up to here everything works fine, but if I use

sonata:
resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: %sub_dir%/secured/admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: %sub_dir%/secured/admin

I get a route not found error.
I checked that in the latter case the line

if (0 === strpos($pathinfo, '/%sub_dir%/secured/admin')) {

is generated in the cache file appdevUrlMatcher.php, which should in fact be

if (0 === strpos($pathinfo, '/mnc/secured/admin')) {.

Regards

@Tobion
Symfony member

It's a problem of the loader in SonataAdminBundle and should be reported there. Thanks.

@Tobion Tobion closed this Feb 19, 2013
@DHorchler DHorchler referenced this issue in sonata-project/SonataPageBundle Feb 20, 2013
Closed

Routing issue with installation in a sub-directory #163

@rande

@Tobion This issue is not related to the AdminBundle. The parameter provided in the routing file is not translated to the correct value.

@Tobion
Symfony member

Well, the replacement is done here. Don't know why it wouldn't for the type: sonata_admin. @rande do you know where the problem is?

@rande

@Tobion the resolve parameter does not seems to replace the prefix. Unless prefix is a default or a requirement

@Tobion
Symfony member

Prefix is just the prefix of the path. So it is part of the path in the end.

@DHorchler

I think the problem is not with the route pattern ($pathinfo) itself but with the pattern it is tested against in
if (0 === strpos($pathinfo, '/%sub_dir%/secured/admin')) {

But I don't know how that string is created.

@DHorchler

I found a workaraound:

in namespace Symfony\Component\Routing\Matcher\Dumper change line 141 from

$optimizable = '' !== $prefix && $prefix !== $parentPrefix && $countDirectChildRoutes > 0 && $countAllChildRoutes > 1 && false === strpos($prefix, '{');

to

$optimizable = false;//'' !== $prefix && $prefix !== $parentPrefix && $countDirectChildRoutes > 0 && $countAllChildRoutes > 1 && false === strpos($prefix, '{');

and it works.

@DHorchler

ok, here's a possible patch:

first we need a setter for the RouteCollection prefix in Symfony\Component\Routing\RouteCollection like:

public function setPrefix($prefix)
{
    $this->prefix = $prefix;
}

Then in Symfony\Bundle\FrameworkBundle\Routing\Router add this line:

$collection->setPrefix('/'.ltrim($this->resolveString($collection->getPrefix()), '/'));

in function ResolveParameters like

private function resolveParameters(RouteCollection $collection)
{
    foreach ($collection as $route) {
        if ($route instanceof RouteCollection) {
            $this->resolveParameters($route);
        } else {
            foreach ($route->getDefaults() as $name => $value) {
                $route->setDefault($name, $this->resolveString($value));
            }

            foreach ($route->getRequirements() as $name => $value) {
                 $route->setRequirement($name, $this->resolveString($value));
            }
            $collection->setPrefix('/'.ltrim($this->resolveString($collection->getPrefix()), '/'));
            $route->setPattern($this->resolveString($route->getPattern()));
        }
    }
}
@rande

@Tobion Can you reconsidere this issue ?
@2manypeople Can you propose a PR (with a test case) ?

Thanks

@Tobion
Symfony member

I see this is for Symfony 2.1 only. It should be fixed in 2.2
@2manypeople please open a PR.

@Tobion Tobion reopened this Feb 21, 2013
@DHorchler

@Tobion yes, will need a couple of days.

@fabpot fabpot closed this Mar 23, 2013
@fabpot fabpot added a commit to symfony/form that referenced this issue Nov 25, 2013
@fabpot fabpot Merge branch '2.1' into 2.2
* 2.1:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony/symfony#7129

Conflicts:
	.travis.yml
	src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
	src/Symfony/Component/Routing/RouteCollection.php
281be82
@fabpot fabpot added a commit to symfony/form that referenced this issue Nov 25, 2013
@fabpot fabpot Merge branch '2.2'
* 2.2:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony/symfony#7129
58741b4
@ondrejmirtes ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
@DHorchler DHorchler Routing issue with installation in a sub-directory 8d9cd42
@ondrejmirtes ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
@fabpot fabpot merged branch DHorchler/2.1 (PR #7193)
This PR was merged into the 2.1 branch.

Discussion
----------

Routing issue with installation in a sub-directory

ref: symfony#7129

Commits
-------

8d9cd42 Routing issue with installation in a sub-directory ref: symfony#7129
8ae7d98
@ondrejmirtes ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
@fabpot fabpot Merge branch '2.1' into 2.2
* 2.1:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony#7129

Conflicts:
	.travis.yml
	src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
	src/Symfony/Component/Routing/RouteCollection.php
03fc97d
@ondrejmirtes ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
@fabpot fabpot Merge branch '2.2'
* 2.2:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony#7129
77ec799
@fabpot fabpot added a commit to symfony/form that referenced this issue May 23, 2014
@fabpot fabpot Merge branch '2.1' into 2.2
* 2.1:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony/symfony#7129

Conflicts:
	.travis.yml
	src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
	src/Symfony/Component/Routing/RouteCollection.php
53a1f64
@fabpot fabpot added a commit to symfony/form that referenced this issue May 23, 2014
@fabpot fabpot Merge branch '2.2'
* 2.2:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony/symfony#7129
135bfbd
@gencer gencer pushed a commit to gencer/Yaml that referenced this issue Jul 29, 2014
@fabpot fabpot Merge branch '2.1' into 2.2
* 2.1:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony/symfony#7129

Conflicts:
	.travis.yml
	src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
	src/Symfony/Component/Routing/RouteCollection.php
41b5114
@gencer gencer pushed a commit to gencer/Yaml that referenced this issue Jul 29, 2014
@fabpot fabpot Merge branch '2.2'
* 2.2:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony/symfony#7129
fbc88f0
@fabpot fabpot added a commit to symfony/framework-bundle that referenced this issue Nov 11, 2014
@fabpot fabpot merged branch DHorchler/2.1 (PR #7193)
This PR was merged into the 2.1 branch.

Discussion
----------

Routing issue with installation in a sub-directory

ref: symfony/symfony#7129

Commits
-------

8d9cd42 Routing issue with installation in a sub-directory ref: symfony/symfony#7129
4274280
@hackzilla hackzilla pushed a commit that referenced this issue Dec 10, 2014
@fabpot fabpot Merge branch '2.1' into 2.2
* 2.1:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: #7129

Conflicts:
	.travis.yml
	src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
	src/Symfony/Component/Routing/RouteCollection.php
6af424d
@hackzilla hackzilla pushed a commit that referenced this issue Dec 10, 2014
@fabpot fabpot Merge branch '2.2'
* 2.2:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: #7129
db5ae8b
@teohhanhui teohhanhui pushed a commit to teohhanhui/Yaml that referenced this issue Aug 7, 2015
@fabpot fabpot Merge branch '2.1' into 2.2
* 2.1:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony/symfony#7129

Conflicts:
	.travis.yml
	src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
	src/Symfony/Component/Routing/RouteCollection.php
eb169a0
@teohhanhui teohhanhui pushed a commit to teohhanhui/Yaml that referenced this issue Aug 7, 2015
@fabpot fabpot Merge branch '2.2'
* 2.2:
  #7106 - fix for ZTS builds
  Added '@@' escaping strategy for YamlFileLoader and YamlDumper
  [Yaml] fixed bugs with folded scalar parsing
  [Form] made DefaultCsrfProvider using session_status() when available
  Added unit tests to Dumper
  Update .travis.yml (closes #7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR #7378)"
  Routing issue with installation in a sub-directory ref: symfony/symfony#7129
fb72fd6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment