-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] PhpDumper should follow coding standards #20082
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac | |
*/ | ||
private function generateMatchMethod($supportsRedirections) | ||
{ | ||
$code = rtrim($this->compileRoutes($this->getRoutes(), $supportsRedirections), "\n"); | ||
$code = $this->compileRoutes($this->getRoutes(), $supportsRedirections); | ||
|
||
return <<<EOF | ||
public function match(\$pathinfo) | ||
|
@@ -147,13 +147,15 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections) | |
// apply extra indention at each line (except empty ones) | ||
$groupCode = preg_replace('/^.{2,}$/m', ' $0', $groupCode); | ||
$code .= $groupCode; | ||
$code .= " }\n\n"; | ||
$code .= "\n }"; | ||
} else { | ||
$code .= $groupCode; | ||
} | ||
|
||
$code .= "\n\n"; | ||
} | ||
|
||
return $code; | ||
return rtrim($code, "\n"); | ||
} | ||
|
||
/** | ||
|
@@ -182,12 +184,15 @@ private function compilePrefixRoutes(DumperPrefixCollection $collection, $suppor | |
if ($route instanceof DumperCollection) { | ||
$code .= $this->compilePrefixRoutes($route, $supportsRedirections, $optimizedPrefix); | ||
} else { | ||
$code .= $this->compileRoute($route->getRoute(), $route->getName(), $supportsRedirections, $optimizedPrefix)."\n"; | ||
$code .= $this->compileRoute($route->getRoute(), $route->getName(), $supportsRedirections, $optimizedPrefix); | ||
} | ||
$code .= "\n\n"; | ||
} | ||
|
||
$code = rtrim($code, "\n"); | ||
|
||
if ($optimizable) { | ||
$code .= " }\n\n"; | ||
$code .= "\n }"; | ||
// apply extra indention at each line (except empty ones) | ||
$code = preg_replace('/^.{2,}$/m', ' $0', $code); | ||
} | ||
|
@@ -300,7 +305,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren | |
if (!$supportsRedirections) { | ||
throw new \LogicException('The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.'); | ||
} | ||
$schemes = str_replace("\n", '', var_export(array_flip($schemes), true)); | ||
$schemes = $this->exportArray(array_flip($schemes)); | ||
$code .= <<<EOF | ||
\$requiredSchemes = $schemes; | ||
if (!isset(\$requiredSchemes[\$this->context->getScheme()])) { | ||
|
@@ -325,17 +330,17 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren | |
$code .= sprintf( | ||
" return \$this->mergeDefaults(array_replace(%s), %s);\n", | ||
implode(', ', $vars), | ||
str_replace("\n", '', var_export($route->getDefaults(), true)) | ||
$this->exportArray($route->getDefaults()) | ||
); | ||
} elseif ($route->getDefaults()) { | ||
$code .= sprintf(" return %s;\n", str_replace("\n", '', var_export(array_replace($route->getDefaults(), array('_route' => $name)), true))); | ||
$code .= sprintf(" return %s;\n", $this->exportArray(array_replace($route->getDefaults(), array('_route' => $name)))); | ||
} else { | ||
$code .= sprintf(" return array('_route' => '%s');\n", $name); | ||
} | ||
$code .= " }\n"; | ||
$code .= ' }'; | ||
|
||
if ($methods) { | ||
$code .= " $gotoname:\n"; | ||
$code .= "\n $gotoname:"; | ||
} | ||
|
||
return $code; | ||
|
@@ -371,6 +376,11 @@ private function groupRoutesByHostRegex(RouteCollection $routes) | |
return $groups; | ||
} | ||
|
||
protected function exportArray($array) | ||
{ | ||
return preg_replace(array('/array \(/', '/,\n *\)/', '/,\n */', '/\n */'), array('array(', ')', ', ', ''), var_export($array, true)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. collision risk again? |
||
} | ||
|
||
/** | ||
* Organizes the routes into a prefix tree. | ||
* | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a risk of collision with the content of a string here, CS is not worth it imho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I thought I had this covered, but I must have missed something (I wrote this code a while back, so I don't remember my reasoning).
I cannot think of an easy way to fix this, so I think I'll just close this PR.
BTW the existing code simply strips newlines – this is also not completely kosher, but it might be enough for the specific arrays in question.