-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiddlewareDeclaration.php
More file actions
98 lines (85 loc) · 2.14 KB
/
MiddlewareDeclaration.php
File metadata and controls
98 lines (85 loc) · 2.14 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Laragear\Meta\Http\Middleware;
use Illuminate\Contracts\Http\Kernel as KernelContract;
use Illuminate\Routing\Router;
/**
* @template TValue
*/
class MiddlewareDeclaration
{
/**
* Create a new Middleware declaration instance.
*
* @param \Illuminate\Routing\Router $router
* @param \Illuminate\Foundation\Http\Kernel $kernel
* @param class-string|string $middleware
*/
public function __construct(
protected Router $router,
protected KernelContract $kernel,
protected string $middleware
) {
//
}
/**
* Aliases the middleware with a friendly name.
*
* @param string $alias
* @return $this
*/
public function as(string $alias): static
{
$this->router->aliasMiddleware($alias, $this->middleware);
return $this;
}
/**
* Registers the middleware in a middleware group.
*
* @param string $group
* @return $this
*/
public function inGroup(string $group): static
{
$this->kernel->appendMiddlewareToGroup($group, $this->middleware);
return $this;
}
/**
* Runs the middleware globally on all routes.
*
* @return $this
*/
public function globally(): static
{
$this->kernel->pushMiddleware($this->middleware);
return $this;
}
/**
* Sets the global middleware priority as first.
*
* @return void
*/
public function first(): void
{
$this->kernel->prependToMiddlewarePriority($this->middleware);
}
/**
* Sets the global middleware priority as last.
*
* @return void
*/
public function last(): void
{
$this->kernel->appendToMiddlewarePriority($this->middleware);
}
/**
* Makes the middleware a shared instance.
*
* @param (callable(\Illuminate\Contracts\Foundation\Application):TValue)|null $callback
* @return $this
*/
public function shared(?callable $callback = null): static
{
$this->kernel->getApplication()->singleton($this->middleware, $callback);
return $this;
}
}