Commit
…anez) This PR was merged into the 2.3 branch. Discussion ---------- [Routing] Remove usage of deprecated _scheme requirement **This is exact the same commit as it was in #9585, which was not merged due to my fault. Sorry for the noise.** | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8898, #8176 | License | MIT | Doc PR | I removed all usages of the deprecated _scheme requirement inside the Routing Component. Most parts were pretty easy and after multiple refactorings I came up with the solution to have a Route::hasScheme() method and check against this method. I also checked for performance and after trying in_array, arra_flip+isset and foreach, the last one was clearly the winner. https://gist.github.com/Danez/7609898#file-test_performance-php I also adjusted all tests that test '_scheme' to also check the new schemes-requirement. Commits ------- 557dfaa Remove usage of deprecated _scheme in Routing Component
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,15 +137,15 @@ public function generate($name, $parameters = array(), $referenceType = self::AB | |
// the Route has a cache of its own and is not recompiled as long as it does not get modified | ||
$compiledRoute = $route->compile(); | ||
|
||
return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens()); | ||
return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens(), $route->getSchemes()); | ||
} | ||
|
||
/** | ||
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route | ||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because | ||
* it does not match the requirement | ||
*/ | ||
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens) | ||
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array()) | ||
{ | ||
$variables = array_flip($variables); | ||
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters); | ||
|
@@ -204,7 +204,24 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa | |
$schemeAuthority = ''; | ||
if ($host = $this->context->getHost()) { | ||
$scheme = $this->context->getScheme(); | ||
if (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) { | ||
|
||
if ($requiredSchemes) { | ||
$schemeMatched = false; | ||
foreach ($requiredSchemes as $requiredScheme) { | ||
if ($scheme === $requiredScheme) { | ||
$schemeMatched = true; | ||
|
||
break; | ||
} | ||
} | ||
|
||
if (!$schemeMatched) { | ||
$referenceType = self::ABSOLUTE_URL; | ||
$scheme = current($requiredSchemes); | ||
} | ||
|
||
} elseif (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) { | ||
// We do this for BC; to be removed if _scheme is not supported anymore | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Tobion
Member
|
||
$referenceType = self::ABSOLUTE_URL; | ||
$scheme = $req; | ||
} | ||
|
IMHO this is not necessary because the Route class also sets the schemes based on requirements['_scheme']