Skip to content

Commit 549a3e2

Browse files
committed
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
1 parent aa2673b commit 549a3e2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Symfony/Component/Routing/RouteCollectionBuilder.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Config\Exception\FileLoaderLoadException;
1515
use Symfony\Component\Config\Loader\LoaderInterface;
16+
use Symfony\Component\Config\Resource\ResourceInterface;
1617

1718
/**
1819
* Helps add and import routes into a RouteCollection.
@@ -35,6 +36,7 @@ class RouteCollectionBuilder
3536
private $options = array();
3637
private $schemes;
3738
private $methods;
39+
private $resources = array();
3840

3941
/**
4042
* @param LoaderInterface $loader
@@ -237,6 +239,20 @@ public function setMethods($methods)
237239
return $this;
238240
}
239241

242+
/**
243+
* Adds a resource for this collection.
244+
*
245+
* @param ResourceInterface $resource
246+
*
247+
* @return $this
248+
*/
249+
private function addResource(ResourceInterface $resource)
250+
{
251+
$this->resources[] = $resource;
252+
253+
return $this;
254+
}
255+
240256
/**
241257
* Creates the final ArrayCollection, returns it, and clears everything.
242258
*
@@ -291,6 +307,10 @@ public function build()
291307

292308
$routeCollection->addCollection($subCollection);
293309
}
310+
311+
foreach ($this->resources as $resource) {
312+
$routeCollection->addResource($resource);
313+
}
294314
}
295315

296316
return $routeCollection;

src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Routing\Tests;
1313

14+
use Symfony\Component\Config\Resource\FileResource;
1415
use Symfony\Component\Routing\Route;
1516
use Symfony\Component\Routing\RouteCollection;
1617
use Symfony\Component\Routing\RouteCollectionBuilder;
@@ -29,6 +30,7 @@ public function testImport()
2930
$originalRoute = new Route('/foo/path');
3031
$expectedCollection = new RouteCollection();
3132
$expectedCollection->add('one_test_route', $originalRoute);
33+
$expectedCollection->addResource(new FileResource('file_resource.yml'));
3234

3335
$resolvedLoader
3436
->expects($this->once())
@@ -52,6 +54,8 @@ public function testImport()
5254
$addedCollection = $importedRoutes->build();
5355
$route = $addedCollection->get('one_test_route');
5456
$this->assertSame($originalRoute, $route);
57+
// should return file_resource.yml, which is in the original collection
58+
$this->assertCount(1, $addedCollection->getResources());
5559
}
5660

5761
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy