create-prisma-php-app 1.26.530 → 1.26.532
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.
|
@@ -22,6 +22,11 @@ class PHPX implements IPHPX
|
|
|
22
22
|
*/
|
|
23
23
|
protected string $class;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @var array<string, mixed> The array representation of the HTML attributes.
|
|
27
|
+
*/
|
|
28
|
+
protected array $attributesArray = [];
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* Constructor to initialize the component with the given properties.
|
|
27
32
|
*
|
|
@@ -67,25 +72,40 @@ class PHPX implements IPHPX
|
|
|
67
72
|
/**
|
|
68
73
|
* Generates and returns a string of HTML attributes from the provided props.
|
|
69
74
|
* Excludes 'class' and 'children' props from being added as attributes.
|
|
70
|
-
*
|
|
71
|
-
*
|
|
75
|
+
* Prioritizes attributes from `$this->props` if duplicates are found in `$params`.
|
|
76
|
+
*
|
|
77
|
+
* @param array $params Optional additional attributes to merge with props.
|
|
78
|
+
*
|
|
79
|
+
* @return string The generated HTML attributes as a space-separated string.
|
|
72
80
|
*/
|
|
73
|
-
protected function getAttributes(): string
|
|
81
|
+
protected function getAttributes(array $params = []): string
|
|
74
82
|
{
|
|
75
83
|
// Filter out 'class' and 'children' props
|
|
76
|
-
$filteredProps = array_filter(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
$filteredProps = array_filter(
|
|
85
|
+
$this->props,
|
|
86
|
+
function ($key) {
|
|
87
|
+
return !in_array($key, ["class", "children"]);
|
|
88
|
+
},
|
|
89
|
+
ARRAY_FILTER_USE_KEY
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Merge attributes, prioritizing props in case of duplicates
|
|
93
|
+
$attributes = array_merge($params, $filteredProps);
|
|
94
|
+
|
|
95
|
+
// Build the attributes string by escaping keys and values
|
|
96
|
+
$attributeStrings = [];
|
|
97
|
+
foreach ($attributes as $key => $value) {
|
|
98
|
+
$escapedKey = htmlspecialchars($key, ENT_QUOTES, "UTF-8");
|
|
99
|
+
$escapedValue = htmlspecialchars(
|
|
100
|
+
(string) $value,
|
|
101
|
+
ENT_QUOTES,
|
|
102
|
+
"UTF-8"
|
|
103
|
+
);
|
|
104
|
+
$attributeStrings[] = "$escapedKey='$escapedValue'";
|
|
86
105
|
}
|
|
87
106
|
|
|
88
|
-
|
|
107
|
+
$this->attributesArray = $attributes;
|
|
108
|
+
return implode(" ", $attributeStrings);
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
/**
|
|
@@ -37,6 +37,25 @@ class TemplateCompiler
|
|
|
37
37
|
self::initializeClassMappings();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
// Convert template to valid XML
|
|
41
|
+
$dom = self::convertToXml($templateContent);
|
|
42
|
+
|
|
43
|
+
// Process the converted XML
|
|
44
|
+
$root = $dom->documentElement;
|
|
45
|
+
$output = "";
|
|
46
|
+
|
|
47
|
+
foreach ($root->childNodes as $child) {
|
|
48
|
+
$output .= self::processNode($child);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return $output;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public static function convertToXml(string $templateContent): DOMDocument
|
|
55
|
+
{
|
|
56
|
+
// Escape `&` characters that are not part of valid XML entities
|
|
57
|
+
$templateContent = preg_replace('/&(?![a-zA-Z0-9#]+;)/', '&', $templateContent);
|
|
58
|
+
|
|
40
59
|
$dom = new DOMDocument();
|
|
41
60
|
libxml_use_internal_errors(true);
|
|
42
61
|
|
|
@@ -50,13 +69,7 @@ class TemplateCompiler
|
|
|
50
69
|
}
|
|
51
70
|
libxml_clear_errors();
|
|
52
71
|
|
|
53
|
-
|
|
54
|
-
$output = "";
|
|
55
|
-
foreach ($root->childNodes as $child) {
|
|
56
|
-
$output .= self::processNode($child);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return $output;
|
|
72
|
+
return $dom;
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
protected static function getXmlErrors(): array
|
|
@@ -163,7 +176,18 @@ class TemplateCompiler
|
|
|
163
176
|
$classPath = self::$classMappings[$componentName];
|
|
164
177
|
// Instantiate the component
|
|
165
178
|
$componentInstance = new $classPath($attributes);
|
|
166
|
-
|
|
179
|
+
|
|
180
|
+
// Render the component
|
|
181
|
+
$renderedContent = $componentInstance->render();
|
|
182
|
+
|
|
183
|
+
// Check if the rendered content contains other components
|
|
184
|
+
if (strpos($renderedContent, '<') !== false) {
|
|
185
|
+
// Re-parse the rendered content
|
|
186
|
+
return self::compile($renderedContent);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Return the plain rendered content if no components are detected
|
|
190
|
+
return $renderedContent;
|
|
167
191
|
} else {
|
|
168
192
|
// Render as an HTML tag
|
|
169
193
|
$attributesString = self::renderAttributes($attributes);
|
|
@@ -30,15 +30,15 @@ class TwMerge
|
|
|
30
30
|
// **Background color classes**
|
|
31
31
|
"bg" => "/^bg-/",
|
|
32
32
|
|
|
33
|
-
// **Text size classes
|
|
33
|
+
// **Text size classes
|
|
34
34
|
"text-size" => '/^text-(xs|sm|base|lg|xl|[2-9]xl)$/',
|
|
35
35
|
|
|
36
|
-
// **Text color classes**
|
|
37
|
-
"text-color" => '/^text-(?!xs$|sm$|base$|lg$|xl$|[2-9]xl$).+$/',
|
|
38
|
-
|
|
39
36
|
// **Text alignment classes**
|
|
40
37
|
"text-alignment" => '/^text-(left|center|right|justify)$/',
|
|
41
38
|
|
|
39
|
+
// **Text color classes
|
|
40
|
+
"text-color" => '/^text-(?!xs$|sm$|base$|lg$|xl$|[2-9]xl$).+$/',
|
|
41
|
+
|
|
42
42
|
// **Text transform classes**
|
|
43
43
|
"text-transform" =>
|
|
44
44
|
'/^text-(uppercase|lowercase|capitalize|normal-case)$/',
|
|
@@ -71,6 +71,9 @@ class TwMerge
|
|
|
71
71
|
// **Opacity classes
|
|
72
72
|
"opacity" => '/^opacity(-[0-9]+)?$/',
|
|
73
73
|
|
|
74
|
+
// **Flexbox alignment classes**
|
|
75
|
+
"justify" => "/^justify-(start|end|center|between|around|evenly)$/",
|
|
76
|
+
|
|
74
77
|
// **Other utility classes can be added here**
|
|
75
78
|
];
|
|
76
79
|
|
|
@@ -117,6 +120,9 @@ class TwMerge
|
|
|
117
120
|
// **Opacity conflict group
|
|
118
121
|
"opacity" => ["opacity"],
|
|
119
122
|
|
|
123
|
+
// **Flexbox alignment conflict group**
|
|
124
|
+
"justify" => ["justify"],
|
|
125
|
+
|
|
120
126
|
// **Add other conflict groups as needed**
|
|
121
127
|
];
|
|
122
128
|
|