Skip to content

Commit

Permalink
Merge pull request #81 from softspring/prevent-exceptions-on-cms-router
Browse files Browse the repository at this point in the history
Prevent exceptions on cms router
  • Loading branch information
javihgil committed May 18, 2023
2 parents 83658f5 + 92ab0ef commit 53a1ed2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Routing/CmsRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\CmsBundle\Routing;

use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
Expand All @@ -18,12 +19,14 @@ class CmsRouter implements RouterInterface, RequestMatcherInterface, WarmableInt
protected Router $staticRouter;
protected UrlMatcher $urlMatcher;
protected UrlGenerator $urlGenerator;
protected LoggerInterface $logger;

public function __construct(Router $staticRouter, UrlMatcher $urlMatcher, UrlGenerator $urlGenerator)
public function __construct(Router $staticRouter, UrlMatcher $urlMatcher, UrlGenerator $urlGenerator, LoggerInterface $cmsLogger)
{
$this->staticRouter = $staticRouter;
$this->urlMatcher = $urlMatcher;
$this->urlGenerator = $urlGenerator;
$this->logger = $cmsLogger;
}

public function setContext(RequestContext $context): void
Expand Down Expand Up @@ -80,7 +83,12 @@ public function match(string $pathinfo): array

public function matchRequest(Request $request): array
{
$attributes = $this->urlMatcher->matchRequest($request);
try {
$attributes = $this->urlMatcher->matchRequest($request);
} catch (\Exception $e) {
$attributes = [];
$this->logger->warning(sprintf('Caught exception in CmsRouter->matchRequest: %s', $e->getMessage()));
}

if (isset($attributes['_controller'])) {
return $attributes;
Expand Down

0 comments on commit 53a1ed2

Please sign in to comment.