Skip to content

Commit 95df0f8

Browse files
author
Andrey Helldar
committed
Removed inheritance from pretty-routes
1 parent efac83b commit 95df0f8

File tree

2 files changed

+76
-7
lines changed

2 files changed

+76
-7
lines changed

src/Models/Route.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,48 @@ final class Route implements Arrayable
1616

1717
protected $priority;
1818

19+
protected $hide_methods = [];
20+
21+
protected $domain_force = false;
22+
23+
protected $url;
24+
25+
protected $namespace;
26+
1927
public function __construct(IlluminateRoute $route, int $priority)
2028
{
2129
$this->route = $route;
2230
$this->priority = ++$priority;
2331
}
2432

33+
public function setHideMethods(array $hide_methods)
34+
{
35+
$this->hide_methods = $hide_methods;
36+
37+
return $this;
38+
}
39+
40+
public function setDomainForce(bool $domain_force)
41+
{
42+
$this->domain_force = $domain_force;
43+
44+
return $this;
45+
}
46+
47+
public function setUrl($url)
48+
{
49+
$this->url = $url;
50+
51+
return $this;
52+
}
53+
54+
public function setNamespace($namespace)
55+
{
56+
$this->namespace = $namespace;
57+
58+
return $this;
59+
}
60+
2561
public function getPriority(): int
2662
{
2763
return $this->priority;
@@ -31,7 +67,7 @@ public function getMethods(): array
3167
{
3268
return array_values(array_diff(
3369
$this->route->methods(),
34-
config('pretty-routes.hide_methods', [])
70+
$this->hide_methods
3571
));
3672
}
3773

@@ -41,8 +77,8 @@ public function getDomain(): ?string
4177
return $domain;
4278
}
4379

44-
return config('pretty-routes.domain_force')
45-
? Http::domain(config('app.url'))
80+
return $this->domain_force
81+
? Http::domain($this->url)
4682
: null;
4783
}
4884

@@ -58,7 +94,7 @@ public function getName(): ?string
5894

5995
public function getModule(): ?string
6096
{
61-
$namespace = config('modules.namespace');
97+
$namespace = $this->namespace;
6298

6399
if ($namespace && Str::startsWith($this->getAction(), $namespace)) {
64100
$action = Str::after($this->getAction(), $namespace);

src/Support/Routes.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,68 @@ final class Routes
1313

1414
protected $hide_matching = [];
1515

16+
protected $domain_force = false;
17+
18+
protected $url = null;
19+
20+
protected $namespace = null;
21+
1622
public function collection(): Collection
1723
{
1824
return $this->getRoutes()
1925
->filter(function (Route $route) {
2026
return $this->allowUri($route->uri()) && $this->allowMethods($route->methods());
2127
})
2228
->values()
23-
->mapInto(RouteModel::class);
29+
->map(function (Route $route, int $index) {
30+
return (new RouteModel($route, $index))
31+
->setDomainForce($this->domain_force)
32+
->setHideMethods($this->hide_methods)
33+
->setUrl($this->url)
34+
->setNamespace($this->namespace);
35+
});
2436
}
2537

2638
public function get(): array
2739
{
2840
return $this->collection()->toArray();
2941
}
3042

31-
public function hideMethods(array $methods): self
43+
public function setHideMethods(array $methods): self
3244
{
3345
$this->hide_methods = $methods;
3446

3547
return $this;
3648
}
3749

38-
public function hideMatching(array $matching): self
50+
public function setHideMatching(array $matching): self
3951
{
4052
$this->hide_matching = $matching;
4153

4254
return $this;
4355
}
4456

57+
public function setDomainForce(bool $force = false): self
58+
{
59+
$this->domain_force = $force;
60+
61+
return $this;
62+
}
63+
64+
public function setUrl(string $url): self
65+
{
66+
$this->url = $url;
67+
68+
return $this;
69+
}
70+
71+
public function setNamespace(string $namespace = null): self
72+
{
73+
$this->namespace = $namespace;
74+
75+
return $this;
76+
}
77+
4578
protected function getRoutes(): Collection
4679
{
4780
return collect(RouteFacade::getRoutes());

0 commit comments

Comments
 (0)