Re-adding the ability to add a resource to the RouteCollectionBuilder

We need this because when you import a RouteCollection and this has a resource
on it, we need to pass that resource forward to the RouteCollectionBuilder
This commit is contained in:
Ryan Weaver 2015-10-27 20:28:52 -04:00
parent 7beea17a02
commit 3b67daacd5
2 changed files with 24 additions and 0 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Routing;
use Symfony\Component\Config\Exception\FileLoaderLoadException;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\ResourceInterface;
/**
* Helps add and import routes into a RouteCollection.
@ -35,6 +36,7 @@ class RouteCollectionBuilder
private $options = array();
private $schemes;
private $methods;
private $resources = array();
/**
* @param LoaderInterface $loader
@ -237,6 +239,20 @@ class RouteCollectionBuilder
return $this;
}
/**
* Adds a resource for this collection.
*
* @param ResourceInterface $resource
*
* @return $this
*/
private function addResource(ResourceInterface $resource)
{
$this->resources[] = $resource;
return $this;
}
/**
* Creates the final RouteCollection and returns it.
*
@ -291,6 +307,10 @@ class RouteCollectionBuilder
$routeCollection->addCollection($subCollection);
}
foreach ($this->resources as $resource) {
$routeCollection->addResource($resource);
}
}
return $routeCollection;

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Routing\Tests;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCollectionBuilder;
@ -29,6 +30,7 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
$originalRoute = new Route('/foo/path');
$expectedCollection = new RouteCollection();
$expectedCollection->add('one_test_route', $originalRoute);
$expectedCollection->addResource(new FileResource('file_resource.yml'));
$resolvedLoader
->expects($this->once())
@ -52,6 +54,8 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
$addedCollection = $importedRoutes->build();
$route = $addedCollection->get('one_test_route');
$this->assertSame($originalRoute, $route);
// should return file_resource.yml, which is in the original collection
$this->assertCount(1, $addedCollection->getResources());
}
/**