|
2 | 2 |
|
3 | 3 | namespace FOS\HttpCache\Exception;
|
4 | 4 |
|
5 |
| -class InvalidUrlException extends \InvalidArgumentException |
| 5 | +/** |
| 6 | + * Thrown during setup if the configuration for a cache proxy is invalid. |
| 7 | + */ |
| 8 | +class InvalidUrlException extends InvalidArgumentException implements HttpCacheExceptionInterface |
6 | 9 | {
|
7 | 10 | /**
|
8 |
| - * Constructor |
| 11 | + * @param string $url The invalid URL. |
| 12 | + * @param string $reason Further explanation why the URL was invalid (optional) |
9 | 13 | *
|
10 |
| - * @param string $url Invalid URL |
11 |
| - * @param string $reason Reason (optional) |
| 14 | + * @return InvalidUrlException |
12 | 15 | */
|
13 |
| - public function __construct($url, $reason = null) |
| 16 | + public static function invalidUrl($url, $reason = null) |
14 | 17 | {
|
15 | 18 | $msg = sprintf('URL "%s" is invalid.', $url);
|
16 | 19 | if ($reason) {
|
17 | 20 | $msg .= sprintf('Reason: %s', $reason);
|
18 | 21 | }
|
19 | 22 |
|
20 |
| - parent::__construct($msg); |
| 23 | + return new InvalidUrlException($msg); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @param string $server Invalid server |
| 28 | + * @param array $allowed Allowed URL parts |
| 29 | + * |
| 30 | + * @return InvalidUrlException |
| 31 | + */ |
| 32 | + public static function invalidUrlParts($server, array $allowed) |
| 33 | + { |
| 34 | + return new InvalidUrlException(sprintf( |
| 35 | + 'Server "%s" is invalid. Only %s URL parts are allowed.', |
| 36 | + $server, |
| 37 | + implode(', ', $allowed) |
| 38 | + )); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @param string $url Requested full URL |
| 43 | + * @param string $scheme Requested URL scheme |
| 44 | + * @param array $allowed Supported URL schemes |
| 45 | + * |
| 46 | + * @return InvalidUrlException |
| 47 | + */ |
| 48 | + public static function invalidUrlScheme($url, $scheme, array $allowed) |
| 49 | + { |
| 50 | + return new InvalidUrlException(sprintf( |
| 51 | + 'Host "%s" with scheme "%s" is invalid. Only schemes "%s" are supported', |
| 52 | + $url, |
| 53 | + $scheme, |
| 54 | + implode(', ', $allowed) |
| 55 | + )); |
21 | 56 | }
|
22 | 57 | }
|
0 commit comments