|
12 | 12 |
|
13 | 13 | class File extends AbstractResolver
|
14 | 14 | {
|
| 15 | + /** |
| 16 | + * Possible values for encoding. |
| 17 | + */ |
| 18 | + public const VALID_ENCODING_VALUES = ['utf-8', 'latin-1', 'binary']; |
| 19 | + |
| 20 | + /** |
| 21 | + * Possible values for parse. |
| 22 | + */ |
| 23 | + public const VALID_PARSE_VALUES = ['auto', 'text', 'json', 'mustache', 'graphql']; |
| 24 | + |
15 | 25 | /**
|
16 | 26 | * {@inheritdoc}
|
17 | 27 | */
|
@@ -40,15 +50,15 @@ public function isValid(Definition $definition): bool
|
40 | 50 | if ($definition->has('encoding')) {
|
41 | 51 | $encoding = $this->getIterator()->get('encoding', $definition);
|
42 | 52 |
|
43 |
| - if (!\in_array(strtolower($encoding), ['utf-8', 'latin-1', 'binary'])) { |
| 53 | + if (!\in_array(strtolower($encoding), self::VALID_ENCODING_VALUES)) { |
44 | 54 | return false;
|
45 | 55 | }
|
46 | 56 | }
|
47 | 57 |
|
48 | 58 | if ($definition->has('parse')) {
|
49 | 59 | $parse = $this->getIterator()->get('parse', $definition);
|
50 | 60 |
|
51 |
| - if (!\in_array(strtolower($parse), ['auto', 'text'])) { |
| 61 | + if (!\in_array(strtolower($parse), self::VALID_PARSE_VALUES)) { |
52 | 62 | return false;
|
53 | 63 | }
|
54 | 64 | }
|
@@ -83,7 +93,7 @@ public function resolve($definition)
|
83 | 93 |
|
84 | 94 | $content = file_get_contents($path);
|
85 | 95 |
|
86 |
| - if ($parse == 'auto' && pathinfo($path, PATHINFO_EXTENSION) == 'json') { |
| 96 | + if (($parse == 'auto' && pathinfo($path, PATHINFO_EXTENSION) == 'json') || $parse == 'json') { |
87 | 97 | $content = json_decode($content, true);
|
88 | 98 |
|
89 | 99 | if (json_last_error() !== JSON_ERROR_NONE) {
|
|
0 commit comments