Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions AbstractProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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)) {
Expand Down
92 changes: 46 additions & 46 deletions Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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])) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
Expand All @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion Interfaces/ProtocolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getProtocolData(): array;

/**
* Shortcut to @getProtocolData
* Pollyfill dependencies
* polyfill dependencies
* @return array
*/
public function list(): array;
Expand Down
17 changes: 8 additions & 9 deletions Protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -35,7 +34,7 @@ public function getProtocolData(): array

/**
* Shortcut to @getProtocolData
* Pollyfill dependencies
* polyfill dependencies
* @return array
*/
public function list(): array
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
}
],
"require": {
"php": ">=8.0",
"maplephp/swiftrender": "^1.0"
"php": ">=8.2",
"maplephp/swiftrender": "^2.1"
},
"autoload": {
"psr-4": {
Expand Down