Skip to content

Commit f964cc8

Browse files
committed
bug symfony#10215 [Routing] reduced recursion in dumper (arnaud-lb)
This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes symfony#10215). Discussion ---------- [Routing] reduced recursion in dumper | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | sensiolabs/SensioFrameworkExtraBundle/issues/275 | License | MIT This reduces recursion in the route dumper, avoiding issues with xdebug's recursion limit. Commits ------- fa6eebc reduced recursion when building DumperPrefixCollection 9278b27 renamed variables - making next change more readable
2 parents 5fbcf88 + 979d5c0 commit f964cc8

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,27 @@ public function addPrefixRoute(DumperRoute $route)
5656
{
5757
$prefix = $route->getRoute()->compile()->getStaticPrefix();
5858

59-
// Same prefix, add to current leave
60-
if ($this->prefix === $prefix) {
61-
$this->add($route);
59+
for ($collection = $this; null !== $collection; $collection = $collection->getParent()) {
6260

63-
return $this;
64-
}
65-
66-
// Prefix starts with route's prefix
67-
if ('' === $this->prefix || 0 === strpos($prefix, $this->prefix)) {
68-
$collection = new DumperPrefixCollection();
69-
$collection->setPrefix(substr($prefix, 0, strlen($this->prefix)+1));
70-
$this->add($collection);
61+
// Same prefix, add to current leave
62+
if ($collection->prefix === $prefix) {
63+
$collection->add($route);
7164

72-
return $collection->addPrefixRoute($route);
73-
}
65+
return $collection;
66+
}
7467

75-
// No match, fallback to parent (recursively)
68+
// Prefix starts with route's prefix
69+
if ('' === $collection->prefix || 0 === strpos($prefix, $collection->prefix)) {
70+
$child = new DumperPrefixCollection();
71+
$child->setPrefix(substr($prefix, 0, strlen($collection->prefix)+1));
72+
$collection->add($child);
7673

77-
if (null === $parent = $this->getParent()) {
78-
throw new \LogicException("The collection root must not have a prefix");
74+
return $child->addPrefixRoute($route);
75+
}
7976
}
8077

81-
return $parent->addPrefixRoute($route);
78+
// Reached only if the root has a non empty prefix
79+
throw new \LogicException("The collection root must not have a prefix");
8280
}
8381

8482
/**

0 commit comments

Comments
 (0)