/
OriginalInvalidAccordingToSchema.php
58 lines (48 loc) 路 1.26 KB
/
OriginalInvalidAccordingToSchema.php
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
53
54
55
56
57
58
<?php
declare(strict_types=1);
/**
* Copyright (c) 2018-2022 Andreas M枚ller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/json-normalizer
*/
namespace Ergebnis\Json\Normalizer\Exception;
final class OriginalInvalidAccordingToSchema extends \RuntimeException implements Exception
{
private string $schemaUri = '';
/**
* @phpstan-var list<string>
* @psalm-var list<string>
*
* @var array<int, string>
*/
private array $errors = [];
public static function fromSchemaUriAndErrors(
string $schemaUri,
string ...$errors
): self {
$exception = new self(\sprintf(
'Original JSON is not valid according to schema "%s".',
$schemaUri,
));
$exception->schemaUri = $schemaUri;
$exception->errors = \array_values($errors);
return $exception;
}
public function schemaUri(): string
{
return $this->schemaUri;
}
/**
* @phpstan-return list<string>
* @psalm-return list<string>
*
* @return array<int, string>
*/
public function errors(): array
{
return $this->errors;
}
}