- Fixed conflict
This commit is contained in:
parent
bf7605eef6
commit
e2c1c7ac39
|
@ -39,10 +39,14 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
|
||||||
|
|
||||||
protected ?UiQuery $kwery = null;
|
protected ?UiQuery $kwery = null;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct(? string $tag = null) {
|
||||||
if ( ! static::$config ) {
|
if ( ! static::$config ) {
|
||||||
static::pushConfigArray( include(dirname(__FILE__) . "/taglist.php") );
|
static::pushConfigArray( include(dirname(__FILE__) . "/taglist.php") );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($tag !== null) {
|
||||||
|
$this->tag = $tag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function pushConfigArray(array $array) : void
|
public static function pushConfigArray(array $array) : void
|
||||||
|
@ -237,54 +241,35 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function append( ...$arguments ) {
|
public function append( ...$arguments ) : self
|
||||||
return $this->insert( self::INSERT_MODE_APPEND, ...$arguments);
|
{
|
||||||
|
return $this->insert( static::INSERT_MODE_APPEND, ...$arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepend( ...$arguments ) {
|
public function prepend( ...$arguments ) : self
|
||||||
return $this->insert( self::INSERT_MODE_PREPEND, ...(is_array($arguments) ? array_reverse($arguments) : $arguments));
|
{
|
||||||
|
return $this->insert( static::INSERT_MODE_PREPEND, ...( is_array($arguments) ? array_reverse($arguments) : $arguments) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert($insert_mode = self::INSERT_MODE_APPEND, ...$arguments) {
|
|
||||||
if ( ! $arguments || !( $count = count($arguments) ) ) {
|
protected function insert(int $mode, ...$elements) : self
|
||||||
return $this;
|
{
|
||||||
}
|
foreach($elements as $item) {
|
||||||
|
switch($mode) {
|
||||||
$insert = function($content) use ( $insert_mode ) {
|
case static::INSERT_MODE_APPEND:
|
||||||
if ( self::is_node($content) ) {
|
array_push($this->childs, $item);
|
||||||
if ($insert_mode === self::INSERT_MODE_APPEND ) {
|
break;
|
||||||
$this->childs[] = $content;
|
|
||||||
}
|
case static::INSERT_MODE_PREPEND:
|
||||||
elseif ($insert_mode === self::INSERT_MODE_PREPEND ) {
|
array_unshift($this->childs, $item);
|
||||||
array_unshift($this->childs, $content);
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( $count == 1 && !is_array($arguments) ) {
|
|
||||||
// Single node to add
|
|
||||||
$insert($arguments);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// multiple node to add
|
|
||||||
foreach ( $arguments as $item ) {
|
|
||||||
if ( is_array($item) ) {
|
|
||||||
foreach ( $item as $key => $value ) {
|
|
||||||
if ( !is_numeric($key) ) {
|
|
||||||
$value->name = $key;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->insert($insert_mode, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$insert($item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function attributes(array $attributes) : self
|
public function attributes(array $attributes) : self
|
||||||
{
|
{
|
||||||
|
@ -416,7 +401,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
|
||||||
|
|
||||||
public static function is_node($obj) : bool
|
public static function is_node($obj) : bool
|
||||||
{
|
{
|
||||||
return is_object($obj) && get_class($obj) === static::class;
|
return $obj instanceof UiElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString() : string
|
public function __toString() : string
|
||||||
|
|
|
@ -55,7 +55,7 @@ class UiForm extends UiElement implements Extension {
|
||||||
{
|
{
|
||||||
$this->option('tag-type', 'single');
|
$this->option('tag-type', 'single');
|
||||||
$this->attributes([ 'method' => $method, 'action' => $action ] + $attributes);
|
$this->attributes([ 'method' => $method, 'action' => $action ] + $attributes);
|
||||||
|
|
||||||
return $this->render() . PHP_EOL;
|
return $this->render() . PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,6 +40,7 @@ class UiSelect extends UiElement implements Extension {
|
||||||
foreach($list as $key => $item) {
|
foreach($list as $key => $item) {
|
||||||
if ($item instanceof UiElement) {
|
if ($item instanceof UiElement) {
|
||||||
$this->append($item);
|
$this->append($item);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
elseif ( is_array($item) ) {
|
elseif ( is_array($item) ) {
|
||||||
|
@ -53,7 +54,7 @@ class UiSelect extends UiElement implements Extension {
|
||||||
else {
|
else {
|
||||||
$obj = $this->createOption($item, $key, $strict ? $key === $selected : $key == $selected);
|
$obj = $this->createOption($item, $key, $strict ? $key === $selected : $key == $selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->append($obj);
|
$this->append($obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +65,10 @@ class UiSelect extends UiElement implements Extension {
|
||||||
$option->text($name);
|
$option->text($name);
|
||||||
$option->attributes($attributes + [ 'value' => $value ]);
|
$option->attributes($attributes + [ 'value' => $value ]);
|
||||||
|
|
||||||
|
if ($selected) {
|
||||||
|
$option->attributes(['selected' => 'selected']);
|
||||||
|
}
|
||||||
|
|
||||||
return $option;
|
return $option;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue