create-prisma-php-app 4.0.0-alpha.50 → 4.0.0-alpha.52
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 +4 -4
- package/dist/index.js +1 -1
- package/dist/src/Lib/Auth/Auth.php +1 -1
- package/dist/src/Lib/CacheHandler.php +1 -1
- package/dist/src/Lib/ErrorHandler.php +2 -2
- package/dist/src/Lib/IncludeTracker.php +1 -1
- package/dist/src/Lib/Middleware/AuthMiddleware.php +1 -1
- package/dist/src/Lib/StateManager.php +1 -1
- package/dist/src/app/index.php +1 -1
- package/dist/src/app/layout.php +2 -2
- package/package.json +1 -1
- package/dist/src/Lib/MainLayout.php +0 -230
- 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/src/Lib/PrismaPHPSettings.php +0 -181
- package/dist/src/Lib/Request.php +0 -479
package/dist/bootstrap.php
CHANGED
|
@@ -18,13 +18,13 @@ if (session_status() === PHP_SESSION_NONE) {
|
|
|
18
18
|
session_start();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
use
|
|
22
|
-
use
|
|
21
|
+
use PPHP\Request;
|
|
22
|
+
use PPHP\PrismaPHPSettings;
|
|
23
23
|
use Lib\StateManager;
|
|
24
24
|
use Lib\Middleware\AuthMiddleware;
|
|
25
25
|
use Lib\Auth\Auth;
|
|
26
|
-
use
|
|
27
|
-
use
|
|
26
|
+
use PPHP\MainLayout;
|
|
27
|
+
use PPHP\PHPX\TemplateCompiler;
|
|
28
28
|
use Lib\CacheHandler;
|
|
29
29
|
use Lib\ErrorHandler;
|
|
30
30
|
use Firebase\JWT\JWT;
|
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(
|
|
@@ -5,9 +5,9 @@ declare(strict_types=1);
|
|
|
5
5
|
namespace Lib;
|
|
6
6
|
|
|
7
7
|
use Bootstrap;
|
|
8
|
-
use
|
|
8
|
+
use PPHP\MainLayout;
|
|
9
9
|
use Throwable;
|
|
10
|
-
use
|
|
10
|
+
use PPHP\PHPX\Exceptions\ComponentValidationException;
|
|
11
11
|
|
|
12
12
|
class ErrorHandler
|
|
13
13
|
{
|
package/dist/src/app/index.php
CHANGED
package/dist/src/app/layout.php
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
use
|
|
4
|
-
use
|
|
3
|
+
use PPHP\MainLayout;
|
|
4
|
+
use PPHP\Request;
|
|
5
5
|
|
|
6
6
|
MainLayout::$title = !empty(MainLayout::$title) ? MainLayout::$title : 'Create Prisma PHP App';
|
|
7
7
|
MainLayout::$description = !empty(MainLayout::$description) ? MainLayout::$description : 'Generated by create Prisma PHP App';
|
package/package.json
CHANGED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Lib;
|
|
6
|
-
|
|
7
|
-
use Lib\Set;
|
|
8
|
-
|
|
9
|
-
class MainLayout
|
|
10
|
-
{
|
|
11
|
-
public static string $title = '';
|
|
12
|
-
public static string $description = '';
|
|
13
|
-
public static string $children = '';
|
|
14
|
-
public static string $childLayoutChildren = '';
|
|
15
|
-
public static string $html = '';
|
|
16
|
-
|
|
17
|
-
/** @var Set<string>|null */
|
|
18
|
-
private static ?Set $headScripts = null;
|
|
19
|
-
/** @var Set<string>|null */
|
|
20
|
-
private static ?Set $footerScripts = null;
|
|
21
|
-
private static array $customMetadata = [];
|
|
22
|
-
|
|
23
|
-
private static array $processedScripts = [];
|
|
24
|
-
|
|
25
|
-
public static function init(): void
|
|
26
|
-
{
|
|
27
|
-
if (self::$headScripts === null) {
|
|
28
|
-
self::$headScripts = new Set();
|
|
29
|
-
}
|
|
30
|
-
if (self::$footerScripts === null) {
|
|
31
|
-
self::$footerScripts = new Set();
|
|
32
|
-
}
|
|
33
|
-
self::$processedScripts = [];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Adds one or more scripts to the head section if they are not already present.
|
|
38
|
-
*
|
|
39
|
-
* @param string ...$scripts The scripts to be added to the head section.
|
|
40
|
-
* @return void
|
|
41
|
-
*/
|
|
42
|
-
public static function addHeadScript(string ...$scripts): void
|
|
43
|
-
{
|
|
44
|
-
foreach ($scripts as $script) {
|
|
45
|
-
self::$headScripts->add($script);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Adds one or more scripts to the footer section if they are not already present.
|
|
51
|
-
*
|
|
52
|
-
* @param string ...$scripts One or more scripts to be added to the footer.
|
|
53
|
-
* @return void
|
|
54
|
-
*/
|
|
55
|
-
public static function addFooterScript(string ...$scripts): void
|
|
56
|
-
{
|
|
57
|
-
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
|
58
|
-
$callerClass = $trace[1]['class'] ?? 'Unknown';
|
|
59
|
-
|
|
60
|
-
foreach ($scripts as $script) {
|
|
61
|
-
$scriptKey = md5(trim($script));
|
|
62
|
-
|
|
63
|
-
if (strpos($script, '<script') !== false) {
|
|
64
|
-
$taggedScript = "<!-- class:" . $callerClass . " -->\n" . $script;
|
|
65
|
-
if (!isset(self::$processedScripts[$scriptKey])) {
|
|
66
|
-
self::$footerScripts->add($taggedScript);
|
|
67
|
-
self::$processedScripts[$scriptKey] = true;
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
if (!isset(self::$processedScripts[$scriptKey])) {
|
|
71
|
-
self::$footerScripts->add($script);
|
|
72
|
-
self::$processedScripts[$scriptKey] = true;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Generates all the head scripts with dynamic attributes.
|
|
80
|
-
*
|
|
81
|
-
* This method iterates over all registered head scripts and adds a custom dynamic attribute
|
|
82
|
-
* based on the tag type (script, link, or style).
|
|
83
|
-
*
|
|
84
|
-
* @return string The concatenated head scripts with dynamic attributes.
|
|
85
|
-
*/
|
|
86
|
-
public static function outputHeadScripts(): string
|
|
87
|
-
{
|
|
88
|
-
$headScriptsArray = self::$headScripts->values();
|
|
89
|
-
$headScriptsWithAttributes = array_map(function ($tag) {
|
|
90
|
-
if (strpos($tag, '<script') !== false) {
|
|
91
|
-
return str_replace('<script', '<script pp-dynamic-script="81D7D"', $tag);
|
|
92
|
-
} elseif (strpos($tag, '<link') !== false) {
|
|
93
|
-
return str_replace('<link', '<link pp-dynamic-link="81D7D"', $tag);
|
|
94
|
-
} elseif (strpos($tag, '<style') !== false) {
|
|
95
|
-
return str_replace('<style', '<style pp-dynamic-style="81D7D"', $tag);
|
|
96
|
-
}
|
|
97
|
-
return $tag;
|
|
98
|
-
}, $headScriptsArray);
|
|
99
|
-
|
|
100
|
-
return implode("\n", $headScriptsWithAttributes);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Generates all the footer scripts.
|
|
105
|
-
*
|
|
106
|
-
* @return string The concatenated footer scripts.
|
|
107
|
-
*/
|
|
108
|
-
public static function outputFooterScripts(): string
|
|
109
|
-
{
|
|
110
|
-
$processed = [];
|
|
111
|
-
$componentCounter = 0;
|
|
112
|
-
|
|
113
|
-
foreach (self::$footerScripts->values() as $script) {
|
|
114
|
-
if (preg_match('/<!-- class:([^\s]+) -->/', $script, $matches)) {
|
|
115
|
-
$rawClassName = $matches[1];
|
|
116
|
-
$script = preg_replace('/<!-- class:[^\s]+ -->\s*/', '', $script, 1);
|
|
117
|
-
|
|
118
|
-
if (str_starts_with(trim($script), '<script')) {
|
|
119
|
-
$script = preg_replace_callback(
|
|
120
|
-
'/<script\b([^>]*)>/i',
|
|
121
|
-
function ($m) use ($rawClassName, &$componentCounter) {
|
|
122
|
-
$attrs = $m[1];
|
|
123
|
-
$scriptHash = substr(md5($m[0]), 0, 8);
|
|
124
|
-
$encodedClass = 's' . base_convert(sprintf('%u', crc32($rawClassName . $componentCounter . $scriptHash)), 10, 36);
|
|
125
|
-
$componentCounter++;
|
|
126
|
-
|
|
127
|
-
if (!str_contains($attrs, 'pp-component=')) {
|
|
128
|
-
$attrs .= " pp-component=\"{$encodedClass}\"";
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (!preg_match('/\btype\s*=\s*(["\'])[^\1]*\1|\btype\s*=\s*\S+/i', $attrs)) {
|
|
132
|
-
$attrs .= ' type="text/php"';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return "<script{$attrs}>";
|
|
136
|
-
},
|
|
137
|
-
$script,
|
|
138
|
-
1
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
$processed[] = $script;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return implode("\n", $processed);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Clears all head scripts.
|
|
151
|
-
*
|
|
152
|
-
* @return void
|
|
153
|
-
*/
|
|
154
|
-
public static function clearHeadScripts(): void
|
|
155
|
-
{
|
|
156
|
-
self::$headScripts->clear();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Clears all footer scripts.
|
|
161
|
-
*
|
|
162
|
-
* @return void
|
|
163
|
-
*/
|
|
164
|
-
public static function clearFooterScripts(): void
|
|
165
|
-
{
|
|
166
|
-
self::$footerScripts->clear();
|
|
167
|
-
self::$processedScripts = [];
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Adds custom metadata.
|
|
172
|
-
*
|
|
173
|
-
* @param string $key The metadata key.
|
|
174
|
-
* @param string $value The metadata value.
|
|
175
|
-
* @return void
|
|
176
|
-
*/
|
|
177
|
-
public static function addCustomMetadata(string $key, string $value): void
|
|
178
|
-
{
|
|
179
|
-
self::$customMetadata[$key] = $value;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Retrieves custom metadata by key.
|
|
184
|
-
*
|
|
185
|
-
* @param string $key The metadata key.
|
|
186
|
-
* @return string|null The metadata value or null if the key does not exist.
|
|
187
|
-
*/
|
|
188
|
-
public static function getCustomMetadata(string $key): ?string
|
|
189
|
-
{
|
|
190
|
-
return self::$customMetadata[$key] ?? null;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Generates the metadata as meta tags for the head section.
|
|
195
|
-
*
|
|
196
|
-
* This method includes default tags for charset and viewport, a title tag,
|
|
197
|
-
* and additional metadata. If a description is not already set in the custom metadata,
|
|
198
|
-
* it will use the class's description property.
|
|
199
|
-
*
|
|
200
|
-
* @return string The concatenated meta tags.
|
|
201
|
-
*/
|
|
202
|
-
public static function outputMetadata(): string
|
|
203
|
-
{
|
|
204
|
-
$metadataContent = [
|
|
205
|
-
'<meta charset="UTF-8">',
|
|
206
|
-
'<meta name="viewport" content="width=device-width, initial-scale=1.0">',
|
|
207
|
-
];
|
|
208
|
-
$metadataContent[] = '<title>' . htmlspecialchars(self::$title) . '</title>';
|
|
209
|
-
|
|
210
|
-
if (!isset(self::$customMetadata['description'])) {
|
|
211
|
-
self::$customMetadata['description'] = self::$description;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
foreach (self::$customMetadata as $key => $value) {
|
|
215
|
-
$metadataContent[] = '<meta name="' . htmlspecialchars($key) . '" content="' . htmlspecialchars($value) . '" pp-dynamic-meta="81D7D">';
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return implode("\n", $metadataContent);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Clears all custom metadata.
|
|
223
|
-
*
|
|
224
|
-
* @return void
|
|
225
|
-
*/
|
|
226
|
-
public static function clearCustomMetadata(): void
|
|
227
|
-
{
|
|
228
|
-
self::$customMetadata = [];
|
|
229
|
-
}
|
|
230
|
-
}
|
|
@@ -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
|
-
}
|