diff --git a/Dom/Document.php b/Dom/Document.php index 8407cc7..771dae0 100755 --- a/Dom/Document.php +++ b/Dom/Document.php @@ -48,7 +48,7 @@ public function __toString(): string */ public function get(): string { - if (is_null($this->html)) { + if ($this->html === null) { $this->execute(); } return $this->html; @@ -107,7 +107,7 @@ public function create($element, $value = null, ?string $bind = null): ElementIn { $inst = new Element($element, $value); - if (!is_null($bind)) { + if ($bind !== null) { $this->elements[$bind] = $inst; } else { $this->elements[] = $inst; @@ -125,10 +125,10 @@ public function create($element, $value = null, ?string $bind = null): ElementIn public function createPrepend(string $element, ?string $value = null, ?string $bind = null): ElementInterface { $inst = new Element($element, $value); - if (is_null($this->elements)) { + if ($this->elements === null) { $this->elements = []; } - if (!is_null($bind)) { + if ($bind !== null) { //$new[$bind] = $inst; $this->elements = array_merge([$bind => $inst], $this->elements); } else { @@ -175,7 +175,7 @@ public function execute(?callable $call = null): string { $this->html = ""; - if (is_null($this->elements)) { + if ($this->elements === null) { if (method_exists($this, "withElement")) { $inst = $this->withElement(); $this->elements[] = $inst; @@ -220,7 +220,7 @@ private function build(array $arr, ?callable $call = null): void private function buildCallable($elemObj, $key, $hasNoEnding, ?callable $call): void { - if (!is_null($call)) { + if ($call !== null) { $call($elemObj, $key, $hasNoEnding); } } diff --git a/Dom/Element.php b/Dom/Element.php index cdcf015..d650528 100755 --- a/Dom/Element.php +++ b/Dom/Element.php @@ -139,7 +139,7 @@ public function getEl(): string public function withElement(?string $elem = null): self { $inst = clone $this; - if (!is_null($elem)) { + if ($elem !== null) { $inst->elem = $elem; } return $inst; @@ -155,7 +155,7 @@ protected function buildAttr(): string if (count($this->attr) > 0) { foreach ($this->attr as $k => $v) { $attr .= " {$k}"; - if (!is_null($v)) { + if ($v !== null) { $attr .= "=\"{$v}\""; } } diff --git a/SwiftRender.php b/SwiftRender.php index 2ee3a7a..9ea6705 100755 --- a/SwiftRender.php +++ b/SwiftRender.php @@ -11,8 +11,8 @@ use MaplePHP\Cache\Cache; use MaplePHP\Cache\Handlers\FileSystemHandler; -use MaplePHP\Cache\Interfaces\CacheInterface; -use MaplePHP\Container\Interfaces\ContainerInterface; +use Psr\SimpleCache\CacheInterface; +use Psr\Container\ContainerInterface; use Exception; use BadMethodCallException; use MaplePHP\DTO\Format\Arr; @@ -58,7 +58,7 @@ public function __construct() */ public function __call(string $method, array $args): ContainerInterface { - if (!is_null($this->container)) { + if ($this->container !== null) { if ($this->container->has($method)) { return $this->container->get($method, $args); } @@ -184,7 +184,7 @@ public function setPartialDir(string $dir): self */ public function setIndex(string|callable $file): self { - if (is_null($this->file) && is_string($file)) { + if ($this->file === null && is_string($file)) { $this->setFile($file); } $func = $this->build($file); @@ -214,7 +214,7 @@ public function setBuffer(string $output): self */ public function setView(string|callable $file, array $args = []): self { - if (is_null($this->file) && is_string($file)) { + if ($this->file === null && is_string($file)) { $this->setFile($file); } $func = $this->build($file, $args); @@ -247,7 +247,7 @@ public function withView(string $file, array $args = []): self public function setPartial(string $partial, array $args = [], int|false $cacheTime = false): self { $keys = $this->selectPartial($partial, $file); - if (is_null($this->file)) { + if ($this->file === null) { $this->setFile($file); } $func = $this->build($this->file, $args, $partial, $cacheTime); @@ -299,7 +299,7 @@ public function bindToBody(string $key, array $bindArr, array $args = []): self */ public function findBind(string|int $find, bool $overwrite = false): void { - if (!is_null($this->bindArr) && ($overwrite || is_null($this->bindView))) { + if ($this->bindArr !== null && ($overwrite || $this->bindView === null)) { foreach ($this->bindArr as $get => $arr) { if (in_array($find, $arr)) { $this->get = "bindView"; @@ -317,7 +317,7 @@ public function findBind(string|int $find, bool $overwrite = false): void */ public function index(?array $args = null): self { - if (!is_null($args)) { + if ($args !== null) { $this->arg = $args; } $this->get = "index"; @@ -341,7 +341,7 @@ public function buffer(): self */ public function view(?array $args = null): self { - if (!is_null($args)) { + if ($args !== null) { $this->arg = $args; } $this->get = "view"; @@ -371,7 +371,7 @@ final public function get(?array $args = null): string $this->buildView(); $output = $this->{$this->get}; ob_start(); - if (!is_null($this->arg)) { + if ($this->arg !== null) { if (is_array($output)) { if (isset($output[$this->arg])) { foreach ($output[$this->arg] as $part) { @@ -380,7 +380,7 @@ final public function get(?array $args = null): string } } } else { - if (is_null($output)) { + if ($output === null) { throw new Exception("Expecting the \"$this->get\" view.", 1); } else { $output($args); @@ -399,7 +399,7 @@ final public function get(?array $args = null): string */ private function buildView(): void { - if (!is_null($this->bindView)) { + if ($this->bindView !== null) { if ($this->existAtGet("buffer")) { $this->buffer = $this->bindView; } @@ -427,12 +427,12 @@ private function build( int|false $cacheTime = false ): callable { - if(is_null($this->cache) && $cacheTime !== false) { + if ($this->cache === null && $cacheTime !== false) { throw new Exception("Cache is not configured"); } $func = function ($argsFromFile) use ($file, $args, $partialKey, $cacheTime) { - if (($dir = ($this->dir[$this->get] ?? null)) || !is_null($dir)) { + if (($dir = ($this->dir[$this->get] ?? null)) || $dir !== null) { if (is_callable($file)) { $out = $file($this, $args); if (is_string($out)) { @@ -444,8 +444,8 @@ private function build( $missingFiles = []; $files = explode("|", $file); - foreach($files as $file) { - if($file[0] === "!") { + foreach ($files as $file) { + if ($file[0] === "!") { $file = substr($file, 1); $throwError = false; } @@ -462,7 +462,7 @@ private function build( $missingFiles[] = $file; } } - if($throwError && count($missingFiles) > 0) { + if ($throwError && count($missingFiles) > 0) { throw new Exception("Could not require template \"$this->get\" files: ".implode(", ", $missingFiles).".", 1); } } @@ -493,14 +493,14 @@ private function getOutput( array $args = [], int|false $cacheTime = false ): void { - if($this->get == "partial" && !is_null($this->cache) && $cacheTime !== false) { + if ($this->get == "partial" && $this->cache !== null && $cacheTime !== false) { $partialKey = str_replace(["!", "/"], ["", "_"], $partialKey); $updateTime = filemtime($filePath); $cacheKey = $partialKey."-".$updateTime; - if(!$this->cache->has($cacheKey)) { + if (!$this->cache->has($cacheKey)) { $clear = Arr::value($this->cache->getAllKeys())->wildcardSearch("$partialKey-*")->get(); - if(count($clear)) { + if (count($clear)) { $this->cache->deleteMultiple($clear); } @@ -628,7 +628,7 @@ final protected function selectPartial(string $partialKey, ?string &$file = null */ final protected function cleanKey(string $key): string { - if(str_starts_with($key, "!")) { + if (str_starts_with($key, "!")) { return substr($key, 1); } return $key; diff --git a/composer.json b/composer.json index 07275fc..b430dc0 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,6 @@ { "name": "maplephp/swiftrender", "type": "library", - "version": "v2.0.1", "description": "PHP SwiftRender is a pure and highly portable PHP template library.", "keywords": ["output buffer", "template", "engine", "partials", "components", "views"], "homepage": "https://wazabii.se", @@ -17,9 +16,9 @@ } ], "require": { - "php": ">=8.0", - "maplephp/dto": "^3.0", - "maplephp/container": "^1.0" + "php": ">=8.2", + "maplephp/dto": "^3.1", + "maplephp/container": "^2.0" }, "autoload": { "psr-4": {