diff --git a/common/Alias/View.php b/common/Alias/View.php new file mode 100644 index 0000000..f28aeda --- /dev/null +++ b/common/Alias/View.php @@ -0,0 +1,5 @@ +render($response, 'home'); + } +} diff --git a/common/Definition/View.php b/common/Definition/View.php new file mode 100644 index 0000000..cfc21c6 --- /dev/null +++ b/common/Definition/View.php @@ -0,0 +1,8 @@ +separator = $separator; + } + protected $array; + public function start(): Merger { + $this->array = []; + return $this; + } + public function add($element): Merger { + $this->array []= $element; + return $this; + } + public function merge() { + return implode($this->separator, $this->array); + } +} diff --git a/common/Helper/Tree.php b/common/Helper/Tree.php new file mode 100644 index 0000000..38a9f00 --- /dev/null +++ b/common/Helper/Tree.php @@ -0,0 +1,58 @@ +merger = new Merger($separator); + } + protected $tree; + public function add($value, $parent = null, $alias = null): Tree { + if ($parent === null) { + if ($alias === null) { + $this->tree []= $value; + return $this; + } + $this->tree[$alias] = $value; + return $this; + } + if (!isset($this->tree[$parent])) { + return $this; + } + if ($alias === null) { + $this->tree []= $this->merger->start() + ->add($this->tree[$parent]) + ->add($value) + ->merge(); + return $this; + } + $this->tree[$alias] = $this->merger->start() + ->add($this->tree[$parent]) + ->add($value) + ->merge(); + return $this; + } + public function check_keys($tree) { + $bool = true; + foreach ($tree as $def) { + if (!isset($def[2])) { + continue; + } + $key = $def[2]; + $bool &= array_key_exists($key, $this->tree); + } + return $bool; + } + public function addTree($tree) { + while (!$this->check_keys($tree)) { + foreach ($tree as $def) { + $this->add($def[0], $def[1] ?? null, $def[2] ?? null); + } + } + } + public function build($tree) { + $this->tree = []; + $this->addTree($tree); + return (object) $this->tree; + } +}