prisma-client-php 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/init.js
CHANGED
|
@@ -202,7 +202,7 @@ const composerPinnedVersions = {
|
|
|
202
202
|
"ezyang/htmlpurifier": "^4.18.0",
|
|
203
203
|
"calicastle/cuid": "^2.0.0",
|
|
204
204
|
"symfony/uid": "^7.2.0",
|
|
205
|
-
"brick/math": "^0.13.
|
|
205
|
+
"brick/math": "^0.13.1",
|
|
206
206
|
};
|
|
207
207
|
function composerPkg(name) {
|
|
208
208
|
return composerPinnedVersions[name]
|
|
@@ -4,14 +4,9 @@ namespace Lib\Prisma\Classes;
|
|
|
4
4
|
|
|
5
5
|
use Lib\Validator;
|
|
6
6
|
use ReflectionClass;
|
|
7
|
-
use InvalidArgumentException;
|
|
8
|
-
use DateTime;
|
|
9
|
-
use Brick\Math\BigDecimal;
|
|
10
|
-
use Brick\Math\BigInteger;
|
|
11
|
-
use ReflectionUnionType;
|
|
12
|
-
use ReflectionNamedType;
|
|
13
7
|
use Exception;
|
|
14
8
|
use PDO;
|
|
9
|
+
use UnitEnum;
|
|
15
10
|
|
|
16
11
|
enum ArrayType: string
|
|
17
12
|
{
|
|
@@ -357,6 +352,28 @@ final class PPHPUtility
|
|
|
357
352
|
|
|
358
353
|
if (is_array($value)) {
|
|
359
354
|
foreach ($value as $condition => $val) {
|
|
355
|
+
|
|
356
|
+
$enumAllowed = ['equals', 'not', 'in', 'notIn'];
|
|
357
|
+
$unsupported = ['contains', 'startsWith', 'endsWith', 'gt', 'gte', 'lt', 'lte'];
|
|
358
|
+
|
|
359
|
+
$castEnum = static function ($v) use ($condition, $key, $enumAllowed, $unsupported) {
|
|
360
|
+
if ($v instanceof UnitEnum) {
|
|
361
|
+
if (in_array($condition, $unsupported, true)) {
|
|
362
|
+
$msg = "Operator '$condition' is not supported for enum field '$key'. ";
|
|
363
|
+
$msg .= 'Allowed operators: ' . implode(', ', $enumAllowed) . '.';
|
|
364
|
+
throw new Exception($msg);
|
|
365
|
+
}
|
|
366
|
+
return $v->value;
|
|
367
|
+
}
|
|
368
|
+
return $v;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
if (in_array($condition, ['in', 'notIn'], true)) {
|
|
372
|
+
$val = array_map($castEnum, $val);
|
|
373
|
+
} else {
|
|
374
|
+
$val = $castEnum($val);
|
|
375
|
+
}
|
|
376
|
+
|
|
360
377
|
$bindingKey = ":" . $prefix . $key . "_" . $condition . $level;
|
|
361
378
|
switch ($condition) {
|
|
362
379
|
case 'contains':
|
|
@@ -419,6 +436,10 @@ final class PPHPUtility
|
|
|
419
436
|
} elseif ($value === '') {
|
|
420
437
|
$sqlConditions[] = "$qualifiedField = ''";
|
|
421
438
|
} else {
|
|
439
|
+
if ($value instanceof UnitEnum) {
|
|
440
|
+
$value = $value->value;
|
|
441
|
+
}
|
|
442
|
+
|
|
422
443
|
$bindingKey = ":" . $prefix . $key . $level;
|
|
423
444
|
$validatedValue = Validator::string($value, false);
|
|
424
445
|
$sqlConditions[] = "$qualifiedField = $bindingKey";
|
|
@@ -906,13 +927,26 @@ final class PPHPUtility
|
|
|
906
927
|
$modelFieldData[$modelClass->_primaryKey] = $existingParent->{$modelClass->_primaryKey};
|
|
907
928
|
}
|
|
908
929
|
|
|
930
|
+
$relatedId = $relatedFieldData[$relatedClass->_primaryKey];
|
|
931
|
+
$modelId = $modelFieldData[$modelClass->_primaryKey];
|
|
932
|
+
|
|
933
|
+
$implicit = self::compareStringsAlphabetically($modelRelatedFieldType, $modelName);
|
|
934
|
+
|
|
935
|
+
if ($implicit['A'] === $modelName) {
|
|
936
|
+
$idA = $modelId;
|
|
937
|
+
$idB = $relatedId;
|
|
938
|
+
} else {
|
|
939
|
+
$idA = $relatedId;
|
|
940
|
+
$idB = $modelId;
|
|
941
|
+
}
|
|
942
|
+
|
|
909
943
|
$relatedResult = self::handleImplicitRelationInsert(
|
|
910
944
|
$modelName,
|
|
911
945
|
$modelRelatedFieldType,
|
|
912
946
|
$dbType,
|
|
913
947
|
$pdo,
|
|
914
|
-
$
|
|
915
|
-
$
|
|
948
|
+
$idA,
|
|
949
|
+
$idB
|
|
916
950
|
);
|
|
917
951
|
} else {
|
|
918
952
|
if (!$modelRelatedFieldIsList && count($operations) > 1) {
|
|
@@ -14,6 +14,8 @@ use Brick\Math\BigDecimal;
|
|
|
14
14
|
use Brick\Math\BigInteger;
|
|
15
15
|
use Brick\Math\Exception\MathException;
|
|
16
16
|
use Brick\Math\RoundingMode;
|
|
17
|
+
use InvalidArgumentException;
|
|
18
|
+
use BackedEnum;
|
|
17
19
|
|
|
18
20
|
final class Validator
|
|
19
21
|
{
|
|
@@ -305,6 +307,44 @@ final class Validator
|
|
|
305
307
|
return in_array($value, $allowedValues, true);
|
|
306
308
|
}
|
|
307
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Validates and casts a value (or array of values) of a native enum.
|
|
312
|
+
*
|
|
313
|
+
* @template T of BackedEnum
|
|
314
|
+
* @param string|int|T|array<string|int|T> $value String, integer, instance, or array.
|
|
315
|
+
* @param class-string<T> $enumClass Enum class name.
|
|
316
|
+
* @return string|int|array<string|int>|null Backed value(s) or null if any is invalid.
|
|
317
|
+
* @throws InvalidArgumentException If the class is not an enum.
|
|
318
|
+
*/
|
|
319
|
+
public static function enumClass(mixed $value, string $enumClass): string|int|array|null
|
|
320
|
+
{
|
|
321
|
+
if (!enum_exists($enumClass)) {
|
|
322
|
+
throw new InvalidArgumentException("Enum '$enumClass' not found.");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
$cast = static function ($v) use ($enumClass) {
|
|
326
|
+
if (is_object($v) && $v instanceof $enumClass && property_exists($v, 'value')) {
|
|
327
|
+
return $v->value;
|
|
328
|
+
}
|
|
329
|
+
$inst = $enumClass::tryFrom($v);
|
|
330
|
+
return $inst?->value;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
if (is_array($value)) {
|
|
334
|
+
$out = [];
|
|
335
|
+
foreach ($value as $item) {
|
|
336
|
+
$val = $cast($item);
|
|
337
|
+
if ($val === null) {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
$out[] = $val;
|
|
341
|
+
}
|
|
342
|
+
return $out;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return $cast($value);
|
|
346
|
+
}
|
|
347
|
+
|
|
308
348
|
/**
|
|
309
349
|
* Purify and sanitize HTML content.
|
|
310
350
|
*
|
|
@@ -647,7 +687,7 @@ final class Validator
|
|
|
647
687
|
return true;
|
|
648
688
|
}
|
|
649
689
|
break;
|
|
650
|
-
|
|
690
|
+
// Add additional rules as needed...
|
|
651
691
|
default:
|
|
652
692
|
return true;
|
|
653
693
|
}
|
package/package.json
CHANGED