| 1 | <?php declare(strict_types = 1); |
||
| 12 | class RouteGroup extends RouteCollection implements RouteGroupContract |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $host = ''; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $prefix = '/'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $scheme = ''; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param callable $callback |
||
| 32 | * @return RouteGroupContract |
||
| 33 | */ |
||
| 34 | 1 | public static function collect(callable $callback): RouteGroupContract |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @inheritDoc |
||
| 44 | */ |
||
| 45 | 4 | public function all(): array |
|
| 46 | { |
||
| 47 | 4 | $routes = []; |
|
| 48 | /** @var Route $route */ |
||
| 49 | 4 | foreach (parent::all() as $route) { |
|
| 50 | 4 | if (!$route->host() && $this->host) { |
|
| 51 | 1 | $route = $route->withHost($this->host); |
|
| 52 | } |
||
| 53 | 4 | if (!$route->scheme() && $this->scheme) { |
|
| 54 | 1 | $route = $route->secure(); |
|
| 55 | } |
||
| 56 | 4 | $routes[] = $route->withPath($this->addPathPrefix($route->path())); |
|
| 57 | } |
||
| 58 | |||
| 59 | 4 | return $routes; |
|
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @inheritDoc |
||
| 64 | */ |
||
| 65 | 1 | public function setHost(string $host): RouteGroupContract |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @inheritDoc |
||
| 74 | */ |
||
| 75 | 1 | public function setPrefix(string $prefix): RouteGroupContract |
|
| 81 | |||
| 82 | /** |
||
| 83 | * @inheritDoc |
||
| 84 | */ |
||
| 85 | 1 | public function setScheme(string $scheme): RouteGroupContract |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Prepends group prefix to provided route $path. |
||
| 94 | * |
||
| 95 | * @param string $path |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | 4 | private function addPathPrefix(string $path): string |
|
| 104 | |||
| 105 | } |