Skip to content

Commit

Permalink
Add Halo handling to HaloRenderer and tests
Browse files Browse the repository at this point in the history
This commit includes a modification in HaloRenderer class where a new method 'setHaloCookie' checks if PHP_SAPI is 'cli' before setting the cookie. The 'render' method has also been modified to
  • Loading branch information
koriym committed Apr 20, 2024
1 parent d44c7aa commit 9e81d1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/Halo/HaloRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;
use const PHP_EOL;
use const PHP_SAPI;

final class HaloRenderer implements RenderInterface
{
Expand All @@ -63,7 +64,9 @@ public function __construct(
public function render(ResourceObject $ro)
{
if (! $this->isEableHalo()) {
return $this->renderer->render($ro);
$ro->view = $this->renderer->render($ro);

return $ro->view;
}

$originalView = $this->renderer->render($ro);
Expand All @@ -82,7 +85,7 @@ private function isEableHalo(): bool
}

if ($_GET[self::HALO_KEY] === '1') {
setcookie(self::HALO_COOKIE_KEY, '1');
$this->setHaloCookie();

return true;
}
Expand Down Expand Up @@ -290,4 +293,13 @@ private function getProfileInfo(ResourceObject $ro): string

return $html . '</div>';
}

public function setHaloCookie(): void
{
if (PHP_SAPI === 'cli') {
return;
}

setcookie(self::HALO_COOKIE_KEY, '1');
}
}
2 changes: 1 addition & 1 deletion tests/Fake/app/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

require dirname(__DIR__) . '/vendor/autoload.php';
require dirname(__DIR__, 4) . '/vendor/autoload.php';
exit((new Bootstrap())(PHP_SAPI === 'cli-server' ? 'dev-html-app' : 'dev-prod-html-app', $GLOBALS, $_SERVER));
exit((new Bootstrap())(PHP_SAPI === 'cli-server' ? 'dev-app' : 'dev-prod-app', $GLOBALS, $_SERVER));
1 change: 1 addition & 0 deletions tests/Halo/HaloModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class HaloModuleTest extends TestCase

protected function setUp(): void
{
$_GET['halo'] = '1';
$injector = Injector::getInstance('dev-app');
$this->resource = $injector->getInstance(ResourceInterface::class);
}
Expand Down

0 comments on commit 9e81d1d

Please sign in to comment.