- First task of v2 done

This commit is contained in:
mcndave committed 2023-02-02 16:43:15 +00:00
1 parent 30ddd4c98b
commit 5397ed4fae
50 files changed
+237 -105

No files matched your search

+29 -25
View File
@@ -11,7 +11,7 @@ class UiForm extends UiElement implements Extension {
public string $defaultMethod = "get";
public array $token = [ "ui.form", "ui.endform", "ui.form.get", "ui.form.post", "ui.form.patch", "ui.form.delete", "ui.form.put" ];
public array $token = [ "ui:form", "ui:endform" /*, "ui:form.get", "ui:form.post", "ui:form.patch", "ui:form.delete", "ui:form.put"*/ ];
public string $tag = "form";
@@ -22,41 +22,45 @@ class UiForm extends UiElement implements Extension {
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) : string
{
switch($token) {
case 'ui.endform':
case 'ui:endform':
return "</form>";
}
case "ui.form.get":
$method = "get";
break;
$opt = $context->tokenOptions($token, true);
case "ui.form.patch":
$method = "patch";
break;
case "ui.form.delete":
$method = "delete";
break;
case "ui.form.put":
$method = "put";
break;
case "ui.form.post":
$method = "post";
break;
if (in_array('get', $opt)) {
$method = "get";
}
elseif (in_array('post', $opt)) {
$method = "post";
}
elseif (in_array('put', $opt)) {
$method = "put";
}
elseif (in_array('delete', $opt)) {
$method = "delete";
}
elseif (in_array('patch', $opt)) {
$method = "patch";
}
$method ??= $this->defaultMethod;
return "<?php echo ( new \\" . static::class . "() )->buildHtml('$method', $arguments) ?>";
return "<?php echo ( new \\" . static::class . "() )->parseOptions($opt)->buildHtml('$method', $arguments) ?>";
}
public function parseOptions($options) : self
{
$this->options = $options;
return $this;
}
public function buildHtml(string $method = "get", string $name = "", string $action = "", array $attributes = []) : string
{
$method = strtolower($method);
$this->option('tag-type', 'single');
if ($attributes['class'] ?? false) {
$attributes['class'] .= " {$this->attributes['class']}";
@@ -67,7 +71,7 @@ class UiForm extends UiElement implements Extension {
if ( $method !== "get" ) {
$token = md5( $name . microtime());
$key = "picea-ui.form:{$name}";
$key = "picea-ui:form:{$name}";
if (count($_SESSION[$key] ?? []) > 100) {
array_shift($_SESSION[$key]);