@@ -55,31 +55,28 @@ public function setPrefix($prefix)
55
55
public function addPrefixRoute (DumperRoute $ route )
56
56
{
57
57
$ prefix = $ route ->getRoute ()->compile ()->getStaticPrefix ();
58
- $ collection = $ this ;
59
58
60
- // Same prefix, add to current leave
61
- if ($ collection ->prefix === $ prefix ) {
62
- $ collection ->add ($ route );
59
+ for ($ collection = $ this ; null !== $ collection ; $ collection = $ collection ->getParent ()) {
63
60
64
- return $ collection ;
65
- }
66
-
67
- // Prefix starts with route's prefix
68
- if ('' === $ collection ->prefix || 0 === strpos ($ prefix , $ collection ->prefix )) {
69
- $ child = new DumperPrefixCollection ();
70
- $ child ->setPrefix (substr ($ prefix , 0 , strlen ($ collection ->prefix )+1 ));
71
- $ collection ->add ($ child );
61
+ // Same prefix, add to current leave
62
+ if ($ collection ->prefix === $ prefix ) {
63
+ $ collection ->add ($ route );
72
64
73
- return $ child -> addPrefixRoute ( $ route ) ;
74
- }
65
+ return $ collection ;
66
+ }
75
67
76
- // 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 );
77
73
78
- if ( null === $ parent = $ collection -> getParent ()) {
79
- throw new \ LogicException ( " The collection root must not have a prefix " );
74
+ return $ child -> addPrefixRoute ( $ route );
75
+ }
80
76
}
81
77
82
- 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 " );
83
80
}
84
81
85
82
/**
0 commit comments