You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/app/core/extension/extension.component.html
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ <h1>Extension Methods</h1>
12
12
</p>
13
13
<h3>Extended class</h3>
14
14
<p>
15
-
The extended class is the class that the extension method operates on, and must include the trait <code>DevNet\System\Tweak</code> to enable this feature like in the following eample:
15
+
The extended class is the class that the extension method operates on, and must include the trait <code>DevNet\System\Tweak</code> to enable this feature like in the following code example:
16
16
</p>
17
17
<pre><codeclass="language-php"><?php
18
18
@@ -84,7 +84,7 @@ <h3>Calling the extension method</h3>
// await next action delegate to chain the pipline to the next filter befor executing the action.
41
-
await($next($context));
42
-
// logging or other works can be done here after executing the action.
43
-
}
44
-
}
45
-
</code></pre>
46
-
<br>
47
-
<h3>Apply Filters</h3>
48
-
<p>
49
-
Any action filter that implements the interface <code>DevNet\Web\Action\IActionFilter</code> can be applied to the route endpoint handler or to the controller, but to apply an action filter to a controller, the action filter class must be declared as an attribute because the controller accepts only action filters as attributes, and if the action filter attribute is applied to the class of controller it will be applied to all the action methods of the controller, and if it is applied only to a specific action method of a controller it will be applied only to that specific action method.
50
-
</p>
51
-
<p>
52
-
The following code represents an example of applying action filters to a controller as attributes.
53
-
</p>
54
-
<pre><codeclass="language-php"><?php
55
-
56
-
namespace Application\Controllers;
57
-
58
-
use DevNet\Web\Action\ActionController;
59
-
use DevNet\Web\Action\IActionResult;
60
-
use DevNet\Web\Action\Filters\HttpMethod;
61
-
use DevNet\Web\Action\Filters\Antiforgery;
62
-
use Application\Filters\AuthenticationFilter;
63
-
use Application\Models\Profile;
64
-
65
-
// this filter will be applied to all controller's methods.
66
-
#[AuthenticationFilter]
67
-
class UserController extends ActionController
68
-
{
69
-
public function index(): IActionResult
70
-
{
71
-
return $this->view();
72
-
}
73
-
74
-
// this filters will be applied only to this action method.
75
-
#[Antiforgery]
76
-
#[HttpMethod('post')]
77
-
public function edit(Profile $form): IActionResult
33
+
public function async_invoke(ActionContext $context, ActionDelegate $next): void
78
34
{
79
-
// code...
35
+
// short-circuiting the pipeline if does not fulfil the condition.
// await next action delegate to chain the pipline to the next filter befor executing the action.
41
+
await($next($context));
42
+
// logging or other works can be done here after executing the action.
80
43
}
81
44
}
82
45
</code></pre>
83
46
<br>
47
+
<h3>Registering action filters</h3>
84
48
<p>
85
-
The next code example shows how to add action filters to the route endpoint handler, as class or as an anonymous async function, with the help of the method <code>RouteHandler::addFilter(callable|string $filter, ...$args)</code>
49
+
The code example below shows how to add action filters to the route endpoint handler as class or as an anonymous async function, with the help of the method <code>RouteHandler::addFilter(callable|string $filter, ...$args)</code>
86
50
</p>
87
51
<pre><codeclass="language-php"><?php
88
52
@@ -116,6 +80,38 @@ <h3>Apply Filters</h3>
116
80
// other routes.
117
81
});
118
82
});</code></pre>
83
+
<p>
84
+
You can apply the action filter to a controller using the attribute syntax and decorate the controller class or the action method with the filter name, as shown in the following code example.
85
+
</p>
86
+
<pre><codeclass="language-php"><?php
87
+
88
+
namespace Application\Controllers;
89
+
90
+
use DevNet\Web\Action\ActionController;
91
+
use DevNet\Web\Action\IActionResult;
92
+
use DevNet\Web\Action\Filters\HttpMethod;
93
+
use DevNet\Web\Action\Filters\Antiforgery;
94
+
use Application\Filters\AuthenticationFilter;
95
+
use Application\Models\Profile;
96
+
97
+
// this filter will be applied to all controller's methods.
98
+
#[AuthenticationFilter]
99
+
class UserController extends ActionController
100
+
{
101
+
public function index(): IActionResult
102
+
{
103
+
return $this->view();
104
+
}
105
+
106
+
// this filters will be applied only to this action method.
107
+
#[Antiforgery]
108
+
#[HttpMethod('post')]
109
+
public function edit(Profile $form): IActionResult
Copy file name to clipboardExpand all lines: src/app/web/middleware/middleware.component.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ <h1>Middleware</h1>
49
49
}
50
50
}</code></pre>
51
51
<br>
52
-
<h3>Registring Middlewares</h3>
52
+
<h3>Registering Middlewares</h3>
53
53
<p>
54
54
Inside the method <code>WebHost::start(Closure $configure)</code>, middlewares can be registered to the pipeline as a class that implements the interface <code>DevNet\Web\Middleware\IMiddleware</code> or as an in-line middleware defined by an anonymous async function, with the help of the following methods:
0 commit comments