Skip to content

Commit 6333a1f

Browse files
authored
Merge pull request #39 from dotkernel/issue-38
Issue 38
2 parents f098d9c + a50b7f5 commit 6333a1f

File tree

16 files changed

+459
-177
lines changed

16 files changed

+459
-177
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
tags:
8+
9+
jobs:
10+
ci:
11+
uses: laminas/workflow-continuous-integration/.github/workflows/[email protected]

.github/workflows/cs-tests.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/docs-build.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: docs-build
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Build Docs
13+
uses: dotkernel/documentation-theme/github-actions/docs@main
14+
env:
15+
DEPLOY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/static-analysis.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/unit-test.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

README.md

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# dot-controller
22

3-
This package contains controller like middleware to be used inside a DotKernel or Mezzio application. It provides base classes for action based controllers similar to Laminas controller component. It is more lightweight though, but supports controller plugins.
3+
This 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
45

56
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-controller)
67
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.4.3)
@@ -17,27 +18,27 @@ This package contains controller like middleware to be used inside a DotKernel o
1718

1819
## Installation
1920

20-
Run the following composer command in your project directory
21+
Install `dot-controller` by executing the following Composer command:
22+
2123
```bash
2224
$ composer require dotkernel/dot-controller
2325
```
24-
Merge the `ConfigProvider` to your configuration aggregate.
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 1
37+
### Example
38+
3639
Creating a UserController with default action and a register action. Will handle routes `/user` and `/user/register`
3740

38-
##### UserController.php
3941
```php
40-
4142
use DotKernel\DotController\AbstractActionController;
4243

4344
class UserController extends AbstractActionController
@@ -56,38 +57,22 @@ class UserController extends AbstractActionController
5657

5758
Then register this controller as a routed middleware in file `RoutesDelegator.php` just like a regular middleware.
5859

60+
```php
61+
//Example from a DotKernel RoutesDelegator
62+
$app->route(
63+
'/user[/{action}]',
64+
UserController::class,
65+
[RequestMethodInterface::METHOD_GET, RequestMethodInterface::METHOD_POST],
66+
'user'
67+
);
68+
```
69+
5970
### Multiple controllers for the same route
6071

6172
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
73+
6274
- create your own controller, independent of the package's controller which adds more actions
6375
- Mezzio lets you define an array of middleware for a route, so you can register this controller before the package's controller
6476

65-
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.
77+
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.
6678
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)
67-
68-
## Controller plugins
69-
70-
Controllers support controller plugins, much like controllers in a Laminas application. The module comes packed with a few common plugins, but you can extend controller functionality with your own plugins too.
71-
72-
### Usage
73-
74-
Controller plugins must implement `Dot\Controller\Plugin\PluginInterface`. You can add them to the config file, at key `['dk_controller']['plugin_manager']`. The design pattern uses the `AbstractPluginManager` provided by Laminas service manager component. So, registration of a plugin under the aforementioned config key looks the same as the declaration of regular dependencies, as `AbstractPluginManager` actually extends `ServiceManager`.
75-
76-
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)
77-
78-
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.
79-
80-
##### Example
81-
```php
82-
//inside a controller
83-
//assume we've already registered a plugin called testPlugin
84-
$this->testPlugin(); //will return the TestPlugin class so you can call any public defined method on it
85-
$this->testPlugin()->someMethod();
86-
```
87-
88-
### Built-in plugins
89-
Note: Each of these plugins requires the associated Mezzio packages to be installed and available in your project.
90-
Although these are optional, if a package is missing, the controller will not have the associated functionality available
91-
92-
- `template` wraps TemplateInterface provided by Mezzio, to make template engine accessible to any controller
93-
- `url` wraps the UrlHelper class provided by Laminas helpers package. Used to generate URIs from routes

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 <[email protected]>. 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.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"config": {
5656
"sort-packages": true,
5757
"allow-plugins": {
58-
"dealerdirect/phpcodesniffer-composer-installer": true
58+
"dealerdirect/phpcodesniffer-composer-installer": true,
59+
"laminas/laminas-dependency-plugin": false
5960
}
6061
}
6162
}

docs/book/index.md

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

docs/book/v3/configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Configuration
2+
3+
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`):
4+
5+
\Dot\Controller\ConfigProvider::class

0 commit comments

Comments
 (0)