diff --git a/phpstan.neon b/phpstan.neon index f102e94..1398dd8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,6 +6,3 @@ parameters: paths: - src/ level: 5 - ignoreErrors: - - '#Parameter \#2 \$replace of function substr_replace expects array\|string, Illuminate\\Contracts\\Support\\Htmlable given.#' - - '#Parameter \#2 \$replace of function substr_replace expects array\|string, Illuminate\\Contracts\\View\\View given.#' diff --git a/src/Response/ResponseHandle.php b/src/Response/ResponseHandle.php index 4663978..029cdb7 100644 --- a/src/Response/ResponseHandle.php +++ b/src/Response/ResponseHandle.php @@ -19,12 +19,22 @@ public function __invoke(): Response $content = $this->response->getContent(); if (($head = strpos($content, '')) !== false) { - $content = substr_replace($content, $this->render->css(), $head + 6, 0); - $content = substr_replace($content, $this->render->js(), $head + 6, 0); + $content = substr_replace($content, $this->render->css(), $head + 6, 0); // @phpstan-ignore-line + $content = substr_replace($content, $this->render->js(), $head + 6, 0); // @phpstan-ignore-line } - $content = preg_replace('/(]*>)/i', '$1'.$this->render->component(), $content); + // Although this code is not the best, it was the only viable way found, at least for now, + // to insert the envbar in the correct place, after , for situations where we have things + // like "x-on:redirect="setTimeout(() => window.location.href = $event.detail.route, $event.detail.time ?? 3000)">" + // inside the , things with symbols that mess up regex. + $explode = array_map(function (string $line): string { + if (str_contains($line, 'render->component(); // @phpstan-ignore-line + } - return $this->response->setContent($content); + return $line; + }, explode("\n", $content)); + + return $this->response->setContent(implode("\n", $explode)); } }