-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoute.php
85 lines (83 loc) · 1.98 KB
/
Route.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
class Route extends Prefab
{
protected $f3;
public function __construct()
{
$this->f3 = f3();
}
public function uri()
{
return $this->f3['URI'];
}
public function type()
{
return $this->f3['VERB'];
}
public function has($route)
{
if (Str::contains($route, '/')) {
return array_key_exists($route, $this->getRoutes());
}
return $this->hasNamedRoute($route);
}
public function current()
{
return $this->f3['PATH'];
}
public function is($route)
{
return Str::contains($this->current(), $route);
}
public function currentRouteName()
{
return $this->getRoutes()[$this->current()][0][$this->type()][3];
}
public function getRouteName($route)
{
$response = null;
foreach ($this->getNamedRoutes() as $name => $url) {
if ($url == $route) {
$response[] = $name;
}
}
return $response;
//return array_search($this->getNamedRoutes(), $route);
}
public function hasNamedRoute($route)
{
return array_key_exists($route, $this->getNamedRoutes());
}
public function getNamedRoutes()
{
return $this->f3['ALIASES'];
}
public function getRoutes()
{
return $this->f3['ROUTES'];
}
public function getUrl($alias)
{
return $this->has($alias) ? $this->getNamedRoutes()[$alias] : null;
}
public function hasParameter($parameter)
{
return (bool) $this->parameter($parameter);
}
public function parameters()
{
return $this->f3[$this->type()];
}
public function parameter($parameter)
{
return $this->f3[$this->type().'.'.$parameter];
}
public function isApi($url = null)
{
$path = $url?:$this->current();
if (is_string($path)) {
return explode('/', $path)[1] === 'api';
}
return false;
}
}