@@ -96,21 +96,21 @@ private function getFields(Context $context, bool $creating = false): array
96
96
/**
97
97
* Assert that the fields contained within a data object are valid.
98
98
*/
99
- private function assertFieldsValid (Context $ context , array $ data , bool $ creating = false ): void
99
+ private function assertFieldsValid (Context $ context , bool $ creating = false ): void
100
100
{
101
- $ this ->assertFieldsExist ($ context, $ data );
102
- $ this ->assertFieldsWritable ($ context , $ data , $ creating );
101
+ $ this ->assertFieldsExist ($ context );
102
+ $ this ->assertFieldsWritable ($ context , $ creating );
103
103
}
104
104
105
105
/**
106
106
* Assert that the fields contained within a data object exist in the schema.
107
107
*/
108
- private function assertFieldsExist (Context $ context, array $ data ): void
108
+ private function assertFieldsExist (Context $ context ): void
109
109
{
110
110
$ fields = $ this ->getFields ($ context );
111
111
112
112
foreach (['attributes ' , 'relationships ' ] as $ location ) {
113
- foreach ($ data [$ location ] as $ name => $ value ) {
113
+ foreach ($ context -> data [$ location ] as $ name => $ value ) {
114
114
if (!isset ($ fields [$ name ]) || $ location !== $ fields [$ name ]->location ()) {
115
115
throw (new UnknownFieldException ($ name ))->source ([
116
116
'pointer ' => '/data/ ' . implode ('/ ' , array_filter ([$ location , $ name ])),
@@ -125,13 +125,10 @@ private function assertFieldsExist(Context $context, array $data): void
125
125
*
126
126
* @throws ForbiddenException if a field is not writable.
127
127
*/
128
- private function assertFieldsWritable (
129
- Context $ context ,
130
- array $ data ,
131
- bool $ creating = false ,
132
- ): void {
128
+ private function assertFieldsWritable (Context $ context , bool $ creating = false ): void
129
+ {
133
130
foreach ($ this ->getFields ($ context , $ creating ) as $ field ) {
134
- if (!has_value ($ data , $ field )) {
131
+ if (!has_value ($ context -> data , $ field )) {
135
132
continue ;
136
133
}
137
134
@@ -160,17 +157,17 @@ private function assertFieldWritable(
160
157
/**
161
158
*
162
159
*/
163
- private function deserializeValues (Context $ context , array & $ data , bool $ creating = false ): void
160
+ private function deserializeValues (Context $ context , bool $ creating = false ): void
164
161
{
165
162
foreach ($ this ->getFields ($ context , $ creating ) as $ field ) {
166
- if (!has_value ($ data , $ field )) {
163
+ if (!has_value ($ context -> data , $ field )) {
167
164
continue ;
168
165
}
169
166
170
- $ value = get_value ($ data , $ field );
167
+ $ value = get_value ($ context -> data , $ field );
171
168
172
169
try {
173
- set_value ($ data , $ field , $ field ->deserializeValue ($ value , $ context ));
170
+ set_value ($ context -> data , $ field , $ field ->deserializeValue ($ value , $ context ));
174
171
} catch (Sourceable $ e ) {
175
172
throw $ e ->prependSource (['pointer ' => '/data ' . field_path ($ field )]);
176
173
}
@@ -182,12 +179,12 @@ private function deserializeValues(Context $context, array &$data, bool $creatin
182
179
*
183
180
* @throws JsonApiErrorsException if any fields do not pass validation.
184
181
*/
185
- private function assertDataValid (Context $ context , array $ data , bool $ validateAll ): void
182
+ private function assertDataValid (Context $ context , bool $ validateAll ): void
186
183
{
187
184
$ errors = [];
188
185
189
186
foreach ($ this ->getFields ($ context , $ validateAll ) as $ field ) {
190
- $ present = has_value ($ data , $ field );
187
+ $ present = has_value ($ context -> data , $ field );
191
188
192
189
if (!$ present && (!$ field ->required || !$ validateAll )) {
193
190
continue ;
@@ -200,7 +197,7 @@ private function assertDataValid(Context $context, array $data, bool $validateAl
200
197
} else {
201
198
array_push (
202
199
$ errors ,
203
- ...$ this ->validateField ($ context , $ field , get_value ($ data , $ field )),
200
+ ...$ this ->validateField ($ context , $ field , get_value ($ context -> data , $ field )),
204
201
);
205
202
}
206
203
}
@@ -232,14 +229,14 @@ private function validateField(Context $context, Field|Id $field, mixed $value):
232
229
/**
233
230
* Set field values from a data object to the model instance.
234
231
*/
235
- private function setValues (Context $ context , array $ data , bool $ creating = false ): void
232
+ private function setValues (Context $ context , bool $ creating = false ): void
236
233
{
237
234
foreach ($ this ->getFields ($ context , $ creating ) as $ field ) {
238
- if (!has_value ($ data , $ field )) {
235
+ if (!has_value ($ context -> data , $ field )) {
239
236
continue ;
240
237
}
241
238
242
- $ value = get_value ($ data , $ field );
239
+ $ value = get_value ($ context -> data , $ field );
243
240
244
241
$ field ->setValue ($ context ->model , $ value , $ context );
245
242
}
@@ -248,14 +245,14 @@ private function setValues(Context $context, array $data, bool $creating = false
248
245
/**
249
246
* Run any field save callbacks.
250
247
*/
251
- private function saveFields (Context $ context , array $ data , bool $ creating = false ): void
248
+ private function saveFields (Context $ context , bool $ creating = false ): void
252
249
{
253
250
foreach ($ this ->getFields ($ context , $ creating ) as $ field ) {
254
- if (!has_value ($ data , $ field )) {
251
+ if (!has_value ($ context -> data , $ field )) {
255
252
continue ;
256
253
}
257
254
258
- $ value = get_value ($ data , $ field );
255
+ $ value = get_value ($ context -> data , $ field );
259
256
260
257
$ field ->saveValue ($ context ->model , $ value , $ context );
261
258
}
0 commit comments