Skip to content

Commit 912fc4d

Browse files
committed
[Routing] deprecate the old url generator reference type values
1 parent a65b489 commit 912fc4d

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class Controller extends ContainerAware
3939
/**
4040
* Generates a URL from the given parameters.
4141
*
42-
* @param string $route The name of the route
43-
* @param mixed $parameters An array of parameters
44-
* @param bool|string $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
42+
* @param string $route The name of the route
43+
* @param mixed $parameters An array of parameters
44+
* @param int $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
4545
*
4646
* @return string The generated URL
4747
*

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/RouterHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function __construct(UrlGeneratorInterface $router)
3636
/**
3737
* Generates a URL from the given parameters.
3838
*
39-
* @param string $name The name of the route
40-
* @param mixed $parameters An array of parameters
41-
* @param bool|string $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
39+
* @param string $name The name of the route
40+
* @param mixed $parameters An array of parameters
41+
* @param int $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
4242
*
4343
* @return string The generated URL
4444
*

src/Symfony/Component/Routing/Generator/UrlGenerator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ public function generate($name, $parameters = array(), $referenceType = self::AB
143143
*/
144144
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array())
145145
{
146+
if (is_bool($referenceType) || is_string($referenceType)) {
147+
@trigger_error('The hardcoded value you are using for the $referenceType argument of the '.__CLASS__.'::generate method is deprecated since version 2.8 and will not be supported anymore in 3.0. Use the constants defined in the UrlGeneratorInterface instead.', E_USER_DEPRECATED);
148+
149+
if (true === $referenceType) {
150+
$referenceType = self::ABSOLUTE_URL;
151+
} elseif (false === $referenceType) {
152+
$referenceType = self::ABSOLUTE_PATH;
153+
} elseif ('relative' === $referenceType) {
154+
$referenceType = self::RELATIVE_PATH;
155+
} elseif ('network' === $referenceType) {
156+
$referenceType = self::NETWORK_PATH;
157+
}
158+
}
159+
146160
$variables = array_flip($variables);
147161
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
148162

src/Symfony/Component/Routing/Generator/UrlGeneratorInterface.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ interface UrlGeneratorInterface extends RequestContextAwareInterface
3434
/**
3535
* Generates an absolute URL, e.g. "http://example.com/dir/file".
3636
*/
37-
const ABSOLUTE_URL = true;
37+
const ABSOLUTE_URL = 0;
3838

3939
/**
4040
* Generates an absolute path, e.g. "/dir/file".
4141
*/
42-
const ABSOLUTE_PATH = false;
42+
const ABSOLUTE_PATH = 1;
4343

4444
/**
4545
* Generates a relative path based on the current request path, e.g. "../parent-file".
4646
*
4747
* @see UrlGenerator::getRelativePath()
4848
*/
49-
const RELATIVE_PATH = 'relative';
49+
const RELATIVE_PATH = 2;
5050

5151
/**
5252
* Generates a network path, e.g. "//example.com/dir/file".
5353
* Such reference reuses the current scheme but specifies the host.
5454
*/
55-
const NETWORK_PATH = 'network';
55+
const NETWORK_PATH = 3;
5656

5757
/**
5858
* Generates a URL or path for a specific route based on the given parameters.
@@ -69,9 +69,9 @@ interface UrlGeneratorInterface extends RequestContextAwareInterface
6969
*
7070
* If there is no route with the given name, the generator must throw the RouteNotFoundException.
7171
*
72-
* @param string $name The name of the route
73-
* @param mixed $parameters An array of parameters
74-
* @param bool|string $referenceType The type of reference to be generated (one of the constants)
72+
* @param string $name The name of the route
73+
* @param mixed $parameters An array of parameters
74+
* @param int $referenceType The type of reference to be generated (one of the constants)
7575
*
7676
* @return string The generated URL
7777
*

src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getLogoutUrl($key = null)
8686
* Generates the logout URL for the firewall.
8787
*
8888
* @param string|null $key The firewall key or null to use the current firewall key
89-
* @param bool|string $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
89+
* @param int $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
9090
*
9191
* @return string The logout URL
9292
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy