-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAbstractRouteCollectionProvider.php
More file actions
56 lines (45 loc) · 1.51 KB
/
AbstractRouteCollectionProvider.php
File metadata and controls
56 lines (45 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php declare(strict_types=1);
namespace Symplify\ModularRouting\Routing;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\Routing\RouteCollection;
use Symplify\ModularRouting\Contract\Routing\RouteCollectionProviderInterface;
use Symplify\ModularRouting\Exception\FileNotFoundException;
abstract class AbstractRouteCollectionProvider implements RouteCollectionProviderInterface
{
/**
* @var LoaderResolverInterface
*/
private $loaderResolver;
public function __construct(LoaderResolverInterface $loaderResolver)
{
$this->loaderResolver = $loaderResolver;
}
protected function loadRouteCollectionFromFile(string $path): RouteCollection
{
$this->ensureFileExists($path);
$loader = $this->loaderResolver->resolve($path);
if ($loader === null) {
return new RouteCollection;
}
return $loader->load($path);
}
/**
* @param string[] $paths
*/
protected function loadRouteCollectionFromFiles(array $paths): RouteCollection
{
$routeCollection = new RouteCollection;
foreach ($paths as $path) {
$routeCollection->addCollection($this->loadRouteCollectionFromFile($path));
}
return $routeCollection;
}
private function ensureFileExists(string $path): void
{
if (! file_exists($path)) {
throw new FileNotFoundException(
sprintf('File "%s" was not found.', $path)
);
}
}
}