forked from membrane-php/membrane-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCannotProcessOpenAPI.php
More file actions
52 lines (42 loc) · 1.54 KB
/
CannotProcessOpenAPI.php
File metadata and controls
52 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Membrane\OpenAPI\Exception;
use RuntimeException;
/*
* This exception occurs if your Open API is readable but cannot be processed.
* This may occur for one of the following reasons:
* 1: Your OpenAPI is invalid according to the OpenAPI Specification
* 2: Your OpenAPI contains features currently unsupported by Membrane
*/
class CannotProcessOpenAPI extends RuntimeException
{
public const INVALID_OPEN_API = 0;
public const UNSUPPORTED_MEDIA_TYPES = 1;
public const UNSUPPORTED_KEYWORD = 2;
public static function invalidOpenAPI(string $fileName, string ...$errors): self
{
$message = sprintf(
"%s is invalid OpenAPI due to the following:\n\t- %s",
$fileName,
implode("\n\t- ", $errors)
);
return new self($message, self::INVALID_OPEN_API);
}
public static function unsupportedMediaTypes(string ...$mediaTypes): self
{
$supportedContentTypes = [
'application/json',
];
$message = sprintf(
"Membrane currently supports:\n\t- %s\nMediaTypes provided:\n\t- %s",
implode("\n\t-", $supportedContentTypes),
implode("\n\t- ", $mediaTypes)
);
return new self($message, self::UNSUPPORTED_MEDIA_TYPES);
}
public static function unsupportedKeyword(string $keyword): self
{
$message = sprintf('Membrane does not currently support the keyword "%s"', $keyword);
return new self($message, self::UNSUPPORTED_KEYWORD);
}
}