| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Routing\Exception;
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* Exception thrown when a route cannot be generated because of missing
|
|
|
16 |
* mandatory parameters.
|
|
|
17 |
*
|
|
|
18 |
* @author Alexandre Salomé <alexandre.salome@gmail.com>
|
|
|
19 |
*/
|
|
|
20 |
class MissingMandatoryParametersException extends \InvalidArgumentException implements ExceptionInterface
|
|
|
21 |
{
|
|
|
22 |
private string $routeName = '';
|
|
|
23 |
private array $missingParameters = [];
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* @param string[] $missingParameters
|
|
|
27 |
* @param int $code
|
|
|
28 |
*/
|
|
|
29 |
public function __construct(string $routeName = '', $missingParameters = null, $code = 0, \Throwable $previous = null)
|
|
|
30 |
{
|
|
|
31 |
if (\is_array($missingParameters)) {
|
|
|
32 |
$this->routeName = $routeName;
|
|
|
33 |
$this->missingParameters = $missingParameters;
|
|
|
34 |
$message = sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', $missingParameters), $routeName);
|
|
|
35 |
} else {
|
|
|
36 |
trigger_deprecation('symfony/routing', '6.1', 'Construction of "%s" with an exception message is deprecated, provide the route name and an array of missing parameters instead.', __CLASS__);
|
|
|
37 |
$message = $routeName;
|
|
|
38 |
$previous = $code instanceof \Throwable ? $code : null;
|
|
|
39 |
$code = (int) $missingParameters;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
parent::__construct($message, $code, $previous);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* @return string[]
|
|
|
47 |
*/
|
|
|
48 |
public function getMissingParameters(): array
|
|
|
49 |
{
|
|
|
50 |
return $this->missingParameters;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
public function getRouteName(): string
|
|
|
54 |
{
|
|
|
55 |
return $this->routeName;
|
|
|
56 |
}
|
|
|
57 |
}
|