-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-schema-utils.php
More file actions
857 lines (725 loc) · 19.2 KB
/
json-schema-utils.php
File metadata and controls
857 lines (725 loc) · 19.2 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
<?php
/**
* JSON Schema util functions
*
* @package wpct-plugin
*/
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
/**
* Applies validation and sanitization to data based on json schemas.
*
* @param array $data Target data.
* @param array $schema JSON schema.
* @param string $name Self name.
*
* @return array|WP_Error validation result
*/
function wpct_plugin_sanitize_with_schema( $data, $schema, $name = '#' ) {
if ( isset( $schema['const'] ) && $data !== $schema['const'] ) {
return $schema['const'];
}
if ( isset( $schema['anyOf'] ) ) {
$matching_schema = rest_find_any_matching_schema( $data, $schema, $name );
if ( is_wp_error( $matching_schema ) ) {
return $matching_schema;
}
if ( ! isset( $schema['type'] ) && isset( $matching_schema['type'] ) ) {
$schema = $matching_schema;
}
}
if ( isset( $schema['oneOf'] ) ) {
$matching_schema = rest_find_one_matching_schema( $data, $schema, $name );
if ( is_wp_error( $matching_schema ) ) {
return $matching_schema;
}
if ( ! isset( $schema['type'] ) && isset( $matching_schema['type'] ) ) {
$schema = $matching_schema;
}
}
if ( ! isset( $schema['type'] ) ) {
return new WP_Error(
'rest_invalid_schema',
'`type` is a required attribute of a schema',
$schema
);
}
if ( is_array( $schema['type'] ) ) {
$type = rest_get_best_type_for_value( $data, $schema['type'] );
if ( ! $type ) {
return new WP_Error(
'rest_invalid_type',
"{$name} is not of type " . implode( $schema['type'] ),
$data
);
} else {
$schema['type'] = $type;
}
}
$sanitize_callback = $schema['sanitize_callback'] ?? null;
if ( is_callable( $sanitize_callback ) ) {
$data = $sanitize_callback( $data, $schema, $name );
if ( ! $data || is_wp_error( $data ) ) {
if ( isset( $schema['default'] ) ) {
return $schema['default'];
}
return new WP_Error( 'rest_invalid_value', "{$name} is invalid" );
}
return $data;
}
$validate_callback = $schema['validate_callback'] ?? null;
if ( is_callable( $validate_callback ) ) {
$is_valid = $validate_callback( $data, $schema, $name );
if ( ! $is_valid || is_wp_error( $is_valid ) ) {
if ( isset( $schema['default'] ) ) {
return $schema['default'];
}
return new WP_Error( 'rest_invalid_value', "{$name} is invalid" );
}
}
if ( 'object' === $schema['type'] ) {
if ( ! rest_is_object( $data ) ) {
return new WP_Error(
'rest_invalid_type',
"{$name} is not of type object",
$data
);
}
$data = rest_sanitize_object( $data );
$required = wp_is_numeric_array( $schema['required'] ?? false )
? $schema['required']
: array();
$props = is_array( $schema['properties'] ?? false )
? $schema['properties']
: array();
$additional_properties = $schema['additionalProperties'] ?? true;
$min_props = $schema['minProps'] ?? 0;
$max_props = $schema['maxProps'] ?? INF;
foreach ( $data as $prop => $val ) {
$prop_schema =
$props[ $prop ] ??
rest_find_matching_pattern_property_schema(
$prop,
$schema,
$name . '.' . $prop
);
if ( $prop_schema ) {
$is_required =
in_array( $prop, $required, true ) ||
( $prop_schema['required'] ?? false ) === true;
$val = wpct_plugin_sanitize_with_schema(
$val,
$prop_schema,
$name . '.' . $prop
);
if ( is_wp_error( $val ) ) {
$error = $val;
if ( isset( $props[ $prop ]['default'] ) ) {
$data[ $prop ] = $props[ $prop ]['default'];
} elseif ( ! $is_required ) {
unset( $data[ $prop ] );
} else {
return $error;
}
} else {
$data[ $prop ] = $val;
}
if ( $is_required ) {
$index = array_search( $prop, $required, true );
array_splice( $required, $index, 1 );
}
} elseif ( false === $additional_properties ) {
unset( $data[ $prop ] );
}
}
if ( count( $required ) ) {
foreach ( $required as $prop ) {
if ( isset( $props[ $prop ]['default'] ) ) {
$data[ $prop ] = $props[ $prop ]['default'];
} elseif ( 'boolean' === $props[ $prop ]['type'] ) {
$data[ $prop ] = false;
} else {
return new WP_Error(
'rest_property_required',
"{$prop} is required property of {$name}",
array( 'value' => $data )
);
}
}
}
foreach ( $props as $prop => $prop_schema ) {
if (
isset( $prop_schema['required'] ) &&
true === $prop_schema['required'] &&
! isset( $data[ $prop ] )
) {
if ( isset( $prop_schema['default'] ) ) {
$data[ $prop ] = $prop_schema['default'];
} elseif ( 'boolean' === $prop_schema['type'] ) {
$data[ $prop ] = false;
} else {
return new WP_Error(
'rest_property_required',
"{$prop} is required property of {$name}",
array( 'value' => $data )
);
}
}
}
if ( count( $data ) < $min_props ) {
return new WP_Error(
'rest_too_few_properties',
"{$name} has less properties than required",
array(
'minProps' => $min_props,
'value' => $data,
)
);
} elseif ( count( $data ) > $max_props ) {
return new WP_Error(
'rest_too_many_properties',
"{$name} exceed the allowed number of properties",
array(
'maxProps' => $max_props,
'value' => $data,
)
);
}
return rest_sanitize_value_from_schema( $data, $schema, $name );
} elseif ( 'array' === $schema['type'] ) {
if ( ! rest_is_array( $data ) ) {
return new WP_Error(
'rest_invalid_type',
"{$name} is not of type array",
array( 'value' => $data )
);
}
$data = rest_sanitize_array( $data );
$items = $schema['items'] ?? array();
$additional_items = $schema['additionalItems'] ?? true;
$min_items = $schema['minItems'] ?? 0;
$max_items = $schema['maxItems'] ?? INF;
// support for array enums.
if ( isset( $schema['enum'] ) && is_array( $schema['enum'] ) ) {
$enum_items = array();
foreach ( $data as $item ) {
if ( in_array( $item, $schema['enum'], true ) ) {
$enum_items[] = $item;
}
}
$data = $enum_items;
}
if ( wp_is_numeric_array( $items ) ) {
if ( false === $additional_items && count( $data ) > count( $items ) ) {
return new WP_Error(
'rest_invalid_items_count',
"{$name} contains invalid count items",
array(
'items' => $items,
'value' => $data,
)
);
}
} else {
$i = 0;
$len = count( $data );
$_items = array();
while ( $i < $len ) {
$_items[] = $items;
++$i;
}
$items = $_items;
}
$i = 0;
$len = count( $data );
while ( $i < $len ) {
if ( isset( $items[ $i ] ) ) {
$val = wpct_plugin_sanitize_with_schema(
$data[ $i ],
$items[ $i ],
$name . "[{$i}]"
);
if ( is_wp_error( $val ) ) {
unset( $data[ $i ] );
} else {
$data[ $i ] = $val;
}
}
++$i;
}
$data = array_values( $data );
if ( count( $data ) > $max_items ) {
return new WP_Error(
'rest_too_many_items',
"{$name} contains more items than allowed",
array(
'maxItems' => $max_items,
'value' => $data,
)
);
} elseif ( count( $data ) < $min_items ) {
return new WP_Error(
'rest_too_few_items',
"{$name} contains less items than required",
array(
'minItems' => $min_items,
'value' => $data,
)
);
}
if (
isset( $schema['uniqueItems'] ) &&
! rest_validate_array_contains_unique_items( $data )
) {
return new WP_Error(
'rest_duplicate_items',
"{$name} has duplicate items",
array( 'value' => $data )
);
}
if ( isset( $schema['items'] ) && wp_is_numeric_array( $schema['items'] ) ) {
return $data;
}
return rest_sanitize_value_from_schema( $data, $schema, $name );
} elseif ( 'boolean' === $schema['type'] ) {
$data = (bool) $data;
} elseif ( in_array( $schema['type'], array( 'integer', 'number' ), true ) && is_numeric( $data ) ) {
$data = 'integer' === $schema['type'] ? intval( $data ) : floatval( $data );
$min = $schema['min'] ?? -INF;
$max = $schema['max'] ?? INF;
if ( $min > $data ) {
return new WP_Error(
'rest_value_too_small',
"{$name} has {$data} that is smaller than {$min}",
array( 'value' => $data ),
);
} elseif ( $max < $data ) {
return new WP_Error(
'rest_value_too_big',
"{$name} has {$data} as value that is bigger than {$max}",
);
}
}
$is_valid = rest_validate_value_from_schema( $data, $schema, $name );
$error = is_wp_error( $is_valid ) ? $is_valid : null;
if ( $error ) {
if ( isset( $schema['default'] ) ) {
return $schema['default'];
}
return $error;
}
return rest_sanitize_value_from_schema( $data, $schema, $name );
}
/**
* Merge numeric arrays with default values and returns the union of
* the two arrays without repetitions.
*
* @param array $list Numeric array with values.
* @param array $default Default values for the list.
*
* @return array
*/
function wpct_plugin_merge_array( $list, $default ) {
if ( ! is_array( $list ) ) {
if ( is_array( $default ) ) {
return $default;
}
return array();
}
if ( ! is_array( $default ) ) {
return $list;
}
return array_values( array_unique( array_merge( $list, $default ) ) );
}
/**
* Merge collection of arrays with its defaults, apply defaults to
* each item of the collection and return the collection without
* repetitions.
*
* @param array $collection Input collection of arrays.
* @param array $default Default values for the collection.
* @param array $schema JSON schema of the collection.
*
* @return array
*/
function wpct_plugin_merge_collection( $collection, $default, $schema = array() ) {
if ( ! isset( $schema['type'] ) ) {
if ( isset( $default[0] ) ) {
$schema = array_merge(
$schema,
wpct_plugin_value_to_json_schema( $default[0] ),
);
} elseif ( isset( $collection[0] ) ) {
$schema = array_merge(
$schema,
wpct_plugin_value_to_json_schema( $collection[0] ),
);
} else {
return $collection;
}
}
if ( ! in_array( $schema['type'], array( 'array', 'object' ), true ) ) {
return wpct_plugin_merge_array( $collection, $default );
}
if ( 'object' === $schema['type'] ) {
foreach ( $default as $default_item ) {
$col_item = null;
$l = count( $collection );
for ( $i = 0; $i < $l; $i++ ) {
$col_item = $collection[ $i ];
if ( ! isset( $col_item['name'] ) ) {
continue;
}
if (
$col_item['name'] === $default_item['name'] &&
( $col_item['ref'] ?? false ) ===
( $default_item['ref'] ?? false )
) {
break;
}
}
$c = count( $collection );
if ( $i === $c ) {
$collection[] = $default_item;
} else {
$collection[ $i ] = wpct_plugin_merge_object(
$col_item,
$default_item,
$schema
);
}
}
// phpcs:disable Generic.CodeAnalysis.EmptyStatement
} elseif ( 'array' === $schema['type'] ) {
// TODO: Handle matrix case.
}
// phpcs:enable Generic.CodeAnalysis.EmptyStatement
return $collection;
}
/**
* Generic array default values merger. Switches between merge_collection and merge_list
* based on the list items' data type.
*
* @param array $array Input array.
* @param array $default Default array values.
* @param array $schema JSON schema of the array values.
*
* @return array Array fullfilled with defaults.
*/
function wpct_plugin_merge_object( $array, $default, $schema = array() ) {
foreach ( $default as $key => $default_value ) {
if ( empty( $array[ $key ] ) ) {
$array[ $key ] = $default_value;
} else {
$value = $array[ $key ];
$type = $schema['properties'][ $key ]['type']
?? wpct_plugin_get_json_schema_type( $default_value );
if ( 'object' === $type ) {
if ( ! is_array( $value ) || wp_is_numeric_array( $value ) ) {
$array[ $key ] = $default_value;
} else {
$array[ $key ] = wpct_plugin_merge_object(
$value,
$default_value,
$schema['properties'][ $key ] ?? array()
);
}
} elseif ( 'array' === $type ) {
if ( ! wp_is_numeric_array( $value ) ) {
$array[ $key ] = $default_value;
} else {
$array[ $key ] = wpct_plugin_merge_collection(
$value,
$default_value,
$schema['properties'][ $key ]['items'] ?? array()
);
}
}
}
}
if ( isset( $schema['properties'] ) ) {
foreach ( $array as $key => $value ) {
if ( ! isset( $schema['properties'][ $key ] ) ) {
unset( $array[ $key ] );
}
}
}
return $array;
}
/**
* Transform a PHP primitive value into a JSON schema.
*
* @param mixed $value Target value.
*
* @return array
*/
function wpct_plugin_value_to_json_schema( $value ) {
$schema = array( 'type' => wpct_plugin_get_json_schema_type( $value ) );
if ( 'array' === $schema['type'] ) {
if ( count( $value ) ) {
$schema['items'] = wpct_plugin_value_to_json_schema( $value[0] );
} else {
$schema['items'] = array( 'type' => 'null' );
}
} elseif ( 'object' === $schema['type'] ) {
$schema['properties'] = array();
foreach ( $value as $key => $val ) {
$schema['properties'][ $key ] = wpct_plugin_value_to_json_schema( $val );
}
}
return $schema;
}
/**
* Gets the corresponding JSON schema type from a given value.
*
* @param mixed $value Target value.
*
* @return string JSON schema value type.
*/
function wpct_plugin_get_json_schema_type( $value ) {
if ( wp_is_numeric_array( $value ) ) {
return 'array';
} elseif ( is_array( $value ) || is_object( $value ) ) {
return 'object';
} else {
$type = strtolower( gettype( $value ) );
if ( 'double' === $type ) {
$type = 'number';
}
return $type;
}
}
/**
* Remove private properties from an array based on a schema.
*
* @param array $data Target data.
* @param array $schema Data JSON schema.
*
* @return array Sanitized data.
*/
function wpct_plugin_prune_rest_private_properties( $data, $schema ) {
if ( $schema['anyOf'] ) {
$schema = rest_find_any_matching_schema( $data, $schema, '.' );
if ( is_wp_error( $schema ) ) {
return $data;
}
}
if ( $schema['oneOf'] ) {
$schema = rest_find_one_matching_schema( $data, $schema, '.' );
if ( is_wp_error( $schema ) ) {
return $data;
}
}
if ( ! isset( $schema['type'] ) ) {
return $data;
}
$public = boolval( $schema['public'] ?? true );
if ( ! $public ) {
return;
}
if ( 'object' === $schema['type'] ) {
if ( ! is_array( $data ) || ! isset( $schema['properties'] ) ) {
return $data;
}
foreach ( array_keys( $data ) as $prop ) {
$prop_schema = $schema['properties'][ $prop ] ?? array();
$value = wpct_plugin_prune_rest_private_properties(
$data[ $prop ],
$prop_schema
);
if ( ! $value && $value !== $data[ $prop ] ) {
unset( $data[ $prop ] );
}
}
} elseif ( 'array' === $schema['type'] ) {
if ( ! wp_is_numeric_array( $data ) || ! isset( $schema['items'] ) ) {
return $data;
}
if ( wp_is_numeric_array( $schema['items'] ) ) {
$items = $schema['items'];
} else {
$i = 0;
$l = count( $data );
while ( $i < $l ) {
$items[] = $schema['items'];
++$i;
}
}
$l = count( $data );
for ( $i = 0; $i < $l; $i++ ) {
$value = wpct_plugin_prune_rest_private_properties(
$data[ $i ],
$items[ $i ]
);
if ( ! $value && $data[ $i ] !== $value ) {
unset( $data[ $i ] );
}
}
$data = array_values( $data );
}
return $data;
}
/**
* Remove private properties from a JSON schema.
*
* @param array $schema Schema definition.
*
* @return array Sanitized schema.
*/
function wpct_plugin_prune_rest_private_schema_properties( $schema ) {
if ( is_array( $schema['anyOf'] ?? null ) ) {
$prop_schemas = array();
foreach ( $schema['anyOf'] as $prop_schema ) {
$prop_schema = wpct_plugin_prune_rest_private_schema_properties(
$prop_schema
);
if ( $prop_schema ) {
$schema['anyOf'][] = $prop_schema;
}
}
$schema['anyOf'] = array_values( $schema['anyOf'] );
} elseif ( is_array( $schema['oneOf'] ?? null ) ) {
$prop_schemas = array();
foreach ( $schema['oneOf'] as $prop_schema ) {
$prop_schema = wpct_plugin_prune_rest_private_schema_properties(
$prop_schema
);
if ( $prop_schema ) {
$prop_schemas = $prop_schema;
}
}
$schema['oneOf'] = $prop_schemas;
}
if ( ! isset( $schema['type'] ) ) {
return $schema;
}
$public = boolval( $schema['public'] ?? true );
if ( ! $public ) {
return;
}
if (
'object' === $schema['type'] &&
is_array( $schema['properties'] ?? null )
) {
foreach ( $schema['properties'] as $prop => $prop_schema ) {
$prop_schema = wpct_plugin_prune_rest_private_schema_properties(
$prop_schema
);
if ( ! $prop_schema ) {
unset( $schema['properties'][ $prop ] );
$schema['additionalProperties'] = true;
}
}
} elseif ( 'array' === $schema['type'] && isset( $schema['items'] ) ) {
if ( wp_is_numeric_array( $schema['items'] ) ) {
$schema_items = array();
foreach ( $schema['items'] as $schema_item ) {
$schema_item = wpct_plugin_prune_rest_private_schema_properties(
$schema_item
);
if ( $schema_item ) {
$schema_items[] = $schema_item;
} else {
$schema['additionalItems'] = true;
}
}
$schema['items'] = $schema_items;
} else {
$item_schema = wpct_plugin_prune_rest_private_schema_properties(
$schema['items']
);
if ( ! $item_schema ) {
return;
}
}
}
return $schema;
}
/**
* Search for diferences between two arrays.
*
* @param array $d1 Left side of the comparission.
* @param array $d2 Right side of the comparission.
*
* @return boolean True if some diff are found, false otherwise.
*
* @throws TypeError If non array value is passed as input param.
*/
function wpct_plugin_diff_arrays( $d1, $d2 ) {
if ( ! ( is_array( $d1 ) && is_array( $d2 ) ) ) {
throw new TypeError( 'Arguments should be arrays' );
}
$is_numeric = wp_is_numeric_array( $d1 );
if ( $is_numeric ) {
if ( ! wp_is_numeric_array( $d2 ) ) {
return true;
}
return wpct_plugin_diff_lists( $d1, $d2 );
}
foreach ( $d1 as $key => $v1 ) {
if ( ! isset( $d2[ $key ] ) ) {
return true;
}
$v2 = $d2[ $key ];
$t1 = gettype( $v1 );
$t2 = gettype( $v2 );
if ( $t1 !== $t2 ) {
return true;
}
if ( 'object' === $t1 ) {
$v1 = (array) $v1;
$v2 = (array) $v2;
}
if ( is_array( $v1 ) ) {
if ( wpct_plugin_diff_arrays( $v1, $v2 ) ) {
return true;
}
} elseif ( $v1 !== $v2 ) {
return true;
}
}
return false;
}
/**
* Search for diferences between two numeric arrays.
*
* @param array $l1 Left side of the comparission.
* @param array $l2 Right side of the comparission.
*
* @return boolean True if some diff are found, false otherwise.
*
* @throws TypeError If non array value is passed as input param.
*/
function wpct_plugin_diff_lists( $l1, $l2 ) {
if ( ! ( wp_is_numeric_array( $l1 ) && wp_is_numeric_array( $l2 ) ) ) {
throw new TypeError( 'Arguments should be numeric arrays' );
}
$c1 = count( $l1 );
$c2 = count( $l2 );
if ( $c1 !== $c2 ) {
return true;
}
for ( $i = 0; $i < $c1; ++$i ) {
$v1 = $l1[ $i ];
$v2 = $l2[ $i ];
$t1 = gettype( $v1 );
$t2 = gettype( $v2 );
if ( $t1 !== $t2 ) {
return true;
}
if ( 'object' === $t1 ) {
$v1 = (array) $v1;
$v2 = (array) $v2;
}
if ( is_array( $v1 ) ) {
if ( wpct_plugin_diff_arrays( $v1, $v2 ) ) {
return true;
}
} elseif ( $v1 !== $v2 ) {
return true;
}
}
return false;
}