Skip to content

Commit 6c9ce16

Browse files
authored
Merge pull request #404 from tugrul/route_expose_false
Route expose false
2 parents 86e2b61 + 6b29b97 commit 6c9ce16

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

Extractor/ExposedRoutesExtractor.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ public function getRoutes()
8383
foreach ($collection->all() as $name => $route) {
8484

8585
if ($route->hasOption('expose')) {
86-
$routes->add($name, $route);
86+
87+
$expose = $route->getOption('expose');
88+
89+
if ($expose !== false && $expose !== 'false') {
90+
$routes->add($name, $route);
91+
}
8792
continue;
8893
}
8994

@@ -196,8 +201,12 @@ public function getResources()
196201
*/
197202
public function isRouteExposed(Route $route, $name)
198203
{
199-
return true === $route->hasOption('expose') ||
200-
('' !== $this->pattern && preg_match('#^' . $this->pattern . '$#', $name));
204+
if (false === $route->hasOption('expose')) {
205+
return ('' !== $this->pattern && preg_match('#^' . $this->pattern . '$#', $name));
206+
}
207+
208+
$status = $route->getOption('expose');
209+
return ($status !== false && $status !== 'false');
201210
}
202211

203212
protected function getDomainByRouteMatches($matches, $name)

Tests/Extractor/ExposedRoutesExtractorTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,33 @@ public function testGetHostOverHttps($host, $httpsPort, $expected)
140140
$this->assertEquals($expected, $extractor->getHost());
141141
}
142142

143+
public function testExposeFalse()
144+
{
145+
$expected = new RouteCollection();
146+
$expected->add('user_public_1', new Route('/user/public/1'));
147+
$expected->add('user_public_2', new Route('/user/public/2', [], [], ['expose' => true]));
148+
$expected->add('user_public_3', new Route('/user/public/3', [], [], ['expose' => 'true']));
149+
$expected->add('user_public_4', new Route('/user/public/4', [], [], ['expose' => 'default']));
150+
$expected->add('user_public_5', new Route('/user/public/5', [], [], ['expose' => 'group_name']));
151+
$expected->add('user_secret_1', new Route('/user/secret/1', [], [], ['expose' => false]));
152+
$expected->add('user_secret_2', new Route('/user/secret/2', [], [], ['expose' => 'false']));
153+
154+
$router = $this->getRouter($expected);
155+
$extractor = new ExposedRoutesExtractor($router, array('user_.+'), $this->cacheDir, []);
156+
157+
$this->assertCount(5, $extractor->getRoutes());
158+
159+
foreach ($expected->all() as $name => $route) {
160+
161+
if (in_array($name, ['user_secret_1', 'user_secret_2'])) {
162+
$this->assertFalse($extractor->isRouteExposed($route, $name));
163+
} else {
164+
$this->assertTrue($extractor->isRouteExposed($route, $name));
165+
}
166+
167+
}
168+
}
169+
143170
/**
144171
* @return array
145172
*/

0 commit comments

Comments
 (0)