diff --git a/AbstractProtocol.php b/AbstractProtocol.php index dc1e773..edc3441 100755 --- a/AbstractProtocol.php +++ b/AbstractProtocol.php @@ -4,12 +4,11 @@ abstract class AbstractProtocol { - protected $isStart = false; - protected $protocol = array(); - protected $protocolID = array(); + protected $protocol = []; + protected $protocolID = []; protected $statusCode = 200; - protected $path = array(); + protected $path = []; /** * Propagate the active returnable data @@ -69,11 +68,11 @@ public function getPart(?string $slug): ?array */ public function getMultipleParts(array $arr, ?callable $call = null): array { - $new = array(); + $new = []; foreach ($arr as $slug) { if ($data = $this->getPart($slug)) { $new[] = $data; - if (!is_null($call)) { + if ($call !== null) { $call($data); } } @@ -90,15 +89,16 @@ public function getMultipleParts(array $arr, ?callable $call = null): array public function add(array $vars, string|int $identifier, mixed $data): void { $key = end($vars); - $this->protocol[$key] = array("uri" => $vars, "id" => $identifier, "data" => $data); + $key = $key->get(); + $this->protocol[$key] = ["uri" => $vars, "id" => $identifier, "data" => $data]; $this->protocolID[$identifier] = $key; } - - /** - * Check if a 301 redirect result - * @param array $vars - * @return bool - */ + + /** + * Check if a 301 redirect result + * @param array $vars + * @return bool + */ final protected function is301(array $vars): bool { if (count($vars) !== count($this->path)) { diff --git a/Builder.php b/Builder.php index 80d7b36..bdd9c2f 100755 --- a/Builder.php +++ b/Builder.php @@ -12,23 +12,23 @@ class Builder private $arr; private $parent = 0; private $permalink; - private $uri = array(); + private $uri = []; private $uriImp; private $uriPrepend; - private $data = array(); + private $data = []; private $item; private $currentID; private ?ProtocolInterface $protocol = null; private $callback; private $dom; - private $level = array(); + private $level = []; private $ul; private $li; private $ulTag; private $ulTagClass = "level-1 clearfix"; private $liTag; private $theUL; - private $where = array(); + private $where = []; private $maxLevel = 0; private $multiple = false; private $select = 'main'; @@ -167,7 +167,7 @@ public function getChildren(int $parent): ?array */ public function getChildrenID(int $parent): array { - $new = array(); + $new = []; if ($arr = $this->getChildren($parent)) { foreach ($arr as $id => $_notUsedValue) { $new[] = (int)$id; @@ -179,10 +179,10 @@ public function getChildrenID(int $parent): array /** * Get last item in parent * @param int $parent - * @param array &$array + * @param array &$array * @return array */ - public function lastChild($parent, array &$array = array()): array + public function lastChild($parent, array &$array = []): array { $arr = $this->getItems(); if (isset($arr[$parent])) { @@ -302,49 +302,49 @@ public function get(string $type, int $parent = 0, ?callable $callback = null): { - //if (is_null($this->dom)) { - if (is_null($this->item)) { - return false; - } - - if (is_null($this->currentID) && $current = $this->protocol()->getData()) { - end($current); - $this->currentID = key($current); - } + //if ($this->dom === null) { + if ($this->item === null) { + return false; + } - if ($this->multiple) { - if (is_null($this->select)) { - throw new \Exception("When using multiple menues you also need to select which menu you want to use: @select(0)->get('nav')", 1); - } - if (empty($this->item[$this->select])) { - throw new \Exception("The multiple menue has wrong menu ID: @select(MENU_ID)->get('nav')", 1); - } - $items = $this->item[$this->select]; + if ($this->currentID === null && $current = $this->protocol()->getData()) { + end($current); + $this->currentID = key($current); + } - } else { - $items = $this->item; + if ($this->multiple) { + if ($this->select === null) { + throw new \Exception("When using multiple menues you also need to select which menu you want to use: @select(0)->get('nav')", 1); } + if (empty($this->item[$this->select])) { + throw new \Exception("The multiple menue has wrong menu ID: @select(MENU_ID)->get('nav')", 1); + } + $items = $this->item[$this->select]; - $this->ulTag = $this->callback[$type]['ul']; - $this->liTag = $this->callback[$type]['li']; - $this->dom = Document::withDom($type); - $this->level[0] = 0; + } else { + $items = $this->item; + } - $elem = $this->dom->create($this->ulTag); + $this->ulTag = $this->callback[$type]['ul']; + $this->liTag = $this->callback[$type]['li']; + $this->dom = Document::withDom($type); + $this->level[0] = 0; - if (!($elem instanceof Element)) { - throw new \Exception("Could not find connection to Element instance", 1); - } + $elem = $this->dom->create($this->ulTag); - $this->ul[0] = $elem->attr("class", "{$this->ulTagClass}"); - $this->theUL = $this->ul[0]; - if (isset($this->callback[$type]['ulCall'])) { - $this->callback[$type]['ulCall']($this->theUL, false, false, 1); - } - $this->iterateView($items, $type, $parent); - // Reset - $this->level = array(); - $this->liTag = $this->ulTag = null; + if (!($elem instanceof Element)) { + throw new \Exception("Could not find connection to Element instance", 1); + } + + $this->ul[0] = $elem->attr("class", "{$this->ulTagClass}"); + $this->theUL = $this->ul[0]; + if (isset($this->callback[$type]['ulCall'])) { + $this->callback[$type]['ulCall']($this->theUL, false, false, 1); + } + $this->iterateView($items, $type, $parent); + // Reset + $this->level = []; + $this->liTag = $this->ulTag = null; //} return $this->dom->execute($callback); @@ -474,7 +474,7 @@ private function validateWhere(object $obj): bool { foreach ($this->where as $k => $v) { $val = ($obj->{$k} ?? null); - if (!is_null($val) && (string)$val !== (string)$v) { + if ($val !== null && (string)$val !== (string)$v) { return false; } } @@ -483,7 +483,7 @@ private function validateWhere(object $obj): bool public function uriAppend(array $array) { - $arr = array(); + $arr = []; foreach ($array as $key => $value) { $arr["w{$key}"] = $value; } @@ -494,7 +494,7 @@ public function uriAppend(array $array) public function uriPrepend(array $array) { $count = 0; - $new = array(); + $new = []; foreach ($array as $uri) { $new["nest-prepend-{$count}"] = $uri; $count++; diff --git a/Interfaces/ProtocolInterface.php b/Interfaces/ProtocolInterface.php index 024da5c..3250e16 100755 --- a/Interfaces/ProtocolInterface.php +++ b/Interfaces/ProtocolInterface.php @@ -20,7 +20,7 @@ public function getProtocolData(): array; /** * Shortcut to @getProtocolData - * Pollyfill dependencies + * polyfill dependencies * @return array */ public function list(): array; diff --git a/Protocol.php b/Protocol.php index acd220c..9a9627f 100755 --- a/Protocol.php +++ b/Protocol.php @@ -6,9 +6,8 @@ class Protocol extends AbstractProtocol implements ProtocolInterface { - - protected $data = array(); - protected $vars = array(); + protected $data = []; + protected $vars = []; protected $startVars; public function __construct() @@ -35,7 +34,7 @@ public function getProtocolData(): array /** * Shortcut to @getProtocolData - * Pollyfill dependencies + * polyfill dependencies * @return array */ public function list(): array @@ -175,7 +174,7 @@ public function setVars(array $vars): self */ public function changeStartVars(?array $arr): self { - $this->startVars = is_null($arr) ? [] : $arr; + $this->startVars = $arr === null ? [] : $arr; return $this; } @@ -186,8 +185,8 @@ public function changeStartVars(?array $arr): self */ public function load(?array $vars = null): self { - $this->data = array(); - if (is_null($vars)) { + $this->data = []; + if ($vars === null) { $vars = $this->vars; } @@ -207,8 +206,8 @@ public function load(?array $vars = null): self } else { $this->isStart = true; } - - $this->validateStartObject(is_null($this->startVars) ? $vars : $this->startVars); + + $this->validateStartObject($this->startVars === null ? $vars : $this->startVars); return $this; } diff --git a/composer.json b/composer.json index d6eed3e..0f046a8 100755 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ } ], "require": { - "php": ">=8.0", - "maplephp/swiftrender": "^1.0" + "php": ">=8.2", + "maplephp/swiftrender": "^2.1" }, "autoload": { "psr-4": {