create-prisma-php-app 3.4.3 → 3.4.5
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.
|
@@ -20,6 +20,8 @@ class MainLayout
|
|
|
20
20
|
private static ?Set $footerScripts = null;
|
|
21
21
|
private static array $customMetadata = [];
|
|
22
22
|
|
|
23
|
+
private static array $processedScripts = [];
|
|
24
|
+
|
|
23
25
|
public static function init(): void
|
|
24
26
|
{
|
|
25
27
|
if (self::$headScripts === null) {
|
|
@@ -28,6 +30,7 @@ class MainLayout
|
|
|
28
30
|
if (self::$footerScripts === null) {
|
|
29
31
|
self::$footerScripts = new Set();
|
|
30
32
|
}
|
|
33
|
+
self::$processedScripts = [];
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
/**
|
|
@@ -55,11 +58,19 @@ class MainLayout
|
|
|
55
58
|
$callerClass = $trace[1]['class'] ?? 'Unknown';
|
|
56
59
|
|
|
57
60
|
foreach ($scripts as $script) {
|
|
61
|
+
$scriptKey = md5(trim($script));
|
|
62
|
+
|
|
58
63
|
if (strpos($script, '<script') !== false) {
|
|
59
64
|
$taggedScript = "<!-- class:" . $callerClass . " -->\n" . $script;
|
|
60
|
-
self::$
|
|
65
|
+
if (!isset(self::$processedScripts[$scriptKey])) {
|
|
66
|
+
self::$footerScripts->add($taggedScript);
|
|
67
|
+
self::$processedScripts[$scriptKey] = true;
|
|
68
|
+
}
|
|
61
69
|
} else {
|
|
62
|
-
self::$
|
|
70
|
+
if (!isset(self::$processedScripts[$scriptKey])) {
|
|
71
|
+
self::$footerScripts->add($script);
|
|
72
|
+
self::$processedScripts[$scriptKey] = true;
|
|
73
|
+
}
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
}
|
|
@@ -97,6 +108,7 @@ class MainLayout
|
|
|
97
108
|
public static function outputFooterScripts(): string
|
|
98
109
|
{
|
|
99
110
|
$processed = [];
|
|
111
|
+
$componentCounter = 0;
|
|
100
112
|
|
|
101
113
|
foreach (self::$footerScripts->values() as $script) {
|
|
102
114
|
if (preg_match('/<!-- class:([^\s]+) -->/', $script, $matches)) {
|
|
@@ -106,9 +118,11 @@ class MainLayout
|
|
|
106
118
|
if (str_starts_with(trim($script), '<script')) {
|
|
107
119
|
$script = preg_replace_callback(
|
|
108
120
|
'/<script\b([^>]*)>/i',
|
|
109
|
-
function ($m) use ($rawClassName) {
|
|
121
|
+
function ($m) use ($rawClassName, &$componentCounter) {
|
|
110
122
|
$attrs = $m[1];
|
|
111
|
-
$
|
|
123
|
+
$scriptHash = substr(md5($m[0]), 0, 8);
|
|
124
|
+
$encodedClass = 's' . base_convert(sprintf('%u', crc32($rawClassName . $componentCounter . $scriptHash)), 10, 36);
|
|
125
|
+
$componentCounter++;
|
|
112
126
|
|
|
113
127
|
if (!str_contains($attrs, 'pp-component=')) {
|
|
114
128
|
$attrs .= " pp-component=\"{$encodedClass}\"";
|
|
@@ -150,6 +164,7 @@ class MainLayout
|
|
|
150
164
|
public static function clearFooterScripts(): void
|
|
151
165
|
{
|
|
152
166
|
self::$footerScripts->clear();
|
|
167
|
+
self::$processedScripts = [];
|
|
153
168
|
}
|
|
154
169
|
|
|
155
170
|
/**
|
|
@@ -118,9 +118,7 @@ class PHPX implements IPHPX
|
|
|
118
118
|
array_flip(array_merge($reserved, $exclude))
|
|
119
119
|
);
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
$props[$k] = $v;
|
|
123
|
-
}
|
|
121
|
+
$props = array_merge($params, $props);
|
|
124
122
|
|
|
125
123
|
$pairs = array_map(
|
|
126
124
|
static fn($k, $v) => sprintf(
|
|
@@ -245,10 +245,10 @@ class TypeCoercer
|
|
|
245
245
|
|
|
246
246
|
private static function isArrayLike(string $value): bool
|
|
247
247
|
{
|
|
248
|
-
return Validator::json($value)
|
|
249
|
-
str_contains($value, ',')
|
|
250
|
-
str_contains($value, '[')
|
|
251
|
-
str_contains($value, '{');
|
|
248
|
+
return Validator::json($value) === true
|
|
249
|
+
|| str_contains($value, ',')
|
|
250
|
+
|| str_contains($value, '[')
|
|
251
|
+
|| str_contains($value, '{');
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
private static function getNormalizedType(mixed $value): string
|
|
@@ -328,7 +328,7 @@ class TypeCoercer
|
|
|
328
328
|
return $value;
|
|
329
329
|
}
|
|
330
330
|
if (is_string($value)) {
|
|
331
|
-
if (Validator::json($value)) {
|
|
331
|
+
if (Validator::json($value) === true) {
|
|
332
332
|
$decoded = json_decode($value, true);
|
|
333
333
|
if (is_array($decoded)) {
|
|
334
334
|
return $decoded;
|
|
@@ -284,17 +284,21 @@ final class Validator
|
|
|
284
284
|
// Other Validation
|
|
285
285
|
|
|
286
286
|
/**
|
|
287
|
-
* Validate a JSON string.
|
|
287
|
+
* Validate a JSON string or convert an array to a JSON string.
|
|
288
288
|
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
289
|
+
* This function checks if the input is a valid JSON string. If it is, it returns the string.
|
|
290
|
+
* If the input is an array, it converts it to a JSON string with specific options.
|
|
291
|
+
* If the input is invalid, it returns an error message.
|
|
292
|
+
*
|
|
293
|
+
* @param mixed $value The value to validate or convert.
|
|
294
|
+
* @return string The valid JSON string or an error message if invalid.
|
|
291
295
|
*/
|
|
292
296
|
public static function json(mixed $value): string
|
|
293
297
|
{
|
|
294
298
|
if (is_string($value)) {
|
|
295
299
|
json_decode($value);
|
|
296
300
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
297
|
-
|
|
301
|
+
return json_last_error_msg();
|
|
298
302
|
}
|
|
299
303
|
return $value;
|
|
300
304
|
}
|