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
After installation, the package can be used immediately but if you want to use all features of the package, like plugins and events you need to register the `ConfigProvider` in your project by adding the below line to your configuration aggregator (usually: `config/config.php`):
Copy file name to clipboardExpand all lines: docs/book/v3/events.md
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,11 @@ DotKernel's controller package supports events and those events can be of 2 type
4
4
5
5
## Getting started
6
6
7
-
- Every event listener that is triggered from a controller
7
+
- Every event listener that is triggered from a controller
8
8
needs to implement `Dot\Controller\Event\ControllerEventListenerInterface` which actually extends `Laminas\EventManager\ListenerAggregateInterface`.
9
9
- You can add the trait `Dot\Controller\Event\ControllerEventListenerTrait` to override the method of the interface.
10
10
- Every event listener needs to be registered under the `['dot_controller']['event_listenenrs]` key in the ConfigProvider, and every key must be the class that you want to attach the events
11
11
12
-
13
12
## Usage
14
13
15
14
The events in a controller can be done in 2 different ways, a global way where an event is attached automatically to all the controllers action and works in the same way the middlewares works
@@ -43,6 +42,7 @@ class UserController extends AbstractActionController
43
42
### Example 1 - Global way
44
43
45
44
First we will create the event listener
45
+
46
46
```php
47
47
use Dot\Controller\Event\ControllerEvent;
48
48
use Dot\Controller\Event\ControllerEventListenerInterface;
@@ -84,9 +84,9 @@ after the controller is dispatched.
84
84
85
85
With this it doesn't matter what action is accessed, the event it will run before and after the action.
86
86
87
-
In addition, you can make use of the `event` variable to access information about the event.
87
+
In addition, you can make use of the `event` variable to access information about the event.
88
88
89
-
For example:
89
+
For example:
90
90
91
91
```php
92
92
// UserUpdatedListener
@@ -101,8 +101,10 @@ public function onAfterDispatch(ControllerEvent $e): void
101
101
}
102
102
```
103
103
104
-
So every time the `updateAction` is accessed and the method is post, right after the action is dispatched, we can log that the user was updated. <br>
105
-
We can use the `onBeforeDispatch` in the same way, to log right before the user is updated.
104
+
So every time the `updateAction` is accessed and the method is post,
105
+
right after the action is dispatched, we can log that the user was updated.
106
+
107
+
We can use the `onBeforeDispatch` in the same way, to log right before the user is updated.
106
108
107
109
### Example 2 - Manually triggered way
108
110
@@ -134,8 +136,10 @@ class UserUpdatedListener implements ControllerEventListenerInterface
134
136
}
135
137
```
136
138
137
-
The `attach` method is from the `ListenerAggregateInterface` which `ControllerEventListenerTrait` already is overriding it so can be used in a global way
138
-
with `onBeforeDispatch` and `onAfterDispatch` methods, but we can make our custom event and bind it to our method. <br>
139
+
The `attach` method is from the `ListenerAggregateInterface` which `ControllerEventListenerTrait`
140
+
already is overriding it so can be used in a global way with `onBeforeDispatch` and `onAfterDispatch`
141
+
methods, but we can make our custom event and bind it to our method.
142
+
139
143
In this case we create attach an event called `user.profile.update` and bind it to the `userProfileUpdated` method.
Copy file name to clipboardExpand all lines: docs/book/v3/plugins.md
+17-11Lines changed: 17 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,22 @@ DotKernel's controller support plugins, much like controllers in a Laminas Appli
4
4
The package comes packed with a few built in plugins, but you can extend controller functionality with your own plugins.
5
5
6
6
## Usage
7
-
Any controller plugins must implement `Dot\Controller\Plugin\PluginInterface`.
8
-
You need to create a factory in addition to the plugin and register it under the `['dot_controller']['plugin_manager']['factories']` with the plugin name. <br>
9
7
10
-
Once registered, a plugin can be directly accessed in any controller, by calling a method with the plugin's name(the service name or the key at which the plugin is registered inside the manager) <br>
11
-
Controller plugins offer the advantage of globally accessible functionality in any controller without to manually inject dependencies. Plugins should be used for functions that are common to any controller. Do not clutter controller's code with unnecessary plugins.
8
+
Any controller plugins must implement `Dot\Controller\Plugin\PluginInterface`.
9
+
You need to create a factory in addition to the plugin and register it
10
+
under the `['dot_controller']['plugin_manager']['factories']` with the plugin name.
11
+
12
+
Once registered, a plugin can be directly accessed in any controller,
13
+
by calling a method with the plugin's name (the service name or the key at which the plugin is registered inside the manager)
14
+
15
+
Controller plugins offer the advantage of globally accessible functionality
16
+
in any controller without to manually inject dependencies.
17
+
Plugins should be used for functions that are common to any controller.
18
+
Do not clutter controller's code with unnecessary plugins.
12
19
13
20
### Example
14
21
15
-
First we create our desired plugin, for our example a string helper
22
+
First we create our desired plugin, for our example a string helper
16
23
17
24
```php
18
25
class StringPlugin implements PluginInterface
@@ -54,7 +61,8 @@ Register the factory under the `['dot_controller']['plugin_manager']['factories'
54
61
]
55
62
```
56
63
57
-
You don't need to register the plugin factory to a regular dependencies in a configuration because `AbstractPluginManager` actually extends `ServiceManager`
64
+
You don't need to register the plugin factory to a regular dependencies in a configuration
65
+
because `AbstractPluginManager` actually extends `ServiceManager`
58
66
59
67
Access it in a controller.
60
68
@@ -66,11 +74,10 @@ $this->string()->toUpper("test") // will return TEST
66
74
67
75
## Build-in plugins
68
76
69
-
The package comes in with 2 default plugins ``template`` and `url`. You can use
77
+
The package comes in with 2 default plugins ``template`` and `url`. You can use
70
78
them in the same way as our example above.
71
79
72
-
- Url plugin
73
-
-- the plugin is an instance of `Mezzio\Helper\UrlHelper`
80
+
-`url` - the plugin is an instance of `Mezzio\Helper\UrlHelper`
74
81
75
82
```php
76
83
//in a controller action
@@ -79,8 +86,7 @@ them in the same way as our example above.
0 commit comments