1 | <?php |
||
12 | class Validator { |
||
13 | const OBJECT_CONTAINER_TYPE = 'type'; |
||
14 | const OBJECT_CONTAINER_ID = 'id'; |
||
15 | const OBJECT_CONTAINER_ATTRIBUTES = 'attributes'; |
||
16 | const OBJECT_CONTAINER_RELATIONSHIPS = 'relationships'; |
||
17 | |||
18 | /** @var array */ |
||
19 | protected $usedFields = []; |
||
20 | /** @var array */ |
||
21 | protected $usedResourceIdentifiers = []; |
||
22 | /** @var array */ |
||
23 | protected static $defaults = [ |
||
24 | /** |
||
25 | * blocks 'type' as a keyword inside attributes or relationships |
||
26 | * the specification doesn't allow this as 'type' is already set at the root of a resource |
||
27 | * set to true if migrating to jsonapi and currently using 'type' as attribute or relationship |
||
28 | */ |
||
29 | 'enforceTypeFieldNamespace' => true, |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * block if already existing in another object, otherwise just overwrite |
||
34 | * |
||
35 | * @see https://jsonapi.org/format/1.1/#document-resource-object-fields |
||
36 | * |
||
37 | * @param string[] $fieldName |
||
38 | * @param string $objectContainer one of the Validator::OBJECT_CONTAINER_* constants |
||
39 | * @param array $options optional {@see Validator::$defaults} |
||
40 | * |
||
41 | * @throws DuplicateException |
||
42 | */ |
||
43 | public function claimUsedFields(array $fieldNames, $objectContainer, array $options=[]) { |
||
65 | |||
66 | /** |
||
67 | * @param string $objectContainer one of the Validator::OBJECT_CONTAINER_* constants |
||
68 | */ |
||
69 | public function clearUsedFields($objectContainerToClear) { |
||
78 | |||
79 | /** |
||
80 | * @param ResourceInterface $resource |
||
81 | * |
||
82 | * @throws InputException if no type or id has been set on the resource |
||
83 | * @throws DuplicateException if the combination of type and id has been set before |
||
84 | */ |
||
85 | public function claimUsedResourceIdentifier(ResourceInterface $resource) { |
||
98 | |||
99 | /** |
||
100 | * @see https://jsonapi.org/format/1.1/#document-member-names |
||
101 | * |
||
102 | * @todo allow non-url safe chars |
||
103 | * |
||
104 | * @param string $memberName |
||
105 | * |
||
106 | * @throws InputException |
||
107 | */ |
||
108 | public static function checkMemberName($memberName) { |
||
130 | |||
131 | /** |
||
132 | * @param string|int $httpStatusCode |
||
133 | * @return boolean |
||
134 | */ |
||
135 | public static function checkHttpStatusCode($httpStatusCode) { |
||
147 | } |
||
148 |