- First commit, work done on form input
This commit is contained in:
commit
a0bf505377
24 files changed
+934
No files matched your search
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Picea\Ui\Form;
|
||||
|
||||
use Picea\Ui\Common\UiElement;
|
||||
use Picea\Extension\Extension;
|
||||
|
||||
class UiInput extends UiElement implements Extension {
|
||||
|
||||
public string $token = "ui.input";
|
||||
|
||||
public string $tag = "input";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => 'ui-input',
|
||||
];
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
|
||||
{
|
||||
list($name, $value, $options) = array_pad(explode(',', $arguments), 3, null);
|
||||
|
||||
$this->attributes['name'] = $name;
|
||||
$this->setValue($value);
|
||||
$this->attributes($this->parseAttributes($options));
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
protected function parseAttributes(string $options) : array
|
||||
{
|
||||
if ( $options ?? false ) {
|
||||
$attributes = eval($options);
|
||||
|
||||
if ( ! is_array($attributes) ) {
|
||||
throw new InvalidArgumentException("Given options `$options` is not a valid attributes array.");
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function setValue($value) : void
|
||||
{
|
||||
$this->attributes['value'] = $value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user