By default, UrlGenerator , I do not think this is possible if you do not want to bind to strings.
You can make your own HttpsUrlGenerator extends UrlGenerator introducing one small change:
Inside the generate() method instead:
return $this->doGenerate( $compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens(), $route->getSchemes() );
You can do:
return $this->doGenerate( $compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens(), ['https'] );
As you can see, $route->getSchemes() loaded into doGenerate() based on the route settings (link to the tutorial above).
You can even go further and externalize this array of circuits and provide it via __construct .
Hope this helps a bit;)
Jovan perovic
source share