10000 [Routing] Fixed the importing of files using glob patterns that match multiple resources by skalpa · Pull Request #26600 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] Fixed the importing of files using glob patterns that match multiple resources #26600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed glob patterns support in RoutingConfigurator
  • Loading branch information
skalpa committed Mar 19, 2018
commit e5dfabad69257616f61076407f0fef585ce84c06
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
final public function import($resource, $type = null, $ignoreErrors = false)
{
$this->loader->setCurrentDir(dirname($this->path));
$subCollection = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
if (!is_array($imported)) {
return new ImportConfigurator($this->collection, $imported);
}

return new ImportConfigurator($this->collection, $subCollection);
$mergedCollection = new RouteCollection();
foreach ($imported as $subCollection) {
$mergedCollection->addCollection($subCollection);
}

return new ImportConfigurator($this->collection, $mergedCollection);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
return $routes->import('php_dsl_ba?.php');
};
12 changes: 12 additions & 0 deletions src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl_bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$collection = $routes->collection();

$collection->add('bar_route', '/bar')
->defaults(['_controller' => 'AppBundle:Bar:view']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array() instead of [] (same below, see fabbot patch)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, old habits. Fixed.


return $collection;
};
12 changes: 12 additions & 0 deletions src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl_baz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$collection = $routes->collection();

$collection->add('baz_route', '/baz')
->defaults(['_controller' => 'AppBundle:Baz:view']);

return $collection;
};
13 changes: 13 additions & 0 deletions src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,17 @@ public function testRoutingConfigurator()

$this->assertEquals($expectedCollection, $routeCollection);
}

public function testRoutingConfiguratorCanImportGlobPatterns()
{
$locator = new FileLocator(array(__DIR__.'/../Fixtures/glob'));
$loader = new PhpFileLoader($locator);
$routeCollection = $loader->load('php_dsl.php');

$route = $routeCollection->get('bar_route');
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));

$route = $routeCollection->get('baz_route');
$this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
}
}
0