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
12 changes: 6 additions & 6 deletions Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Dom/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}\"";
}
}
Expand Down
42 changes: 21 additions & 21 deletions SwiftRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand Down