|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | + |
| 6 | +use Constructo\Support\Metadata\Schema\Field\Formatter\MergeFormatter; |
| 7 | +use Constructo\Support\Metadata\Schema\Field\Formatter\PatternFormatter; |
| 8 | + |
| 9 | +$schemata = [ |
| 10 | + 'specs' => [ |
| 11 | + # Special setup |
| 12 | + 'bail' => [], |
| 13 | + 'sometimes' => [], |
| 14 | + |
| 15 | + # Requirements |
| 16 | + 'required_if' => [ |
| 17 | + 'params' => [ |
| 18 | + 'field', |
| 19 | + 'value', |
| 20 | + ], |
| 21 | + ], |
| 22 | + 'required_unless' => [ |
| 23 | + 'params' => [ |
| 24 | + 'field', |
| 25 | + 'value', |
| 26 | + ], |
| 27 | + ], |
| 28 | + 'required_with' => [ |
| 29 | + 'params' => '...', |
| 30 | + ], |
| 31 | + 'required_with_all' => [ |
| 32 | + 'params' => '...', |
| 33 | + ], |
| 34 | + 'required_without' => [ |
| 35 | + 'params' => '...', |
| 36 | + ], |
| 37 | + 'required_without_all' => [ |
| 38 | + 'params' => '...', |
| 39 | + ], |
| 40 | + 'required' => [], |
| 41 | + 'nullable' => [], |
| 42 | + 'filled' => [], |
| 43 | + 'present' => [], |
| 44 | + |
| 45 | + # Types |
| 46 | + 'string' => ['kind' => 'type'], |
| 47 | + 'integer' => ['kind' => 'type'], |
| 48 | + 'numeric' => ['kind' => 'type'], |
| 49 | + 'array' => ['kind' => 'type'], |
| 50 | + 'boolean' => ['kind' => 'type'], |
| 51 | + 'date' => ['kind' => 'type'], |
| 52 | + 'json' => ['kind' => 'type'], |
| 53 | + 'file' => ['kind' => 'type'], |
| 54 | + 'image' => ['kind' => 'type'], |
| 55 | + 'email' => ['kind' => 'type'], |
| 56 | + 'url' => ['kind' => 'type'], |
| 57 | + 'active_url' => ['kind' => 'type'], |
| 58 | + 'uuid' => ['kind' => 'type'], |
| 59 | + 'ip' => ['kind' => 'type'], |
| 60 | + 'ipv4' => ['kind' => 'type'], |
| 61 | + 'ipv6' => ['kind' => 'type'], |
| 62 | + 'timezone' => ['kind' => 'type'], |
| 63 | + |
| 64 | + # Constraints |
| 65 | + ## Numbers constraints |
| 66 | + 'min' => ['params' => ['min']], |
| 67 | + 'max' => ['params' => ['max']], |
| 68 | + 'between' => [ |
| 69 | + 'params' => [ |
| 70 | + 'min', |
| 71 | + 'max', |
| 72 | + ], |
| 73 | + ], |
| 74 | + 'digits' => ['params' => ['digits']], |
| 75 | + 'digits_between' => [ |
| 76 | + 'params' => [ |
| 77 | + 'min', |
| 78 | + 'max', |
| 79 | + ], |
| 80 | + ], |
| 81 | + ## Among fields constraints |
| 82 | + 'gt' => ['params' => ['field']], |
| 83 | + 'gte' => ['params' => ['field']], |
| 84 | + 'lt' => ['params' => ['field']], |
| 85 | + 'lte' => ['params' => ['field']], |
| 86 | + 'same' => ['params' => ['field']], |
| 87 | + 'different' => ['params' => ['field']], |
| 88 | + 'confirmed' => [], |
| 89 | + 'distinct' => [], |
| 90 | + 'in_array' => ['params' => ['field']], |
| 91 | + ## String constraints |
| 92 | + 'accepted' => [], |
| 93 | + 'alpha' => [], |
| 94 | + 'alpha_dash' => [], |
| 95 | + 'alpha_num' => [], |
| 96 | + 'starts_with' => [], |
| 97 | + ## Date constraints |
| 98 | + 'after' => ['params' => ['date']], |
| 99 | + 'after_or_equal' => ['params' => ['date']], |
| 100 | + 'before' => ['params' => ['date']], |
| 101 | + 'before_or_equal' => ['params' => ['date']], |
| 102 | + 'date_equals' => ['params' => ['date']], |
| 103 | + 'date_format' => ['params' => ['format']], |
| 104 | + ## Multiple types constraints |
| 105 | + 'size' => ['params' => ['size']], |
| 106 | + ## File constraints |
| 107 | + 'mimes' => ['params' => '...'], |
| 108 | + 'mimetypes' => ['params' => '...'], |
| 109 | + 'dimensions' => ['params' => '...'], |
| 110 | + |
| 111 | + # Database |
| 112 | + 'unique' => [ |
| 113 | + 'params' => [ |
| 114 | + 'table', |
| 115 | + 'column', |
| 116 | + 'except', |
| 117 | + 'id_column', |
| 118 | + ], |
| 119 | + ], |
| 120 | + 'exists' => [ |
| 121 | + 'params' => [ |
| 122 | + 'table', |
| 123 | + 'column', |
| 124 | + ], |
| 125 | + ], |
| 126 | + |
| 127 | + # Behaviors |
| 128 | + 'in' => [ |
| 129 | + 'formatter' => MergeFormatter::class, |
| 130 | + 'params' => ['items'], |
| 131 | + ], |
| 132 | + 'not_in' => [ |
| 133 | + 'formatter' => MergeFormatter::class, |
| 134 | + 'params' => ['items'], |
| 135 | + ], |
| 136 | + 'regex' => [ |
| 137 | + 'formatter' => PatternFormatter::class, |
| 138 | + 'params' => [ |
| 139 | + 'pattern', |
| 140 | + 'parameters:optional', |
| 141 | + ], |
| 142 | + ], |
| 143 | + 'not_regex' => [ |
| 144 | + 'formatter' => PatternFormatter::class, |
| 145 | + 'params' => [ |
| 146 | + 'pattern', |
| 147 | + 'parameters:optional', |
| 148 | + ], |
| 149 | + ], |
| 150 | + ], |
| 151 | + 'types' => [ |
| 152 | + 'DateTime' => 'date', |
| 153 | + 'DateTimeImmutable' => 'date', |
| 154 | + 'DateTimeInterface' => 'date', |
| 155 | + ], |
| 156 | +]; |
| 157 | + |
| 158 | +if (! defined('CONSTRUCTO_SCHEMATA')) { |
| 159 | + define('CONSTRUCTO_SCHEMATA', $schemata); |
| 160 | +} |
0 commit comments