Skip to content

Commit 6614c05

Browse files
committed
fixing issues from review
1 parent 6c20855 commit 6614c05

10 files changed

Lines changed: 86 additions & 26 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ It provides base classes for action based controllers similar to Laminas control
1919
## Installation
2020

2121
Install `dot-controller` by executing the following Composer command:
22+
2223
```bash
2324
$ composer require dotkernel/dot-controller
2425
```
2526

2627
## Usage
2728

2829
Middleware controllers act as a handler for multiple routes. Some conventions were made:
30+
2931
- register controllers in the routes array just like any mezzio middleware. The requirement is that you should define an `action` route parameter(possibly optional) anywhere inside the route(e.g `/user[/{action}]`)
3032
- action parameter value is converted to a method name inside the controller. Underscore, dot and line characters are removed and the action name is converted to camel-case suffixed by the string `Action`. For example a route and action pair like `/user/forgot-password` will be converted to method `forgotPasswordAction`.
3133
- the default action value, if not present in the URI is `index`, so you should always define an `indexAction` within your controllers for displaying a default page or redirecting.
3234

3335
In order to create your action based controllers, you must extend the abstract class `DotKernel\DotController\AbstractActionController`
3436

35-
##### Example
37+
### Example
3638
Creating a UserController with default action and a register action. Will handle routes `/user` and `/user/register`
3739

38-
##### UserController.php
3940
```php
40-
4141
use DotKernel\DotController\AbstractActionController;
4242

4343
class UserController extends AbstractActionController
@@ -69,6 +69,7 @@ $app->route(
6969
### Multiple controllers for the same route
7070

7171
Use case: You have defined a controller inside some package, with default actions. You want to add actions that fall into the same controller name(or route name more exactly). You want to do this without extending the controller provided by the package. In this case you can do the following
72+
7273
- create your own controller, independent of the package's controller which adds more actions
7374
- Mezzio lets you define an array of middleware for a route, so you can register this controller before the package's controller
7475

SECURITY.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
6+
| Version | Supported | PHP Version |
7+
|---------|--------------------|----------------------------------------------------------------------------------------------------------------|
8+
| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.4.3) |
9+
| <= 2.x | :x: | |
10+
11+
12+
## Reporting Potential Security Issues
13+
14+
If you have encountered a potential security vulnerability in this project,
15+
please report it to us at <security@dotkernel.com>. We will work with you to
16+
verify the vulnerability and patch it.
17+
18+
When reporting issues, please provide the following information:
19+
20+
- Component(s) affected
21+
- A description indicating how to reproduce the issue
22+
- A summary of the security vulnerability and impact
23+
24+
We request that you contact us via the email address above and give the
25+
project contributors a chance to resolve the vulnerability and issue a new
26+
release prior to any public exposure; this helps protect the project's
27+
users, and provides them with a chance to upgrade and/or update in order to
28+
protect their applications.
29+
30+
31+
## Policy
32+
33+
If we verify a reported security vulnerability, our policy is:
34+
35+
- We will patch the current release branch, as well as the immediate prior minor
36+
release branch.
37+
38+
- After patching the release branches, we will immediately issue new security
39+
fix releases for each patched release branch.

docs/book/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../README.md
1+
../../README.md

docs/book/v3/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
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`):
44

5-
\Dot\Controller\ConfigProvider::class
5+
\Dot\Controller\ConfigProvider::class
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# Events
2+
23
DotKernel's controller package supports events and those events can be of 2 types: global events (middleware-like) or manually dispatch events.
34

4-
# Getting started
5-
- Every event listener that is triggered from a controller
6-
needs to implement `Dot\Controller\Event\ControllerEventListenerInterface` which actually extends `Laminas\EventManager\ListenerAggregateInterface`.
5+
## Getting started
6+
7+
- Every event listener that is triggered from a controller
8+
needs to implement `Dot\Controller\Event\ControllerEventListenerInterface` which actually extends `Laminas\EventManager\ListenerAggregateInterface`.
79
- You can add the trait `Dot\Controller\Event\ControllerEventListenerTrait` to override the method of the interface.
810
- 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
911

