@@ 7-57 (lines=51) @@ | ||
4 | ||
5 | use Rudolf\Component\Routing\RouteCollection; |
|
6 | ||
7 | class Routing |
|
8 | { |
|
9 | /** |
|
10 | * @var RouteCollection |
|
11 | */ |
|
12 | private $collection; |
|
13 | ||
14 | /** |
|
15 | * @var array |
|
16 | */ |
|
17 | private $modules; |
|
18 | ||
19 | /** |
|
20 | * @var string |
|
21 | */ |
|
22 | private $path; |
|
23 | ||
24 | /** |
|
25 | * Constructor. |
|
26 | * |
|
27 | * @param array $modules |
|
28 | * @param RouteCollection $collection |
|
29 | * @param string $path from-root path to modules directory |
|
30 | */ |
|
31 | public function __construct(array $modules, RouteCollection $collection, $path = '/modules') |
|
32 | { |
|
33 | $this->collection = $collection; |
|
34 | $this->modules = $modules; |
|
35 | $this->path = $path; |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * Add routes to collection. |
|
40 | * |
|
41 | * @return RouteCollection |
|
42 | */ |
|
43 | public function addRoutes() |
|
44 | { |
|
45 | $collection = $this->collection; |
|
46 | ||
47 | foreach ($this->modules as $key => $value) { |
|
48 | $file = $this->path.'/'.$value->getName().'/routing.php'; |
|
49 | ||
50 | if (is_file($file)) { |
|
51 | include $file; |
|
52 | } |
|
53 | } |
|
54 | ||
55 | return $collection; |
|
56 | } |
|
57 | } |
|
58 |
@@ 7-57 (lines=51) @@ | ||
4 | ||
5 | use Rudolf\Component\Routing\RouteCollection; |
|
6 | ||
7 | class Routing |
|
8 | { |
|
9 | /** |
|
10 | * @var RouteCollection |
|
11 | */ |
|
12 | private $collection; |
|
13 | ||
14 | /** |
|
15 | * @var array |
|
16 | */ |
|
17 | private $plugins; |
|
18 | ||
19 | /** |
|
20 | * @var string |
|
21 | */ |
|
22 | private $path; |
|
23 | ||
24 | /** |
|
25 | * Constructor. |
|
26 | * |
|
27 | * @param array $plugins |
|
28 | * @param RouteCollection $collection |
|
29 | * @param string $path from-root path to plugins directory |
|
30 | */ |
|
31 | public function __construct(array $plugins, RouteCollection $collection, $path = '/plugins') |
|
32 | { |
|
33 | $this->collection = $collection; |
|
34 | $this->plugins = $plugins; |
|
35 | $this->path = $path; |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * Add routes to collection. |
|
40 | * |
|
41 | * @return RouteCollection |
|
42 | */ |
|
43 | public function addRoutes() |
|
44 | { |
|
45 | $collection = $this->collection; |
|
46 | ||
47 | foreach ($this->plugins as $key => $value) { |
|
48 | $file = $this->path.'/'.$value->getName().'/routing.php'; |
|
49 | ||
50 | if (is_file($file)) { |
|
51 | include $file; |
|
52 | } |
|
53 | } |
|
54 | ||
55 | return $collection; |
|
56 | } |
|
57 | } |
|
58 |