Skip to content
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

Routing issue with installation in a sub-directory #7129

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

Routing issue with installation in a sub-directory #7129

DHorchler opened this issue Feb 19, 2013 · 11 comments

Comments

@DHorchler
Copy link

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
Copy link
Member

Tobion commented Feb 19, 2013

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

@rande
Copy link
Contributor

rande commented Feb 20, 2013

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

@Tobion
Copy link
Member

Tobion commented Feb 20, 2013

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
Copy link
Contributor

rande commented Feb 20, 2013

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

@Tobion
Copy link
Member

Tobion commented Feb 20, 2013

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

@DHorchler
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Contributor

rande commented Feb 21, 2013

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

Thanks

@Tobion
Copy link
Member

Tobion commented Feb 21, 2013

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
Copy link
Author

@Tobion yes, will need a couple of days.

@fabpot fabpot closed this as completed Mar 23, 2013
fabpot added a commit to symfony/form that referenced this issue Nov 25, 2013
* 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
fabpot added a commit to symfony/form that referenced this issue Nov 25, 2013
* 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
ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
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
ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
* 2.1:
  symfony#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 symfony#7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR symfony#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
ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
* 2.2:
  symfony#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 symfony#7355)
  [HttpFoudantion] fixed Request::getPreferredLanguage()
  Revert "merged branch jfsimon/issue-6928 (PR symfony#7378)"
  Routing issue with installation in a sub-directory ref: symfony#7129
fabpot added a commit to symfony/form that referenced this issue May 23, 2014
* 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
fabpot added a commit to symfony/form that referenced this issue May 23, 2014
* 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
gencer pushed a commit to gencer/Yaml that referenced this issue Jul 29, 2014
* 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
gencer pushed a commit to gencer/Yaml that referenced this issue Jul 29, 2014
* 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
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this issue Nov 11, 2014
fabpot added a commit to symfony/framework-bundle that referenced this issue Nov 11, 2014
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
teohhanhui pushed a commit to teohhanhui/Yaml that referenced this issue Aug 7, 2015
* 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
teohhanhui pushed a commit to teohhanhui/Yaml that referenced this issue Aug 7, 2015
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants