From d44c7aa5bc0e99f88e7cad9c1aefb3ae2e3bb0a5 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sat, 20 Apr 2024 13:29:34 +0900 Subject: [PATCH] Update halo rendering logic and conditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored method "isDisableHalo" to "isEnableHalo" in HaloRenderer class. The change in function name is also accompanied by an update in its logic – specifically related to the condition checks and setcookie values. Furthermore, adjusted the call in the 'render' function to reflect this modification. This improves the understanding and readability of the code. --- src/Halo/HaloRenderer.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Halo/HaloRenderer.php b/src/Halo/HaloRenderer.php index db2e503..1dc7bdd 100644 --- a/src/Halo/HaloRenderer.php +++ b/src/Halo/HaloRenderer.php @@ -62,7 +62,7 @@ public function __construct( */ public function render(ResourceObject $ro) { - if ($this->isDisableHalo()) { + if (! $this->isEableHalo()) { return $this->renderer->render($ro); } @@ -75,19 +75,21 @@ public function render(ResourceObject $ro) return $haloView; } - private function isDisableHalo(): bool + private function isEableHalo(): bool { - $disableHalo = (isset($_GET[self::HALO_KEY]) && $_GET[self::HALO_KEY] === '0') || isset($_COOKIE[self::HALO_COOKIE_KEY]); - if (! empty($_GET[self::HALO_KEY]) && $_GET[self::HALO_KEY] === '1') { - $disableHalo = false; - setcookie(self::HALO_COOKIE_KEY, '', time() - 3600); + if (! isset($_GET[self::HALO_KEY])) { + return isset($_COOKIE[self::HALO_COOKIE_KEY]); } - if ($disableHalo) { - setcookie(self::HALO_COOKIE_KEY, '0'); + if ($_GET[self::HALO_KEY] === '1') { + setcookie(self::HALO_COOKIE_KEY, '1'); + + return true; } - return $disableHalo; + setcookie(self::HALO_COOKIE_KEY, '', time() - 3600); // delete cookies + + return false; } private function addJsDevTools(string $body): string