8000 fix phpdoc of UrlGeneratorInterface that missed some exceptions and i… · symfony/symfony@1997e2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 1997e2e

Browse files
committed
fix phpdoc of UrlGeneratorInterface that missed some exceptions and improve language of exception message
1 parent f0415ed commit 1997e2e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ public function generate($name, $parameters = array(), $referenceType = self::AB
141141
}
142142

143143
/**
144-
* @throws MissingMandatoryParametersException When route has some missing mandatory parameters
145-
* @throws InvalidParameterException When a parameter value is not correct
144+
* @throws MissingMandatoryParametersException When some parameters are missing that mandatory for the route
145+
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
146+
* it does not match the requirement
146147
*/
147148
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostnameTokens)
148149
{
@@ -151,7 +152,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
151152

152153
// all params must be given
153154
if ($diff = array_diff_key($variables, $mergedParams)) {
154-
throw new MissingMandatoryParametersException(sprintf('The "%s" route has some missing mandatory parameters ("%s").', $name, implode('", "', array_keys($diff))));
155+
throw new MissingMandatoryParametersException(sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', array_keys($diff)), $name));
155156
}
156157

157158
$url = '';
@@ -161,7 +162,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
161162
if (!$optional || !array_key_exists($token[3], $defaults) || (string) $mergedParams[$token[3]] !== (string) $defaults[$token[3]]) {
162163
// check requirement
163164
if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#', $mergedParams[$token[3]])) {
164-
$message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $token[2], $mergedParams[$token[3]]);
165+
8000 $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
165166
if ($this->strictRequirements) {
166167
throw new InvalidParameterException($message);
167168
}
@@ -213,7 +214,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
213214
foreach ($hostnameTokens as $token) {
214215
if ('variable' === $token[0]) {
215216
if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#', $mergedParams[$token[3]])) {
216-
$message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $token[2], $mergedParams[$token[3]]);
217+
$message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
217218

218219
if ($this->strictRequirements) {
219220
throw new InvalidParameterException($message);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Component\Routing\Generator;
1313

14-
use Symfony\Component\Routing\RequestContextAwareInterface;
14+
use Symfony\Component\Routing\Exception\InvalidParameterException;
15+
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
1516
use Symfony\Component\Routing\Exception\RouteNotFoundException;
17+
use Symfony\Component\Routing\RequestContextAwareInterface;
1618

1719
/**
1820
* UrlGeneratorInterface is the interface that all URL generator classes must implement.
@@ -74,7 +76,10 @@ interface UrlGeneratorInterface extends RequestContextAwareInterface
7476
*
7577
* @return string The generated URL
7678
*
77-
* @throws RouteNotFoundException if route doesn't exist
79+
* @throws RouteNotFoundException If the named route doesn't exist
80+
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
81+
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
82+
* it does not match the requirement
7883
*
7984
* @api
8085
*/

0 commit comments

Comments
 (0)
0