|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Limoncello\Core\Routing; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2015-2020 [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use Limoncello\Contracts\Routing\GroupInterface; |
|
22
|
|
|
use function assert; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @package Limoncello\Core |
|
26
|
|
|
*/ |
|
27
|
|
|
class Group extends BaseGroup |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @param array $parameters |
|
31
|
|
|
*/ |
|
32
|
25 |
|
public function __construct(array $parameters = []) |
|
33
|
|
|
{ |
|
34
|
|
|
list($middleware, $configurators, $factoryWasGiven, $requestFactory, $name) = |
|
35
|
25 |
|
$this->normalizeGroupParameters($parameters); |
|
36
|
|
|
|
|
37
|
25 |
|
if (empty($middleware) === false) { |
|
38
|
1 |
|
$this->setMiddleware($middleware); |
|
39
|
|
|
} |
|
40
|
25 |
|
if (empty($configurators) === false) { |
|
41
|
2 |
|
$this->setConfigurators($configurators); |
|
42
|
|
|
} |
|
43
|
25 |
|
if (empty($name) === false) { |
|
44
|
1 |
|
$this->setName($name); |
|
45
|
|
|
} |
|
46
|
25 |
|
if ($factoryWasGiven === true) { |
|
47
|
9 |
|
$this->setRequestFactory($requestFactory); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritdoc |
|
53
|
|
|
*/ |
|
54
|
18 |
|
public function parentGroup(): ?GroupInterface |
|
55
|
|
|
{ |
|
56
|
18 |
|
$group = parent::parentGroup(); |
|
57
|
|
|
|
|
58
|
|
|
// for groups with a parent use NestedGroup |
|
59
|
18 |
|
assert($group === null); |
|
60
|
|
|
|
|
61
|
18 |
|
return $group; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return BaseGroup |
|
66
|
|
|
*/ |
|
67
|
17 |
|
protected function createGroup(): BaseGroup |
|
68
|
|
|
{ |
|
69
|
17 |
|
$group = (new NestedGroup($this))->setHasTrailSlash($this->hasTrailSlash()); |
|
70
|
|
|
|
|
71
|
17 |
|
return $group; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|