Skip to content

Commit 7746bc8

Browse files
committed
Merge pull request #238 from symfony-cmf/raise-error
no longer swallow the phpcr-odm exception
2 parents 814de93 + c7865fb commit 7746bc8

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Doctrine/Phpcr/RouteProvider.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Doctrine\Common\Persistence\ManagerRegistry;
1919
use Doctrine\ODM\PHPCR\DocumentManager;
2020

21+
use Psr\Log\LoggerInterface;
2122
use Symfony\Component\Routing\Route as SymfonyRoute;
2223
use Symfony\Component\Routing\RouteCollection;
2324
use Symfony\Component\Routing\Exception\RouteNotFoundException;
@@ -31,7 +32,7 @@
3132
/**
3233
* Loads routes from Doctrine PHPCR-ODM.
3334
*
34-
* This is <strong>NOT</strong> not a doctrine repository but just the route
35+
* This is <strong>NOT</strong> a doctrine repository but just the route
3536
* provider for the NestedMatcher. (you could of course implement this
3637
* interface in a repository class, if you need that)
3738
*
@@ -44,10 +45,20 @@ class RouteProvider extends DoctrineProvider implements RouteProviderInterface
4445
*/
4546
private $candidatesStrategy;
4647

47-
public function __construct(ManagerRegistry $managerRegistry, CandidatesInterface $candidatesStrategy, $className = null)
48-
{
48+
/**
49+
* @var LoggerInterface
50+
*/
51+
private $logger;
52+
53+
public function __construct(
54+
ManagerRegistry $managerRegistry,
55+
CandidatesInterface $candidatesStrategy,
56+
$className = null,
57+
LoggerInterface $logger = null
58+
) {
4959
parent::__construct($managerRegistry, $className);
5060
$this->candidatesStrategy = $candidatesStrategy;
61+
$this->logger = $logger;
5162
}
5263

5364
/**
@@ -79,11 +90,9 @@ public function getRouteCollectionForRequest(Request $request)
7990
}
8091
}
8192
} catch (RepositoryException $e) {
82-
// TODO: how to determine whether this is a relevant exception or not?
83-
// https://github.com/symfony-cmf/RoutingBundle/issues/143
84-
// for example, getting /my//test (note the double /) is just an invalid path
85-
// and means another router might handle this.
86-
// but if the PHPCR backend is down for example, we want to alert the user
93+
if ($this->logger) {
94+
$this->logger->critical($e);
95+
}
8796
}
8897

8998
return $collection;

Resources/config/provider-phpcr.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<argument type="service" id="doctrine_phpcr"/>
1818
<argument type="service" id="cmf_routing.phpcr_candidates_prefix"/>
1919
<argument>%cmf_routing.route_model.class%</argument>
20+
<argument type="service" id="logger" on-invalid="ignore" />
2021
<call method="setManagerName"><argument>%cmf_routing.dynamic.persistence.phpcr.manager_name%</argument></call>
2122
<call method="setRouteCollectionLimit"><argument>%cmf_routing.route_collection_limit%</argument></call>
2223
</service>

0 commit comments

Comments
 (0)