1012

11-
# Usage
13+
## Usage
14+
1215
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
1316
or a manually dispatchable way, where you can define to which controller the events is attached, and you can trigger the event where you want.
1417

1518
For our example we have a UserController with some methods in it
19+
1620
```php
1721
use DotKernel\DotController\AbstractActionController;
1822

@@ -34,10 +38,10 @@ class UserController extends AbstractActionController
3438

3539
}
3640
}
37-
3841
```
3942

4043
### Example 1 - Global way
44+
4145
First we will create the event listener
4246
```php
4347
use Dot\Controller\Event\ControllerEvent;
@@ -64,6 +68,7 @@ class UserUpdatedListener implements ControllerEventListenerInterface
6468
```
6569

6670
We register the event listener in the configuration key
71+
6772
```php
6873
'dot_controller' => [
6974
'event_listeners' => [
@@ -82,6 +87,7 @@ With this it doesn't matter what action is accessed, the event it will run befor
8287
In addition, you can make use of the `event` variable to access information about the event.
8388

8489
For example:
90+
8591
```php
8692
// UserUpdatedListener
8793
public function onAfterDispatch(ControllerEvent $e): void
@@ -94,10 +100,12 @@ public function onAfterDispatch(ControllerEvent $e): void
94100
}
95101
}
96102
```
103+
97104
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>
98105
We can use the `onBeforeDispatch` in the same way, to log right before the user is updated.
99106

100107
### Example 2 - Manually triggered way
108+
101109
```php
102110
use Dot\Controller\Event\ControllerEvent;
103111
use Dot\Controller\Event\ControllerEventListenerInterface;
@@ -131,6 +139,7 @@ with `onBeforeDispatch` and `onAfterDispatch` methods, but we can make our custo
131139
In this case we create attach an event called `user.profile.update` and bind it to the `userProfileUpdated` method.
132140

133141
Next we need to register the event
142+
134143
```php
135144
'dot_controller' => [
136145
'event_listeners' => [
@@ -142,6 +151,7 @@ Next we need to register the event
142151
```
143152

144153
Now you can manually trigger the event from the controller using build in `dispatchEvent` method.
154+
145155
```php
146156
// UserController
147157
// post method for updating the user
@@ -152,12 +162,13 @@ public function updateAction()
152162

153163
}
154164
```
165+
155166
As you can see we attach the `user` key to the parameters, so we can actually access it.
167+
156168
```php
157169
public function userProfileUpdated(ControllerEvent $event): void
158170
{
159171
$user = $event->getParams()['user'];
160172
$this->logger->info('User profile updated', $user->toArray());
161173
}
162174
```
163-

docs/book/v3/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
Install `dot-controller` by executing the following Composer command:
44

5-
composer require dotkernel/dot-controller
5+
composer require dotkernel/dot-controller

docs/book/v3/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Overview
22

33
`dot-controller` is DotKernel's controller package that can be use like middleware inside DotKernel or Mezzio application.
4-
It provides base classes for action based controllers similar to Laminas controller component. It is more lightweight though, but supports controller plugins and event listeners
4+
It provides base classes for action based controllers similar to Laminas controller component. It is more lightweight though, but supports controller plugins and event listeners
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Controller plugins offer the advantage of globally accessible functionality in a
1313
### Example
1414

1515
First we create our desired plugin, for our example a string helper
16+
1617
```php
1718
class StringPlugin implements PluginInterface
1819
{
@@ -26,6 +27,7 @@ class StringPlugin implements PluginInterface
2627
```
2728

2829
We create a factory for the plugin
30+
2931
```php
3032
use Psr\Container\ContainerInterface;
3133

@@ -41,6 +43,7 @@ class StringPluginFactory
4143
```
4244

