create-prisma-php-app 3.1.11 → 4.0.0-alpha.2
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 +10 -10
- package/dist/index.js +12 -8
- package/dist/settings/restart-websocket.bat +1 -1
- package/dist/settings/restart-websocket.ts +2 -9
- package/dist/src/{Lib/Websocket → Websocket}/ConnectionManager.php +1 -1
- package/dist/src/app/error.php +1 -1
- package/dist/src/app/index.php +1 -1
- package/dist/src/app/js/index.js +1 -1
- package/dist/src/app/layout.php +2 -2
- package/dist/{src/Lib/Websocket/websocket-server.php → websocket-server.php} +2 -7
- package/package.json +1 -1
- package/dist/src/Lib/AI/ChatGPTClient.php +0 -147
- package/dist/src/Lib/Auth/Auth.php +0 -544
- package/dist/src/Lib/Auth/AuthConfig.php +0 -89
- package/dist/src/Lib/CacheHandler.php +0 -121
- package/dist/src/Lib/ErrorHandler.php +0 -322
- package/dist/src/Lib/FileManager/UploadFile.php +0 -383
- package/dist/src/Lib/Headers/Boom.php +0 -208
- package/dist/src/Lib/IncludeTracker.php +0 -59
- package/dist/src/Lib/MainLayout.php +0 -215
- package/dist/src/Lib/Middleware/AuthMiddleware.php +0 -154
- package/dist/src/Lib/PHPMailer/Mailer.php +0 -169
- package/dist/src/Lib/PHPX/Exceptions/ComponentValidationException.php +0 -49
- package/dist/src/Lib/PHPX/IPHPX.php +0 -22
- package/dist/src/Lib/PHPX/PHPX.php +0 -173
- package/dist/src/Lib/PHPX/TemplateCompiler.php +0 -571
- package/dist/src/Lib/PHPX/TwMerge.php +0 -195
- package/dist/src/Lib/PHPX/TypeCoercer.php +0 -490
- package/dist/src/Lib/PartialRenderer.php +0 -40
- package/dist/src/Lib/PrismaPHPSettings.php +0 -181
- package/dist/src/Lib/Request.php +0 -476
- package/dist/src/Lib/Set.php +0 -102
- package/dist/src/Lib/StateManager.php +0 -127
- package/dist/src/Lib/Validator.php +0 -738
|
@@ -1,173 +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
|
-
* Constructor to initialize the component with the given properties.
|
|
31
|
-
*
|
|
32
|
-
* @param array<string, mixed> $props Optional properties to customize the component.
|
|
33
|
-
*/
|
|
34
|
-
public function __construct(array $props = [])
|
|
35
|
-
{
|
|
36
|
-
$this->props = $props;
|
|
37
|
-
$this->children = $props['children'] ?? '';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Combines and returns the CSS classes for the component.
|
|
42
|
-
*
|
|
43
|
-
* This method merges the provided classes, which can be either strings or arrays of strings,
|
|
44
|
-
* without automatically including the component's `$class` property. It uses the `Utils::mergeClasses`
|
|
45
|
-
* method to ensure that the resulting CSS class string is optimized, with duplicate or conflicting
|
|
46
|
-
* classes removed.
|
|
47
|
-
*
|
|
48
|
-
* ### Features:
|
|
49
|
-
* - Accepts multiple arguments as strings or arrays of strings.
|
|
50
|
-
* - Only merges the classes provided as arguments (does not include `$this->class` automatically).
|
|
51
|
-
* - Ensures the final CSS class string is well-formatted and free of conflicts.
|
|
52
|
-
*
|
|
53
|
-
* @param string|array ...$classes The CSS classes to be merged. Each argument can be a string or an array of strings.
|
|
54
|
-
* @return string A single CSS class string with the merged and optimized classes.
|
|
55
|
-
*/
|
|
56
|
-
protected function getMergeClasses(string|array ...$classes): string
|
|
57
|
-
{
|
|
58
|
-
$all = array_merge($classes);
|
|
59
|
-
|
|
60
|
-
$expr = [];
|
|
61
|
-
foreach ($all as &$chunk) {
|
|
62
|
-
$chunk = preg_replace_callback('/\{\{[\s\S]*?\}\}/', function ($m) use (&$expr) {
|
|
63
|
-
$token = '__EXPR' . count($expr) . '__';
|
|
64
|
-
$expr[$token] = $m[0];
|
|
65
|
-
return $token;
|
|
66
|
-
}, $chunk);
|
|
67
|
-
}
|
|
68
|
-
unset($chunk);
|
|
69
|
-
|
|
70
|
-
$merged = PrismaPHPSettings::$option->tailwindcss
|
|
71
|
-
? TwMerge::mergeClasses(...$all)
|
|
72
|
-
: $this->mergeClasses(...$all);
|
|
73
|
-
|
|
74
|
-
return str_replace(array_keys($expr), array_values($expr), $merged);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Merges multiple CSS class strings or arrays of CSS class strings into a single, optimized CSS class string.
|
|
79
|
-
*
|
|
80
|
-
* @param string|array ...$classes The CSS classes to be merged.
|
|
81
|
-
* @return string A single CSS class string with duplicates resolved.
|
|
82
|
-
*/
|
|
83
|
-
private function mergeClasses(string|array ...$classes): string
|
|
84
|
-
{
|
|
85
|
-
$classSet = [];
|
|
86
|
-
|
|
87
|
-
foreach ($classes as $class) {
|
|
88
|
-
$classList = is_array($class) ? $class : [$class];
|
|
89
|
-
foreach ($classList as $item) {
|
|
90
|
-
if (!empty(trim($item))) {
|
|
91
|
-
$splitClasses = preg_split("/\s+/", $item);
|
|
92
|
-
foreach ($splitClasses as $individualClass) {
|
|
93
|
-
$classSet[$individualClass] = true;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return implode(" ", array_keys($classSet));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Build an HTML-attribute string.
|
|
104
|
-
*
|
|
105
|
-
* • Always ignores "class" and "children".
|
|
106
|
-
* • $params overrides anything in $this->props.
|
|
107
|
-
* • Pass names in $exclude to drop them for this call.
|
|
108
|
-
*
|
|
109
|
-
* @param array $params Extra / overriding attributes (optional)
|
|
110
|
-
* @param array $exclude Attribute names to remove on the fly (optional)
|
|
111
|
-
* @return string Example: id="btn" data-id="7"
|
|
112
|
-
*/
|
|
113
|
-
protected function getAttributes(array $params = [], array $exclude = []): string
|
|
114
|
-
{
|
|
115
|
-
$reserved = ['class', 'children'];
|
|
116
|
-
$props = array_diff_key(
|
|
117
|
-
$this->props,
|
|
118
|
-
array_flip(array_merge($reserved, $exclude))
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
foreach ($params as $k => $v) {
|
|
122
|
-
$props[$k] = $v;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
$pairs = array_map(
|
|
126
|
-
static fn($k, $v) => sprintf(
|
|
127
|
-
"%s='%s'",
|
|
128
|
-
htmlspecialchars($k, ENT_QUOTES, 'UTF-8'),
|
|
129
|
-
htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8')
|
|
130
|
-
),
|
|
131
|
-
array_keys($props),
|
|
132
|
-
$props
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
$this->attributesArray = $props;
|
|
136
|
-
return implode(' ', $pairs);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Renders the component as an HTML string with the appropriate classes and attributes.
|
|
141
|
-
* Also, allows for dynamic children rendering if a callable is passed.
|
|
142
|
-
*
|
|
143
|
-
* @return string The final rendered HTML of the component.
|
|
144
|
-
*/
|
|
145
|
-
public function render(): string
|
|
146
|
-
{
|
|
147
|
-
$attributes = $this->getAttributes();
|
|
148
|
-
$class = $this->getMergeClasses();
|
|
149
|
-
|
|
150
|
-
return <<<HTML
|
|
151
|
-
<div class="{$class}" {$attributes}>{$this->children}</div>
|
|
152
|
-
HTML;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Converts the object to its string representation by rendering the component.
|
|
157
|
-
*
|
|
158
|
-
* This method allows the object to be used directly in string contexts, such as
|
|
159
|
-
* when echoing or concatenating, by automatically invoking the `render()` method.
|
|
160
|
-
* If an exception occurs during rendering, it safely returns an empty string
|
|
161
|
-
* to prevent runtime errors, ensuring robustness in all scenarios.
|
|
162
|
-
*
|
|
163
|
-
* @return string The rendered HTML output of the component, or an empty string if rendering fails.
|
|
164
|
-
*/
|
|
165
|
-
public function __toString(): string
|
|
166
|
-
{
|
|
167
|
-
try {
|
|
168
|
-
return $this->render();
|
|
169
|
-
} catch (Exception) {
|
|
170
|
-
return '';
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|