Skip to content

Commit 0662698

Browse files
author
Chirs Warner
committed
Fixed getRoutesByNames so that if the $idPrefix is not set, it bypasses the foreach loop.
Removed the .idea file from .gitignore Added Back the missing getRoutesByNames skipped test.
1 parent e633e1a commit 0662698

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ composer.lock
33
vendor
44
Tests/Resources/app/cache
55
Tests/Resources/app/logs
6-
.idea

Doctrine/Phpcr/RouteProvider.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function setPrefix($prefix)
6060
*/
6161
public function getRouteCollectionForRequest(Request $request)
6262
{
63-
$url = $request->getPathInfo();
63+
$url = $request->getPathInfo();
6464
$candidates = $this->getCandidates($url);
6565

6666
$collection = new RouteCollection();
@@ -77,7 +77,8 @@ public function getRouteCollectionForRequest(Request $request)
7777
$collection->add($key, $route);
7878
}
7979
}
80-
} catch (RepositoryException $e) {
80+
}
81+
catch (RepositoryException $e) {
8182
// TODO: how to determine whether this is a relevant exception or not?
8283
// https://github.com/symfony-cmf/RoutingBundle/issues/143
8384
// for example, getting /my//test (note the double /) is just an invalid path
@@ -95,17 +96,17 @@ public function getRouteCollectionForRequest(Request $request)
9596
*/
9697
protected function getCandidates($url)
9798
{
98-
$candidates = array();
99+
$candidates = array ();
99100
if ('/' !== $url) {
100101
if (preg_match('/(.+)\.[a-z]+$/i', $url, $matches)) {
101102
$candidates[] = $this->idPrefix . $url;
102-
$url = $matches[1];
103+
$url = $matches[1];
103104
}
104105

105106
$part = $url;
106107
while (false !== ($pos = strrpos($part, '/'))) {
107108
$candidates[] = $this->idPrefix . $part;
108-
$part = substr($url, 0, $pos);
109+
$part = substr($url, 0, $pos);
109110
}
110111
}
111112

@@ -117,15 +118,15 @@ protected function getCandidates($url)
117118
/**
118119
* {@inheritDoc}
119120
*/
120-
public function getRouteByName($name, $parameters = array())
121+
public function getRouteByName($name, $parameters = array ())
121122
{
122123

123124
// $name is the route document path
124-
if ( '' === $this->idPrefix || 0 === strpos($name, $this->idPrefix) ) {
125+
if ('' === $this->idPrefix || 0 === strpos($name, $this->idPrefix)) {
125126
$route = $this->getObjectManager()->find($this->className, $name);
126127
}
127128

128-
if (!$route) {
129+
if (empty($route)) {
129130
throw new RouteNotFoundException(sprintf('No route found for path "%s"', $name));
130131
}
131132

@@ -139,15 +140,20 @@ public function getRouteByName($name, $parameters = array())
139140
/**
140141
* {@inheritDoc}
141142
*/
142-
public function getRoutesByNames($names, $parameters = array())
143+
public function getRoutesByNames($names, $parameters = array ())
143144
{
144-
$routes = array();
145-
foreach ($names as $name) {
146-
if ('' === $this->idPrefix || 0 === strpos($name, $this->idPrefix)) {
147-
$routes[] = $name;
145+
$routes = array ();
146+
if ('' === $this->idPrefix) {
147+
foreach ($names as $name) {
148+
if (0 === strpos($name, $this->idPrefix)) {
149+
$routes[] = $name;
150+
}
148151
}
152+
} else {
153+
$routes = $names;
149154
}
150155

156+
151157
$collection = $this->getObjectManager()->findMany($this->className, $routes);
152158
foreach ($collection as $key => $document) {
153159
if (!$document instanceof SymfonyRoute) {
@@ -158,5 +164,4 @@ public function getRoutesByNames($names, $parameters = array())
158164

159165
return $collection;
160166
}
161-
162167
}

Tests/Unit/Doctrine/Phpcr/RouteProviderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ public function testGetRouteByNameNoRoutePrefixEmptyString()
230230
$routeProvider->getRouteByName('/cms/routes/test-route');
231231
}
232232

233+
public function testGetRoutesByNames()
234+
{
235+
$this->markTestIncomplete();
236+
}
233237

234238
/**
235239
* Use getRouteByName() with two different document managers.

0 commit comments

Comments
 (0)