From 8ae531c799aea31de6b8e5c966ae10f4cb77c6ac Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Fri, 17 Jun 2022 15:09:42 +0200 Subject: [PATCH] Fix the Canonical even Better! --- src/Canonical.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Canonical.php b/src/Canonical.php index 7b3e7bed0..3012f4f8d 100644 --- a/src/Canonical.php +++ b/src/Canonical.php @@ -105,10 +105,14 @@ public function get(?string $route = null, array $params = [], bool $absolute = return null; } - $this->setPath($route, $params); + $path = $this->getPath(); + + if ($route) { + $path = $this->returnPath($route, $params); + } if (! $absolute) { - return $this->getPath(); + return $path; } return sprintf( @@ -116,7 +120,7 @@ public function get(?string $route = null, array $params = [], bool $absolute = $this->getScheme(), $this->getHost(), ($this->getPort() ? ':' . $this->getPort() : ''), - $this->getPath() + $path ); } @@ -179,14 +183,19 @@ public function getPath(): string } public function setPath(?string $route = null, array $params = []): void + { + $this->path = $this->returnPath($route, $params); + } + + public function returnPath(?string $route = null, array $params = []): string { if (! $route && ! $this->getRequest()->attributes->has('_route')) { - return; + return ''; } elseif (! $route) { $route = $this->getRequest()->attributes->get('_route'); } - $this->path = $this->generateLink($route, $params, false); + return $this->generateLink($route, $params, false); } /**