Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] Changing RouteCollectionBuilder::import() behavior to add to the builder #16477

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
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 8 additions & 4 deletions src/Symfony/Component/Routing/RouteCollectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ public function __construct(LoaderInterface $loader = null)
/**
* Import an external routing resource and returns the RouteCollectionBuilder.
*
* $routes->mount('/blog', $routes->import('blog.yml'));
* $routes->import('blog.yml', '/blog');
*
* @param mixed $resource
* @param string $type
* @param mixed $resource
* @param string|null $prefix
* @param string $type
*
* @return RouteCollectionBuilder
*
* @throws FileLoaderLoadException
*/
public function import($resource, $type = null)
public function import($resource, $prefix = '/', $type = null)
{
/** @var RouteCollection $collection */
$collection = $this->load($resource, $type);
Expand All @@ -73,6 +74,9 @@ public function import($resource, $type = null)
$builder->addResource($resource);
}

// mount into this builder
$this->mount($prefix, $builder);

return $builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testImport()

// import the file!
$routes = new RouteCollectionBuilder($loader);
$importedRoutes = $routes->import('admin_routing.yml', 'yaml');
$importedRoutes = $routes->import('admin_routing.yml', '/', 'yaml');

// we should get back a RouteCollectionBuilder
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollectionBuilder', $importedRoutes);
Expand All @@ -56,6 +56,9 @@ public function testImport()
$this->assertSame($originalRoute, $route);
// should return file_resource.yml, which is in the original collection
$this->assertCount(1, $addedCollection->getResources());

// make sure the routes were imported into the top-level builder
$this->assertCount(1, $routes->build());
}

/**
Expand Down Expand Up @@ -285,7 +288,7 @@ public function testFlushSetsPrefixedWithMultipleLevels()
->method('load')
->will($this->returnValue($importedCollection));
// import this from the /admin route builder
$adminRoutes->mount('/imported', $adminRoutes->import('admin.yml'));
$adminRoutes->import('admin.yml', '/imported');

$collection = $routes->build();
$this->assertEquals('/admin/dashboard', $collection->get('admin_dashboard')->getPath(), 'Routes before mounting have the prefix');
Expand Down