create-prisma-php-app 4.0.0-alpha.50 → 4.0.0-alpha.51
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/bootstrap.php +1 -1
- package/dist/index.js +1 -1
- package/dist/src/Lib/ErrorHandler.php +1 -1
- package/dist/src/Lib/IncludeTracker.php +1 -1
- package/package.json +1 -1
- package/dist/src/Lib/PHPX/Exceptions/ComponentValidationException.php +0 -49
- package/dist/src/Lib/PHPX/Fragment.php +0 -32
- package/dist/src/Lib/PHPX/IPHPX.php +0 -22
- package/dist/src/Lib/PHPX/PHPX.php +0 -287
- package/dist/src/Lib/PHPX/TemplateCompiler.php +0 -663
- package/dist/src/Lib/PHPX/TwMerge.php +0 -346
- package/dist/src/Lib/PHPX/TypeCoercer.php +0 -490
package/dist/bootstrap.php
CHANGED
package/dist/index.js
CHANGED
|
@@ -533,7 +533,7 @@ async function main() {
|
|
|
533
533
|
composerPkg("ezyang/htmlpurifier"),
|
|
534
534
|
composerPkg("symfony/uid"),
|
|
535
535
|
composerPkg("brick/math"),
|
|
536
|
-
|
|
536
|
+
composerPkg("tsnc/prisma-php"),
|
|
537
537
|
];
|
|
538
538
|
if (answer.swaggerDocs) {
|
|
539
539
|
npmDependencies.push(
|
package/package.json
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
namespace Lib\PHPX\Exceptions;
|
|
4
|
-
|
|
5
|
-
use RuntimeException;
|
|
6
|
-
|
|
7
|
-
class ComponentValidationException extends RuntimeException
|
|
8
|
-
{
|
|
9
|
-
private string $propName;
|
|
10
|
-
private string $componentName;
|
|
11
|
-
private array $availableProps;
|
|
12
|
-
|
|
13
|
-
public function __construct(
|
|
14
|
-
string $propName,
|
|
15
|
-
string $componentName,
|
|
16
|
-
array $availableProps,
|
|
17
|
-
string $context = ''
|
|
18
|
-
) {
|
|
19
|
-
$this->propName = $propName;
|
|
20
|
-
$this->componentName = $componentName;
|
|
21
|
-
$this->availableProps = $availableProps;
|
|
22
|
-
|
|
23
|
-
$availableList = implode(', ', $availableProps);
|
|
24
|
-
|
|
25
|
-
$message = "Invalid prop '{$propName}' for component '{$componentName}'.\n";
|
|
26
|
-
$message .= "Available props: {$availableList}";
|
|
27
|
-
|
|
28
|
-
if ($context) {
|
|
29
|
-
$message .= "\n{$context}";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
parent::__construct($message);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public function getPropName(): string
|
|
36
|
-
{
|
|
37
|
-
return $this->propName;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public function getComponentName(): string
|
|
41
|
-
{
|
|
42
|
-
return $this->componentName;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public function getAvailableProps(): array
|
|
46
|
-
{
|
|
47
|
-
return $this->availableProps;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Lib\PHPX;
|
|
6
|
-
|
|
7
|
-
use Lib\PHPX\PHPX;
|
|
8
|
-
|
|
9
|
-
class Fragment extends PHPX
|
|
10
|
-
{
|
|
11
|
-
/** @property ?string $as = div|span|section|article|nav|header|footer|main|aside */
|
|
12
|
-
public ?string $as = null;
|
|
13
|
-
public ?string $class = '';
|
|
14
|
-
|
|
15
|
-
public function __construct(array $props = [])
|
|
16
|
-
{
|
|
17
|
-
parent::__construct($props);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public function render(): string
|
|
21
|
-
{
|
|
22
|
-
if ($this->as !== null) {
|
|
23
|
-
$attributes = $this->getAttributes();
|
|
24
|
-
$class = $this->getMergeClasses($this->class);
|
|
25
|
-
$classAttr = $class ? "class=\"{$class}\"" : '';
|
|
26
|
-
|
|
27
|
-
return "<{$this->as} {$classAttr} {$attributes}>{$this->children}</{$this->as}>";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return $this->children;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Lib\PHPX;
|
|
6
|
-
|
|
7
|
-
interface IPHPX
|
|
8
|
-
{
|
|
9
|
-
/**
|
|
10
|
-
* Constructor to initialize the component with the given properties.
|
|
11
|
-
*
|
|
12
|
-
* @param array<string, mixed> $props Optional properties to customize the component.
|
|
13
|
-
*/
|
|
14
|
-
public function __construct(array $props = []);
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Renders the component with the given properties and children.
|
|
18
|
-
*
|
|
19
|
-
* @return string The rendered HTML content.
|
|
20
|
-
*/
|
|
21
|
-
public function render(): string;
|
|
22
|
-
}
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Lib\PHPX;
|
|
6
|
-
|
|
7
|
-
use Lib\PHPX\IPHPX;
|
|
8
|
-
use Lib\PHPX\TwMerge;
|
|
9
|
-
use Lib\PrismaPHPSettings;
|
|
10
|
-
use Exception;
|
|
11
|
-
|
|
12
|
-
class PHPX implements IPHPX
|
|
13
|
-
{
|
|
14
|
-
/**
|
|
15
|
-
* @var array<string, mixed> The properties or attributes passed to the component.
|
|
16
|
-
*/
|
|
17
|
-
protected array $props;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @var mixed The children elements or content to be rendered within the component.
|
|
21
|
-
*/
|
|
22
|
-
public mixed $children;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @var array<string, mixed> The array representation of the HTML attributes.
|
|
26
|
-
*/
|
|
27
|
-
protected array $attributesArray = [];
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @var array|null Component hierarchy set during rendering
|
|
31
|
-
*/
|
|
32
|
-
protected static ?array $currentHierarchy = null;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @var string|null Current component ID
|
|
36
|
-
*/
|
|
37
|
-
protected static ?string $currentComponentId = null;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Constructor to initialize the component with the given properties.
|
|
41
|
-
*
|
|
42
|
-
* @param array<string, mixed> $props Optional properties to customize the component.
|
|
43
|
-
*/
|
|
44
|
-
public function __construct(array $props = [])
|
|
45
|
-
{
|
|
46
|
-
$this->props = $props;
|
|
47
|
-
$this->children = $props['children'] ?? '';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Convert a property name to a JavaScript variable path.
|
|
52
|
-
*
|
|
53
|
-
* This method generates a JavaScript variable path for the given property name,
|
|
54
|
-
* based on the current component hierarchy. It is used to access properties in
|
|
55
|
-
* the JavaScript context of the component.
|
|
56
|
-
*
|
|
57
|
-
* @param string $name The property name to convert.
|
|
58
|
-
* @return string The JavaScript variable path for the property.
|
|
59
|
-
*/
|
|
60
|
-
protected function propsAsVar(string $name): string
|
|
61
|
-
{
|
|
62
|
-
if (empty($name)) {
|
|
63
|
-
return '';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
$hierarchy = $this->getComponentHierarchy();
|
|
67
|
-
|
|
68
|
-
if (count($hierarchy) > 1 && end($hierarchy) === self::$currentComponentId) {
|
|
69
|
-
array_pop($hierarchy);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return "pphp.props." . implode('.', $hierarchy) . ".{$name}";
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Emit a client-side dispatch call.
|
|
77
|
-
*
|
|
78
|
-
* @param non-empty-string|null $name Reactive key (e.g. "myVar", "voucher.total", or "app.s9ggniz.myVar").
|
|
79
|
-
* @param string $value Raw JS inserted verbatim (variable, expression, or pre-JSON-encoded value).
|
|
80
|
-
* @param array{
|
|
81
|
-
* scope?: 'current'|'parent'|'root'|string[]
|
|
82
|
-
* } $options Dispatch options (defaults to ['scope' => 'current']).
|
|
83
|
-
*
|
|
84
|
-
* @return string JavaScript snippet like: pphp.dispatchEvent("myVar", 123, {"scope":"current"});
|
|
85
|
-
*/
|
|
86
|
-
protected function dispatchEvent(?string $name, string $value, array $options = []): string
|
|
87
|
-
{
|
|
88
|
-
$name = trim((string) $name);
|
|
89
|
-
if ($name === '') {
|
|
90
|
-
return '';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// normalize options
|
|
94
|
-
$opts = $options;
|
|
95
|
-
if (!array_key_exists('scope', $opts)) {
|
|
96
|
-
$opts['scope'] = 'current';
|
|
97
|
-
} else {
|
|
98
|
-
if (is_string($opts['scope'])) {
|
|
99
|
-
$allowed = ['current', 'parent', 'root'];
|
|
100
|
-
if (!in_array($opts['scope'], $allowed, true)) {
|
|
101
|
-
$opts['scope'] = 'current';
|
|
102
|
-
}
|
|
103
|
-
} elseif (is_array($opts['scope'])) {
|
|
104
|
-
$opts['scope'] = array_values(array_map('strval', $opts['scope']));
|
|
105
|
-
} else {
|
|
106
|
-
$opts['scope'] = 'current';
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// safely encode name/options; value is inserted verbatim
|
|
111
|
-
$jsName = json_encode($name, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
112
|
-
$jsOpts = json_encode($opts, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
113
|
-
|
|
114
|
-
return "pphp.dispatchEvent({$jsName}, {$value}, {$jsOpts});";
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Set the component hierarchy and current component ID (called by TemplateCompiler during rendering)
|
|
119
|
-
*
|
|
120
|
-
* @param array $hierarchy The component hierarchy
|
|
121
|
-
* @param string $currentId The current component ID
|
|
122
|
-
*/
|
|
123
|
-
public static function setRenderingContext(array $hierarchy, string $currentId): void
|
|
124
|
-
{
|
|
125
|
-
self::$currentHierarchy = $hierarchy;
|
|
126
|
-
self::$currentComponentId = $currentId;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Get the parent component ID from the current hierarchy.
|
|
131
|
-
*
|
|
132
|
-
* @return string|null The parent component ID, or null if no parent exists
|
|
133
|
-
*/
|
|
134
|
-
protected function getParentComponent(): ?string
|
|
135
|
-
{
|
|
136
|
-
$fullHierarchy = $this->getComponentHierarchy();
|
|
137
|
-
|
|
138
|
-
if (count($fullHierarchy) >= 2) {
|
|
139
|
-
return $fullHierarchy[count($fullHierarchy) - 2];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get the full component hierarchy as an array.
|
|
147
|
-
* Useful for building complete hierarchy paths for JavaScript.
|
|
148
|
-
*
|
|
149
|
-
* @return array Array of component IDs from root to current
|
|
150
|
-
*/
|
|
151
|
-
protected function getComponentHierarchy(): array
|
|
152
|
-
{
|
|
153
|
-
return self::$currentHierarchy ?? ['app'];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Combines and returns the CSS classes for the component.
|
|
158
|
-
*
|
|
159
|
-
* This method merges the provided classes, which can be either strings or arrays of strings,
|
|
160
|
-
* without automatically including the component's `$class` property. It uses the `Utils::mergeClasses`
|
|
161
|
-
* method to ensure that the resulting CSS class string is optimized, with duplicate or conflicting
|
|
162
|
-
* classes removed.
|
|
163
|
-
*
|
|
164
|
-
* ### Features:
|
|
165
|
-
* - Accepts multiple arguments as strings or arrays of strings.
|
|
166
|
-
* - Only merges the classes provided as arguments (does not include `$this->class` automatically).
|
|
167
|
-
* - Ensures the final CSS class string is well-formatted and free of conflicts.
|
|
168
|
-
*
|
|
169
|
-
* @param string|array ...$classes The CSS classes to be merged. Each argument can be a string or an array of strings.
|
|
170
|
-
* @return string A single CSS class string with the merged and optimized classes.
|
|
171
|
-
*/
|
|
172
|
-
protected function getMergeClasses(string|array ...$classes): string
|
|
173
|
-
{
|
|
174
|
-
$all = array_merge($classes);
|
|
175
|
-
|
|
176
|
-
$expr = [];
|
|
177
|
-
foreach ($all as &$chunk) {
|
|
178
|
-
$chunk = preg_replace_callback('/\{\{[\s\S]*?\}\}/', function ($m) use (&$expr) {
|
|
179
|
-
$token = '__EXPR' . count($expr) . '__';
|
|
180
|
-
$expr[$token] = $m[0];
|
|
181
|
-
return $token;
|
|
182
|
-
}, $chunk);
|
|
183
|
-
}
|
|
184
|
-
unset($chunk);
|
|
185
|
-
|
|
186
|
-
$merged = PrismaPHPSettings::$option->tailwindcss
|
|
187
|
-
? TwMerge::merge(...$all)
|
|
188
|
-
: $this->mergeClasses(...$all);
|
|
189
|
-
|
|
190
|
-
return str_replace(array_keys($expr), array_values($expr), $merged);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Merges multiple CSS class strings or arrays of CSS class strings into a single, optimized CSS class string.
|
|
195
|
-
*
|
|
196
|
-
* @param string|array ...$classes The CSS classes to be merged.
|
|
197
|
-
* @return string A single CSS class string with duplicates resolved.
|
|
198
|
-
*/
|
|
199
|
-
private function mergeClasses(string|array ...$classes): string
|
|
200
|
-
{
|
|
201
|
-
$classSet = [];
|
|
202
|
-
|
|
203
|
-
foreach ($classes as $class) {
|
|
204
|
-
$classList = is_array($class) ? $class : [$class];
|
|
205
|
-
foreach ($classList as $item) {
|
|
206
|
-
if (!empty(trim($item))) {
|
|
207
|
-
$splitClasses = preg_split("/\s+/", $item);
|
|
208
|
-
foreach ($splitClasses as $individualClass) {
|
|
209
|
-
$classSet[$individualClass] = true;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return implode(" ", array_keys($classSet));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Build an HTML-attribute string.
|
|
220
|
-
*
|
|
221
|
-
* • Always ignores "class" and "children".
|
|
222
|
-
* • $params overrides anything in $this->props.
|
|
223
|
-
* • Pass names in $exclude to drop them for this call.
|
|
224
|
-
*
|
|
225
|
-
* @param array $params Extra / overriding attributes (optional)
|
|
226
|
-
* @param array $exclude Attribute names to remove on the fly (optional)
|
|
227
|
-
* @return string Example: id="btn" data-id="7"
|
|
228
|
-
*/
|
|
229
|
-
protected function getAttributes(array $params = [], array $exclude = []): string
|
|
230
|
-
{
|
|
231
|
-
$reserved = ['class', 'children'];
|
|
232
|
-
$props = array_diff_key(
|
|
233
|
-
$this->props,
|
|
234
|
-
array_flip(array_merge($reserved, $exclude))
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
$props = array_merge($params, $props);
|
|
238
|
-
|
|
239
|
-
$pairs = array_map(
|
|
240
|
-
static fn($k, $v) => sprintf(
|
|
241
|
-
"%s='%s'",
|
|
242
|
-
htmlspecialchars($k, ENT_QUOTES, 'UTF-8'),
|
|
243
|
-
htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8')
|
|
244
|
-
),
|
|
245
|
-
array_keys($props),
|
|
246
|
-
$props
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
$this->attributesArray = $props;
|
|
250
|
-
return implode(' ', $pairs);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Renders the component as an HTML string with the appropriate classes and attributes.
|
|
255
|
-
* Also, allows for dynamic children rendering if a callable is passed.
|
|
256
|
-
*
|
|
257
|
-
* @return string The final rendered HTML of the component.
|
|
258
|
-
*/
|
|
259
|
-
public function render(): string
|
|
260
|
-
{
|
|
261
|
-
$attributes = $this->getAttributes();
|
|
262
|
-
$class = $this->getMergeClasses();
|
|
263
|
-
|
|
264
|
-
return <<<HTML
|
|
265
|
-
<div class="{$class}" {$attributes}>{$this->children}</div>
|
|
266
|
-
HTML;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Converts the object to its string representation by rendering the component.
|
|
271
|
-
*
|
|
272
|
-
* This method allows the object to be used directly in string contexts, such as
|
|
273
|
-
* when echoing or concatenating, by automatically invoking the `render()` method.
|
|
274
|
-
* If an exception occurs during rendering, it safely returns an empty string
|
|
275
|
-
* to prevent runtime errors, ensuring robustness in all scenarios.
|
|
276
|
-
*
|
|
277
|
-
* @return string The rendered HTML output of the component, or an empty string if rendering fails.
|
|
278
|
-
*/
|
|
279
|
-
public function __toString(): string
|
|
280
|
-
{
|
|
281
|
-
try {
|
|
282
|
-
return $this->render();
|
|
283
|
-
} catch (Exception) {
|
|
284
|
-
return '';
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|