4345
Register the factory under the `['dot_controller']['plugin_manager']['factories']` key.
46+
4447
```php
4548
'dot_controller' => [
4649
'plugin_manager' => [
@@ -50,21 +53,25 @@ Register the factory under the `['dot_controller']['plugin_manager']['factories'
5053
]
5154
]
5255
```
56+
5357
You don't need to register the plugin factory to a regular dependencies in a configuration because `AbstractPluginManager` actually extends `ServiceManager`
5458

5559
Access it in a controller.
60+
5661
```php
5762
//inside a controller
5863
$this->string(); // will return the StringPlugin class, so you can call any public method from it
5964
$this->string()->toUpper("test") // will return TEST
6065
```
6166

6267
## Build-in plugins
68+
6369
The package comes in with 2 default plugins ``template`` and `url`. You can use
6470
them in the same way as our example above.
6571

6672
- Url plugin
6773
- - the plugin is an instance of `Mezzio\Helper\UrlHelper`
74+
6875
```php
6976
//in a controller action
7077
/** @var UrlHelper $url */
@@ -74,6 +81,7 @@ them in the same way as our example above.
7481

7582
- Template plugin
7683
- - the plugin is an instance of `Mezzio\Template\TemplateRendererInterface`
84+
7785
```php
7886
// in a controller action
7987
return new HtmlResponse(

docs/book/v3/usage.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# Usage
22

33
Middleware controllers act as a handler for multiple routes. Some conventions were made:
4+
45
- register controllers in the routes array just like any mezzio middleware. The requirement is that you should define an `action` route parameter(possibly optional) anywhere inside the route(e.g `/user[/{action}]`)
56
- action parameter value is converted to a method name inside the controller. Underscore, dot and line characters are removed and the action name is converted to camel-case suffixed by the string `Action`. For example a route and action pair like `/user/forgot-password` will be converted to method `forgotPasswordAction`.
67
- the default action value, if not present in the URI is `index`, so you should always define an `indexAction` within your controllers for displaying a default page or redirecting.
78

89
In order to create your action based controllers, you must extend the abstract class `DotKernel\DotController\AbstractActionController`
910

10-
##### Example
11+
## Example
1112
Creating a UserController with default action and a register action. Will handle routes `/user` and `/user/register`
1213

13-
##### UserController.php
1414
```php
15-
1615
use DotKernel\DotController\AbstractActionController;
1716

1817
class UserController extends AbstractActionController
@@ -44,15 +43,17 @@ $app->route(
4443
### Multiple controllers for the same route
4544

4645
Use case: You have defined a controller inside some package, with default actions. You want to add actions that fall into the same controller name(or route name more exactly). You want to do this without extending the controller provided by the package. In this case you can do the following
46+
4747
- create your own controller, independent of the package's controller which adds more actions
4848
- Mezzio lets you define an array of middleware for a route, so you can register this controller before the package's controller
4949

5050
Now when a request for this route comes in, your controller will run first. DotKernel controllers are designed to ignore requests that cannot be matched to one of its methods, so if no action matches, it will call the next middleware, in our case, the second controller.
5151
If this is the last controller, and action does not match here, it will go to the default 404 Not found page(handled by NotFoundDelegate)
5252

53-
# Plugins
54-
- [Plugins](plugins/plugins.md)
53+
## Plugins
54+
55+
- [Plugins](plugins.md)
5556

56-
# Events
57+
## Events
5758

58-
- [Events](events/events.md)
59+
- [Events](events.md)

mkdocs.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ extra:
88
nav:
99
- Home: index.md
1010
- v3:
11-
- Overview: v5/overview.md
12-
- Installation: v5/installation.md
13-
- Configuration: v5/configuration.md
14-
- Usage: v5/usage.md
15-
- Plugins: v5/plugins/plugins.md
16-
- Events: v5/events/events.md
11+
- Overview: v3/overview.md
12+
- Installation: v3/installation.md
13+
- Configuration: v3/configuration.md
14+
- Usage: v3/usage.md
15+
- Plugins: v3/plugins.md
16+
- Events: v3/events.md
1717
site_name: dot-controller
1818
site_description: "DotKernel's controller package"
1919
repo_url: "https://github.com/dotkernel/dot-controller"

0 commit comments

Comments
 (0)