- First task of v2 done
This commit is contained in:
1 parent
30ddd4c98b
commit
5397ed4fae
50 files changed
+237
-105
No files matched your search
@@ -9,7 +9,7 @@ use Picea\Extension\ExtensionTrait;
|
||||
class UiMessage extends UiElement implements Extension {
|
||||
use ExtensionTrait;
|
||||
|
||||
public string $token = "ui.message";
|
||||
public string $token = "ui:message";
|
||||
|
||||
public string $tag = "input";
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use Picea\Extension\ExtensionTrait;
|
||||
class UiPopup extends UiElement implements Extension {
|
||||
use ExtensionTrait;
|
||||
|
||||
public string $token = "ui.popup";
|
||||
public string $token = "ui:popup";
|
||||
|
||||
public string $tag = "div";
|
||||
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace Picea\Ui\Form;
|
||||
|
||||
use Picea\Extension\Extension;
|
||||
use Picea\Extension\ExtensionTrait;
|
||||
use Picea\Ui\Common\UiElement;
|
||||
use Picea\Ui\Component\UiMessage;
|
||||
use Picea\Ui\Component\UiPopup;
|
||||
|
||||
class Ui extends UiElement implements Extension {
|
||||
use ExtensionTrait;
|
||||
|
||||
public string $token = "ui";
|
||||
|
||||
protected /* ? mixed */ $value;
|
||||
|
||||
protected string $name;
|
||||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) : string
|
||||
{
|
||||
$opt = $context->tokenOptions($token);
|
||||
|
||||
switch(true) {
|
||||
case in_array('checkbox', $opt):
|
||||
$input = new UiCheckbox();
|
||||
break;
|
||||
|
||||
case in_array('color', $opt):
|
||||
$input = new UiColor();
|
||||
break;
|
||||
|
||||
case in_array('date', $opt):
|
||||
$input = new UiDate();
|
||||
break;
|
||||
|
||||
case in_array('datetime', $opt):
|
||||
$input = new UiDatetime();
|
||||
break;
|
||||
|
||||
case in_array('email', $opt):
|
||||
$input = new UiEmail();
|
||||
break;
|
||||
|
||||
case in_array('file', $opt):
|
||||
$input = new UiFile();
|
||||
break;
|
||||
|
||||
case in_array('form', $opt):
|
||||
case in_array('endform', $opt):
|
||||
$input = new UiForm();
|
||||
break;
|
||||
|
||||
case in_array('hidden', $opt):
|
||||
$input = new UiHidden();
|
||||
break;
|
||||
|
||||
case in_array('image', $opt):
|
||||
$input = new UiImage();
|
||||
break;
|
||||
|
||||
case in_array('input', $opt):
|
||||
$input = new UiInput();
|
||||
break;
|
||||
|
||||
case in_array('numeric', $opt):
|
||||
$input = new UiNumeric();
|
||||
break;
|
||||
|
||||
case in_array('password', $opt):
|
||||
$input = new UiPassword();
|
||||
break;
|
||||
|
||||
case in_array('radio', $opt):
|
||||
$input = new UiRadio();
|
||||
break;
|
||||
|
||||
case in_array('range', $opt):
|
||||
$input = new UiRange();
|
||||
break;
|
||||
|
||||
case in_array('search', $opt):
|
||||
$input = new UiSearch();
|
||||
break;
|
||||
|
||||
case in_array('select', $opt):
|
||||
$input = new UiSelect();
|
||||
break;
|
||||
|
||||
case in_array('tel', $opt):
|
||||
$input = new UiTel();
|
||||
break;
|
||||
|
||||
case in_array('text', $opt):
|
||||
$input = new UiText();
|
||||
break;
|
||||
|
||||
case in_array('textarea', $opt):
|
||||
$input = new UiTextarea();
|
||||
break;
|
||||
|
||||
case in_array('time', $opt):
|
||||
$input = new UiText();
|
||||
break;
|
||||
|
||||
case in_array('url', $opt):
|
||||
$input = new UiUrl();
|
||||
break;
|
||||
|
||||
case in_array('week', $opt):
|
||||
$input = new UiWeek();
|
||||
break;
|
||||
|
||||
case in_array('popup', $opt):
|
||||
$input = new UiPopup();
|
||||
break;
|
||||
|
||||
case in_array('message', $opt):
|
||||
$input = new UiMessage();
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($input)) {
|
||||
throw new \Exception("Missing token ? $token");
|
||||
}
|
||||
|
||||
return $input->parse($context, $arguments, $token);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiCheckbox extends UiRadio {
|
||||
|
||||
public string $token = "ui.checkbox";
|
||||
public string $token = "ui:checkbox";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-checkbox",
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiColor extends UiInput {
|
||||
|
||||
public string $token = "ui.color";
|
||||
public string $token = "ui:color";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-color",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiDate extends UiInput {
|
||||
|
||||
public string $token = "ui.date";
|
||||
public string $token = "ui:date";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-date",
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiDatetime extends UiInput {
|
||||
|
||||
public string $token = "ui.datetime";
|
||||
public string $token = "ui:datetime";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-datetime",
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiEmail extends UiInput {
|
||||
|
||||
public string $token = "ui.email";
|
||||
public string $token = "ui:email";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-email",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiFile extends UiInput {
|
||||
|
||||
public string $token = "ui.file";
|
||||
public string $token = "ui:file";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-file",
|
||||
|
||||
+29
-25
@@ -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]);
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiHidden extends UiInput {
|
||||
|
||||
public string $token = "ui.hidden";
|
||||
public string $token = "ui:hidden";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-hidden",
|
||||
|
||||
@@ -9,7 +9,7 @@ use Picea\Extension\ExtensionTrait;
|
||||
class UiImage extends UiElement implements Extension {
|
||||
use ExtensionTrait;
|
||||
|
||||
public string $token = "ui.img";
|
||||
public array $tokens = [ "ui:img", "ui:image" ];
|
||||
|
||||
public string $tag = "img";
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use Picea\Extension\ExtensionTrait;
|
||||
class UiInput extends UiElement implements Extension {
|
||||
use ExtensionTrait;
|
||||
|
||||
public string $token = "ui.input";
|
||||
public string $token = "ui:input";
|
||||
|
||||
public string $tag = "input";
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiNumeric extends UiInput {
|
||||
|
||||
public string $token = "ui.numeric";
|
||||
public string $token = "ui:numeric";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-numeric",
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiPassword extends UiInput {
|
||||
|
||||
public string $token = "ui.password";
|
||||
public string $token = "ui:password";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-password",
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiRadio extends UiInput {
|
||||
|
||||
public string $token = "ui.radio";
|
||||
public string $token = "ui:radio";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-radio",
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiRange extends UiInput {
|
||||
|
||||
public string $token = "ui.range";
|
||||
public string $token = "ui:range";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-range",
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiSearch extends UiInput {
|
||||
|
||||
public string $token = "ui.search";
|
||||
public string $token = "ui:search";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-search",
|
||||
|
||||
@@ -9,7 +9,7 @@ use Picea\Extension\ExtensionTrait;
|
||||
class UiSelect extends UiElement implements Extension {
|
||||
use ExtensionTrait;
|
||||
|
||||
public string $token = "ui.select";
|
||||
public string $token = "ui:select";
|
||||
|
||||
public string $tag = "select";
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiTel extends UiInput {
|
||||
|
||||
public string $token = "ui.tel";
|
||||
public string $token = "ui:tel";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-tel",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiText extends UiInput {
|
||||
|
||||
public string $token = "ui.text";
|
||||
public string $token = "ui:text";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-text",
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiTextarea extends UiInput {
|
||||
|
||||
public array $tokens = [ "ui.textarea", "ui.textarea.raw" ];
|
||||
public array $tokens = [ "ui:textarea" ];
|
||||
|
||||
public string $tag = "textarea";
|
||||
|
||||
@@ -18,11 +18,7 @@ class UiTextarea extends UiInput {
|
||||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) : string
|
||||
{
|
||||
if ($token === 'ui.textarea.raw') {
|
||||
$this->echoRaw = true;
|
||||
}
|
||||
|
||||
$raw = $this->echoRaw ? 'true' : 'false';
|
||||
$raw = in_array('raw', $context->tokenOptions($token, true)) ? 'true' : 'false';
|
||||
|
||||
return "<?php echo ( new \\" . static::class . "() )->echoRaw($raw)->buildHtml($arguments) ?>";
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiTime extends UiInput {
|
||||
|
||||
public string $token = "ui.time";
|
||||
public string $token = "ui:time";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-time",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiUrl extends UiInput {
|
||||
|
||||
public string $token = "ui.url";
|
||||
public string $token = "ui:url";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-url",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Picea\Ui\Form;
|
||||
|
||||
class UiWeek extends UiInput {
|
||||
|
||||
public string $token = "ui.week";
|
||||
public string $token = "ui:week";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => "ui-week",
|
||||
|
||||
@@ -8,6 +8,9 @@ class Ui {
|
||||
|
||||
public function registerFormExtension(Compiler $compiler) : self
|
||||
{
|
||||
# BW compatibility with v1.x syntax
|
||||
$compiler->registerExtension(new Form\Ui());
|
||||
|
||||
$compiler->registerExtension(new Form\UiForm());
|
||||
$compiler->registerExtension(new Form\UiInput());
|
||||
$compiler->registerExtension(new Form\UiCheckbox());
|
||||
|
||||
Reference in new issue
Block a user