初始化仓库
This commit is contained in:
56
admin/components/UI/Node/NodeEl.php
Normal file
56
admin/components/UI/Node/NodeEl.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Node;
|
||||
|
||||
|
||||
use admin\components\UI\Node;
|
||||
|
||||
/**
|
||||
* node 属性
|
||||
*/
|
||||
class NodeEl
|
||||
{
|
||||
|
||||
public string $name = 'div';
|
||||
public $callback;
|
||||
public array $attr = [];
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $callback
|
||||
*/
|
||||
public function __construct($name, $callback = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
if ($callback instanceof \Closure) {
|
||||
$node = new Node();
|
||||
$callback($node);
|
||||
$this->callback = $node;
|
||||
}else {
|
||||
$this->callback = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$data = [
|
||||
'nodeName' => $this->name,
|
||||
];
|
||||
if ($this->callback instanceof Node) {
|
||||
$data['child'] = $this->callback->render();
|
||||
} else if ($this->callback) {
|
||||
$data['child'] = $this->callback;
|
||||
}
|
||||
return array_merge($data, $this->attr);
|
||||
}
|
||||
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
$this->attr[$method] = $arguments[0];
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user