Skip to content

Commit

Permalink
Merge pull request #404 from tugrul/route_expose_false
Browse files Browse the repository at this point in the history
Route expose false
  • Loading branch information
tobias-93 authored Dec 15, 2021
2 parents 86e2b61 + 6b29b97 commit 6c9ce16
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Extractor/ExposedRoutesExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ public function getRoutes()
foreach ($collection->all() as $name => $route) {

if ($route->hasOption('expose')) {
$routes->add($name, $route);

$expose = $route->getOption('expose');

if ($expose !== false && $expose !== 'false') {
$routes->add($name, $route);
}
continue;
}

Expand Down Expand Up @@ -196,8 +201,12 @@ public function getResources()
*/
public function isRouteExposed(Route $route, $name)
{
return true === $route->hasOption('expose') ||
('' !== $this->pattern && preg_match('#^' . $this->pattern . '$#', $name));
if (false === $route->hasOption('expose')) {
return ('' !== $this->pattern && preg_match('#^' . $this->pattern . '$#', $name));
}

$status = $route->getOption('expose');
return ($status !== false && $status !== 'false');
}

protected function getDomainByRouteMatches($matches, $name)
Expand Down
27 changes: 27 additions & 0 deletions Tests/Extractor/ExposedRoutesExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@ public function testGetHostOverHttps($host, $httpsPort, $expected)
$this->assertEquals($expected, $extractor->getHost());
}

public function testExposeFalse()
{
$expected = new RouteCollection();
$expected->add('user_public_1', new Route('/user/public/1'));
$expected->add('user_public_2', new Route('/user/public/2', [], [], ['expose' => true]));
$expected->add('user_public_3', new Route('/user/public/3', [], [], ['expose' => 'true']));
$expected->add('user_public_4', new Route('/user/public/4', [], [], ['expose' => 'default']));
$expected->add('user_public_5', new Route('/user/public/5', [], [], ['expose' => 'group_name']));
$expected->add('user_secret_1', new Route('/user/secret/1', [], [], ['expose' => false]));
$expected->add('user_secret_2', new Route('/user/secret/2', [], [], ['expose' => 'false']));

$router = $this->getRouter($expected);
$extractor = new ExposedRoutesExtractor($router, array('user_.+'), $this->cacheDir, []);

$this->assertCount(5, $extractor->getRoutes());

foreach ($expected->all() as $name => $route) {

if (in_array($name, ['user_secret_1', 'user_secret_2'])) {
$this->assertFalse($extractor->isRouteExposed($route, $name));
} else {
$this->assertTrue($extractor->isRouteExposed($route, $name));
}

}
}

/**
* @return array
*/
Expand Down

0 comments on commit 6c9ce16

Please # to comment.