@@ -17,178 +17,178 @@ |
||
| 17 | 17 | * @since 30.0.0 |
| 18 | 18 | */ |
| 19 | 19 | enum EShapeType: int { |
| 20 | - case Number = 0; |
|
| 21 | - case Text = 1; |
|
| 22 | - case Image = 2; |
|
| 23 | - case Audio = 3; |
|
| 24 | - case Video = 4; |
|
| 25 | - case File = 5; |
|
| 26 | - case Enum = 6; |
|
| 27 | - case ListOfNumbers = 10; |
|
| 28 | - case ListOfTexts = 11; |
|
| 29 | - case ListOfImages = 12; |
|
| 30 | - case ListOfAudios = 13; |
|
| 31 | - case ListOfVideos = 14; |
|
| 32 | - case ListOfFiles = 15; |
|
| 20 | + case Number = 0; |
|
| 21 | + case Text = 1; |
|
| 22 | + case Image = 2; |
|
| 23 | + case Audio = 3; |
|
| 24 | + case Video = 4; |
|
| 25 | + case File = 5; |
|
| 26 | + case Enum = 6; |
|
| 27 | + case ListOfNumbers = 10; |
|
| 28 | + case ListOfTexts = 11; |
|
| 29 | + case ListOfImages = 12; |
|
| 30 | + case ListOfAudios = 13; |
|
| 31 | + case ListOfVideos = 14; |
|
| 32 | + case ListOfFiles = 15; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param mixed $value |
|
| 36 | - * @param ShapeEnumValue[] $enumValues |
|
| 37 | - * @return void |
|
| 38 | - * @throws ValidationException |
|
| 39 | - * @since 30.0.0 |
|
| 40 | - */ |
|
| 41 | - public function validateEnum(mixed $value, array $enumValues): void { |
|
| 42 | - if ($this !== EShapeType::Enum) { |
|
| 43 | - throw new ValidationException('Provider provided enum values for non-enum slot'); |
|
| 44 | - } |
|
| 45 | - foreach ($enumValues as $enumValue) { |
|
| 46 | - if ($value === $enumValue->getValue()) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - throw new ValidationException('Wrong value given for Enum slot. Got "' . $value . '", but expected one of the provided enum values: "' . implode('", "', array_map(fn ($enumValue) => $enumValue->getValue(), $enumValues)) . '"'); |
|
| 51 | - } |
|
| 34 | + /** |
|
| 35 | + * @param mixed $value |
|
| 36 | + * @param ShapeEnumValue[] $enumValues |
|
| 37 | + * @return void |
|
| 38 | + * @throws ValidationException |
|
| 39 | + * @since 30.0.0 |
|
| 40 | + */ |
|
| 41 | + public function validateEnum(mixed $value, array $enumValues): void { |
|
| 42 | + if ($this !== EShapeType::Enum) { |
|
| 43 | + throw new ValidationException('Provider provided enum values for non-enum slot'); |
|
| 44 | + } |
|
| 45 | + foreach ($enumValues as $enumValue) { |
|
| 46 | + if ($value === $enumValue->getValue()) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + throw new ValidationException('Wrong value given for Enum slot. Got "' . $value . '", but expected one of the provided enum values: "' . implode('", "', array_map(fn ($enumValue) => $enumValue->getValue(), $enumValues)) . '"'); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param mixed $value |
|
| 55 | - * @return void |
|
| 56 | - * @throws ValidationException |
|
| 57 | - * @since 30.0.0 |
|
| 58 | - */ |
|
| 59 | - private function validateNonFileType(mixed $value): void { |
|
| 60 | - if ($this === EShapeType::Enum && !is_string($value)) { |
|
| 61 | - throw new ValidationException('Non-text item provided for Enum slot'); |
|
| 62 | - } |
|
| 63 | - if ($this === EShapeType::Text && !is_string($value)) { |
|
| 64 | - throw new ValidationException('Non-text item provided for Text slot'); |
|
| 65 | - } |
|
| 66 | - if ($this === EShapeType::ListOfTexts && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 67 | - throw new ValidationException('Non-text list item provided for ListOfTexts slot'); |
|
| 68 | - } |
|
| 69 | - if ($this === EShapeType::Number && !is_numeric($value)) { |
|
| 70 | - throw new ValidationException('Non-numeric item provided for Number slot'); |
|
| 71 | - } |
|
| 72 | - if ($this === EShapeType::ListOfNumbers && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 73 | - throw new ValidationException('Non-numeric list item provided for ListOfNumbers slot'); |
|
| 74 | - } |
|
| 75 | - } |
|
| 53 | + /** |
|
| 54 | + * @param mixed $value |
|
| 55 | + * @return void |
|
| 56 | + * @throws ValidationException |
|
| 57 | + * @since 30.0.0 |
|
| 58 | + */ |
|
| 59 | + private function validateNonFileType(mixed $value): void { |
|
| 60 | + if ($this === EShapeType::Enum && !is_string($value)) { |
|
| 61 | + throw new ValidationException('Non-text item provided for Enum slot'); |
|
| 62 | + } |
|
| 63 | + if ($this === EShapeType::Text && !is_string($value)) { |
|
| 64 | + throw new ValidationException('Non-text item provided for Text slot'); |
|
| 65 | + } |
|
| 66 | + if ($this === EShapeType::ListOfTexts && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 67 | + throw new ValidationException('Non-text list item provided for ListOfTexts slot'); |
|
| 68 | + } |
|
| 69 | + if ($this === EShapeType::Number && !is_numeric($value)) { |
|
| 70 | + throw new ValidationException('Non-numeric item provided for Number slot'); |
|
| 71 | + } |
|
| 72 | + if ($this === EShapeType::ListOfNumbers && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 73 | + throw new ValidationException('Non-numeric list item provided for ListOfNumbers slot'); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @param mixed $value |
|
| 79 | - * @return void |
|
| 80 | - * @throws Exception\ValidationException |
|
| 81 | - * @since 30.0.0 |
|
| 82 | - */ |
|
| 83 | - public function validateInput(mixed $value): void { |
|
| 84 | - $this->validateNonFileType($value); |
|
| 85 | - if ($this === EShapeType::Image && !is_numeric($value)) { |
|
| 86 | - throw new ValidationException('Non-image item provided for Image slot'); |
|
| 87 | - } |
|
| 88 | - if ($this === EShapeType::ListOfImages && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 89 | - throw new ValidationException('Non-image list item provided for ListOfImages slot'); |
|
| 90 | - } |
|
| 91 | - if ($this === EShapeType::Audio && !is_numeric($value)) { |
|
| 92 | - throw new ValidationException('Non-audio item provided for Audio slot'); |
|
| 93 | - } |
|
| 94 | - if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 95 | - throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); |
|
| 96 | - } |
|
| 97 | - if ($this === EShapeType::Video && !is_numeric($value)) { |
|
| 98 | - throw new ValidationException('Non-video item provided for Video slot'); |
|
| 99 | - } |
|
| 100 | - if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 101 | - throw new ValidationException('Non-video list item provided for ListOfTexts slot'); |
|
| 102 | - } |
|
| 103 | - if ($this === EShapeType::File && !is_numeric($value)) { |
|
| 104 | - throw new ValidationException('Non-file item provided for File slot'); |
|
| 105 | - } |
|
| 106 | - if ($this === EShapeType::ListOfFiles && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 107 | - throw new ValidationException('Non-audio list item provided for ListOfFiles slot'); |
|
| 108 | - } |
|
| 109 | - } |
|
| 77 | + /** |
|
| 78 | + * @param mixed $value |
|
| 79 | + * @return void |
|
| 80 | + * @throws Exception\ValidationException |
|
| 81 | + * @since 30.0.0 |
|
| 82 | + */ |
|
| 83 | + public function validateInput(mixed $value): void { |
|
| 84 | + $this->validateNonFileType($value); |
|
| 85 | + if ($this === EShapeType::Image && !is_numeric($value)) { |
|
| 86 | + throw new ValidationException('Non-image item provided for Image slot'); |
|
| 87 | + } |
|
| 88 | + if ($this === EShapeType::ListOfImages && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 89 | + throw new ValidationException('Non-image list item provided for ListOfImages slot'); |
|
| 90 | + } |
|
| 91 | + if ($this === EShapeType::Audio && !is_numeric($value)) { |
|
| 92 | + throw new ValidationException('Non-audio item provided for Audio slot'); |
|
| 93 | + } |
|
| 94 | + if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 95 | + throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); |
|
| 96 | + } |
|
| 97 | + if ($this === EShapeType::Video && !is_numeric($value)) { |
|
| 98 | + throw new ValidationException('Non-video item provided for Video slot'); |
|
| 99 | + } |
|
| 100 | + if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 101 | + throw new ValidationException('Non-video list item provided for ListOfTexts slot'); |
|
| 102 | + } |
|
| 103 | + if ($this === EShapeType::File && !is_numeric($value)) { |
|
| 104 | + throw new ValidationException('Non-file item provided for File slot'); |
|
| 105 | + } |
|
| 106 | + if ($this === EShapeType::ListOfFiles && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 107 | + throw new ValidationException('Non-audio list item provided for ListOfFiles slot'); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @throws ValidationException |
|
| 113 | - * @since 30.0.0 |
|
| 114 | - */ |
|
| 115 | - public function validateOutputWithFileData(mixed $value): void { |
|
| 116 | - $this->validateNonFileType($value); |
|
| 117 | - if ($this === EShapeType::Image && !is_string($value)) { |
|
| 118 | - throw new ValidationException('Non-image item provided for Image slot'); |
|
| 119 | - } |
|
| 120 | - if ($this === EShapeType::ListOfImages && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 121 | - throw new ValidationException('Non-image list item provided for ListOfImages slot'); |
|
| 122 | - } |
|
| 123 | - if ($this === EShapeType::Audio && !is_string($value)) { |
|
| 124 | - throw new ValidationException('Non-audio item provided for Audio slot'); |
|
| 125 | - } |
|
| 126 | - if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 127 | - throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); |
|
| 128 | - } |
|
| 129 | - if ($this === EShapeType::Video && !is_string($value)) { |
|
| 130 | - throw new ValidationException('Non-video item provided for Video slot'); |
|
| 131 | - } |
|
| 132 | - if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 133 | - throw new ValidationException('Non-video list item provided for ListOfTexts slot'); |
|
| 134 | - } |
|
| 135 | - if ($this === EShapeType::File && !is_string($value)) { |
|
| 136 | - throw new ValidationException('Non-file item provided for File slot'); |
|
| 137 | - } |
|
| 138 | - if ($this === EShapeType::ListOfFiles && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 139 | - throw new ValidationException('Non-audio list item provided for ListOfFiles slot'); |
|
| 140 | - } |
|
| 141 | - } |
|
| 111 | + /** |
|
| 112 | + * @throws ValidationException |
|
| 113 | + * @since 30.0.0 |
|
| 114 | + */ |
|
| 115 | + public function validateOutputWithFileData(mixed $value): void { |
|
| 116 | + $this->validateNonFileType($value); |
|
| 117 | + if ($this === EShapeType::Image && !is_string($value)) { |
|
| 118 | + throw new ValidationException('Non-image item provided for Image slot'); |
|
| 119 | + } |
|
| 120 | + if ($this === EShapeType::ListOfImages && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 121 | + throw new ValidationException('Non-image list item provided for ListOfImages slot'); |
|
| 122 | + } |
|
| 123 | + if ($this === EShapeType::Audio && !is_string($value)) { |
|
| 124 | + throw new ValidationException('Non-audio item provided for Audio slot'); |
|
| 125 | + } |
|
| 126 | + if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 127 | + throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); |
|
| 128 | + } |
|
| 129 | + if ($this === EShapeType::Video && !is_string($value)) { |
|
| 130 | + throw new ValidationException('Non-video item provided for Video slot'); |
|
| 131 | + } |
|
| 132 | + if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 133 | + throw new ValidationException('Non-video list item provided for ListOfTexts slot'); |
|
| 134 | + } |
|
| 135 | + if ($this === EShapeType::File && !is_string($value)) { |
|
| 136 | + throw new ValidationException('Non-file item provided for File slot'); |
|
| 137 | + } |
|
| 138 | + if ($this === EShapeType::ListOfFiles && (!is_array($value) || count(array_filter($value, fn ($item) => !is_string($item))) > 0)) { |
|
| 139 | + throw new ValidationException('Non-audio list item provided for ListOfFiles slot'); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * @param mixed $value |
|
| 145 | - * @return void |
|
| 146 | - * @throws ValidationException |
|
| 147 | - * @since 30.0.0 |
|
| 148 | - */ |
|
| 149 | - public function validateOutputWithFileIds(mixed $value): void { |
|
| 150 | - $this->validateNonFileType($value); |
|
| 151 | - if ($this === EShapeType::Image && !is_numeric($value)) { |
|
| 152 | - throw new ValidationException('Non-image item provided for Image slot'); |
|
| 153 | - } |
|
| 154 | - if ($this === EShapeType::ListOfImages && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 155 | - throw new ValidationException('Non-image list item provided for ListOfImages slot'); |
|
| 156 | - } |
|
| 157 | - if ($this === EShapeType::Audio && !is_numeric($value)) { |
|
| 158 | - throw new ValidationException('Non-audio item provided for Audio slot'); |
|
| 159 | - } |
|
| 160 | - if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 161 | - throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); |
|
| 162 | - } |
|
| 163 | - if ($this === EShapeType::Video && !is_numeric($value)) { |
|
| 164 | - throw new ValidationException('Non-video item provided for Video slot'); |
|
| 165 | - } |
|
| 166 | - if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 167 | - throw new ValidationException('Non-video list item provided for ListOfTexts slot'); |
|
| 168 | - } |
|
| 169 | - if ($this === EShapeType::File && !is_numeric($value)) { |
|
| 170 | - throw new ValidationException('Non-file item provided for File slot'); |
|
| 171 | - } |
|
| 172 | - if ($this === EShapeType::ListOfFiles && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 173 | - throw new ValidationException('Non-audio list item provided for ListOfFiles slot'); |
|
| 174 | - } |
|
| 175 | - } |
|
| 143 | + /** |
|
| 144 | + * @param mixed $value |
|
| 145 | + * @return void |
|
| 146 | + * @throws ValidationException |
|
| 147 | + * @since 30.0.0 |
|
| 148 | + */ |
|
| 149 | + public function validateOutputWithFileIds(mixed $value): void { |
|
| 150 | + $this->validateNonFileType($value); |
|
| 151 | + if ($this === EShapeType::Image && !is_numeric($value)) { |
|
| 152 | + throw new ValidationException('Non-image item provided for Image slot'); |
|
| 153 | + } |
|
| 154 | + if ($this === EShapeType::ListOfImages && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 155 | + throw new ValidationException('Non-image list item provided for ListOfImages slot'); |
|
| 156 | + } |
|
| 157 | + if ($this === EShapeType::Audio && !is_numeric($value)) { |
|
| 158 | + throw new ValidationException('Non-audio item provided for Audio slot'); |
|
| 159 | + } |
|
| 160 | + if ($this === EShapeType::ListOfAudios && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 161 | + throw new ValidationException('Non-audio list item provided for ListOfAudio slot'); |
|
| 162 | + } |
|
| 163 | + if ($this === EShapeType::Video && !is_numeric($value)) { |
|
| 164 | + throw new ValidationException('Non-video item provided for Video slot'); |
|
| 165 | + } |
|
| 166 | + if ($this === EShapeType::ListOfVideos && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 167 | + throw new ValidationException('Non-video list item provided for ListOfTexts slot'); |
|
| 168 | + } |
|
| 169 | + if ($this === EShapeType::File && !is_numeric($value)) { |
|
| 170 | + throw new ValidationException('Non-file item provided for File slot'); |
|
| 171 | + } |
|
| 172 | + if ($this === EShapeType::ListOfFiles && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) { |
|
| 173 | + throw new ValidationException('Non-audio list item provided for ListOfFiles slot'); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * @param EShapeType $type |
|
| 179 | - * @return EShapeType |
|
| 180 | - * @since 30.0.0 |
|
| 181 | - */ |
|
| 182 | - public static function getScalarType(EShapeType $type): EShapeType { |
|
| 183 | - return EShapeType::from($type->value % 10); |
|
| 184 | - } |
|
| 177 | + /** |
|
| 178 | + * @param EShapeType $type |
|
| 179 | + * @return EShapeType |
|
| 180 | + * @since 30.0.0 |
|
| 181 | + */ |
|
| 182 | + public static function getScalarType(EShapeType $type): EShapeType { |
|
| 183 | + return EShapeType::from($type->value % 10); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * @param EShapeType $type |
|
| 188 | - * @return bool |
|
| 189 | - * @since 30.0.0 |
|
| 190 | - */ |
|
| 191 | - public static function isFileType(EShapeType $type): bool { |
|
| 192 | - return in_array(EShapeType::getScalarType($type), [EShapeType::File, EShapeType::Image, EShapeType::Audio, EShapeType::Video], true); |
|
| 193 | - } |
|
| 186 | + /** |
|
| 187 | + * @param EShapeType $type |
|
| 188 | + * @return bool |
|
| 189 | + * @since 30.0.0 |
|
| 190 | + */ |
|
| 191 | + public static function isFileType(EShapeType $type): bool { |
|
| 192 | + return in_array(EShapeType::getScalarType($type), [EShapeType::File, EShapeType::Image, EShapeType::Audio, EShapeType::Video], true); |
|
| 193 | + } |
|
| 194 | 194 | } |