-
Notifications
You must be signed in to change notification settings - Fork 7
/
validation.php
170 lines (150 loc) · 5.64 KB
/
validation.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
use CloudCreativity\JsonApi\Contracts\Document\MutableErrorInterface as Error;
use CloudCreativity\JsonApi\Validators\ValidatorErrorFactory as V;
return [
/**
* A compulsory member has not been included in document.
*/
V::MEMBER_REQUIRED => [
Error::TITLE => 'Required Member',
Error::DETAIL => "The member '{member}' is required.",
Error::STATUS => 400,
],
/**
* A non-object has been provided for a member that must be an object.
*/
V::MEMBER_OBJECT_EXPECTED => [
Error::TITLE => 'Object Expected',
Error::DETAIL => "The member '{member}' must be an object.",
Error::STATUS => 400,
],
/**
* A non-string has been provided for a member that must be a string.
* E.g. the spec says that a resource's `type` and `id` keys MUST be strings.
*/
V::MEMBER_STRING_EXPECTED => [
Error::TITLE => 'String Expected',
Error::DETAIL => "The member '{member}' must be a string.",
Error::STATUS => 400,
],
/**
* A value was provided but it was empty, which is not allowed.
*/
V::MEMBER_EMPTY_NOT_ALLOWED => [
Error::TITLE => 'Value Expected',
Error::DETAIL => "The member '{member}' cannot be empty.",
Error::STATUS => 400,
],
/**
* A member that is expected to be a relationship is not an object, array or null value.
*/
V::MEMBER_RELATIONSHIP_EXPECTED => [
Error::TITLE => 'Relationship Expected',
Error::DETAIL => "The member '{member}' must be a relationship object.",
Error::STATUS => 400,
],
/**
* A resource's type is not supported.
*/
V::RESOURCE_UNSUPPORTED_TYPE => [
Error::TITLE => 'Unsupported Resource',
Error::DETAIL => "Resource '{actual}' is not among the type(s) supported by this endpoint. Expecting only '{expected}' resources.",
Error::STATUS => V::STATUS_UNSUPPORTED_TYPE,
],
/**
* A resource's id is not supported.
*/
V::RESOURCE_UNSUPPORTED_ID => [
Error::TITLE => 'Unsupported Resource',
Error::DETAIL => "Resource id '{actual}' is not supported by this endpoint. Expecting only resource '{expected}'.",
Error::STATUS => V::STATUS_UNSUPPORTED_ID,
],
/**
* Used when attributes are invalid but there are no validation error messages in the attributes validator.
*/
V::RESOURCE_INVALID_ATTRIBUTES => [
Error::TITLE => 'Invalid Attributes',
Error::DETAIL => 'The attributes member is invalid.',
Error::STATUS => 400,
],
/**
* Used when generating JSON API errors from validation messages (usually from a framework specific validator)
* for the attributes member of a resource object.
*/
V::RESOURCE_INVALID_ATTRIBUTES_MESSAGES => [
Error::TITLE => 'Invalid Attribute',
Error::STATUS => 422,
],
/**
* Used when relationships are invalid but there are no validation error messages in the relationships validator.
*/
V::RESOURCE_INVALID_RELATIONSHIPS => [
Error::TITLE => 'Invalid Relationships',
Error::DETAIL => 'The relationships member is invalid.',
Error::STATUS => 400,
],
/**
* Used when a has-one relationship is expected, but a has-many has been provided.
*/
V::RELATIONSHIP_HAS_ONE_EXPECTED => [
Error::TITLE => 'Invalid Relationship',
Error::DETAIL => 'The provided relationship must be a has-one relationship',
Error::STATUS => 400,
],
/**
* Used when a has-many relationship is expected, but a has-one has been provided.
*/
V::RELATIONSHIP_HAS_MANY_EXPECTED => [
Error::TITLE => 'Invalid Relationship',
Error::DETAIL => 'The provided relationship must be a has-many relationship',
Error::STATUS => 400,
],
/**
* When an empty relationship is not allowed.
*/
V::RELATIONSHIP_EMPTY_NOT_ALLOWED => [
Error::TITLE => 'Invalid Relationship',
Error::DETAIL => 'The provided relationship cannot be empty.',
Error::STATUS => 422,
],
/**
* The related resource does not exist.
*/
V::RELATIONSHIP_DOES_NOT_EXIST => [
Error::TITLE => 'Invalid Relationship',
Error::DETAIL => 'The related resource does not exist.',
Error::STATUS => V::STATUS_RELATED_RESOURCE_DOES_NOT_EXIST,
],
/**
* When a related resource is not logically acceptable for the relationship. This is the default error
* used if an accept relationship callback/instance returns a boolean rather than an error or errors.
*/
V::RELATIONSHIP_NOT_ACCEPTABLE => [
Error::TITLE => 'Invalid Relationship',
Error::DETAIL => 'The related resource is not acceptable.',
Error::STATUS => 422,
],
/**
* When the resource type of a related resource is not recognised.
*/
V::RELATIONSHIP_UNKNOWN_TYPE => [
Error::TITLE => 'Invalid Relationship',
Error::DETAIL => "Resource type '{actual}' is not recognised.",
Error::STATUS => 400,
],
/**
* When a related resource is not of the correct type for the relationship.
*/
V::RELATIONSHIP_UNSUPPORTED_TYPE => [
Error::TITLE => 'Invalid Relationship',
Error::DETAIL => "Resource '{actual}' is not among the type(s) supported by this relationship. Expecting only '{expected}' resources.",
Error::STATUS => 400,
],
/**
* Used when creating messages about the query parameters, usually from a framework specific validator.
*/
V::QUERY_PARAMETERS_MESSAGES => [
Error::TITLE => 'Invalid Query Parameter',
Error::STATUS => 400,
],
];