Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ jobs:
- ubuntu-latest

php:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: Checkout
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/docs-build.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
- push

name: Run PHPStan checks

jobs:
mutation:
name: PHPStan ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-

- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis with PHPStan
run: vendor/bin/phpstan analyse
48 changes: 30 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# dot-controller

This is DotKernel's controller package that can be use like middleware inside 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 and event listeners
This is Dotkernel's controller package that can be used like middleware inside Dotkernel or Mezzio application.
It provides base classes for action-based controllers similar to a Laminas controller component.
It is more lightweight, though, but supports controller plugins and event listeners.

## Documentation

Documentation is available at: https://docs.dotkernel.org/dot-controller/v3/overview/.

## Badges

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-controller)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.4.3)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.6.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-controller)](https://github.com/dotkernel/dot-controller/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-controller)](https://github.com/dotkernel/dot-controller/network)
Expand All @@ -13,33 +20,35 @@ It provides base classes for action based controllers similar to Laminas control

[![Build Static](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-controller/graph/badge.svg?token=VUBG5LM4CK)](https://codecov.io/gh/dotkernel/dot-controller)

[![SymfonyInsight](https://insight.symfony.com/projects/c4aac671-40d7-4590-b1fa-b3e46a1e3f43/big.svg)](https://insight.symfony.com/projects/c4aac671-40d7-4590-b1fa-b3e46a1e3f43)
[![PHPStan](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml)

## Installation

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

```bash
$ composer require dotkernel/dot-controller
```shell
composer require dotkernel/dot-controller
```

## Usage

Middleware controllers act as a handler for multiple routes. Some conventions were made:

- 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}]`)
- 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`.
- 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}]`).
- 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 a camel-case suffixed by the string `Action`.
For example, a route and action pair like `/user/forgot-password` will be converted to method `forgotPasswordAction`.
- 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.

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

### Example

Creating a UserController with default action and a register action. Will handle routes `/user` and `/user/register`
Creating a UserController with a default action and a register action. Will handle routes `/user` and `/user/register`.

```php
use DotKernel\DotController\AbstractActionController;
use Dot\DotController\AbstractActionController;

class UserController extends AbstractActionController
{
Expand All @@ -55,10 +64,10 @@ class UserController extends AbstractActionController
}
```

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

```php
//Example from a DotKernel RoutesDelegator
// Example from a Dotkernel RoutesDelegator
$app->route(
'/user[/{action}]',
UserController::class,
Expand All @@ -69,10 +78,13 @@ $app->route(

### Multiple controllers for the same route

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
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:

- create your own controller, independent of the package's controller which adds more actions
- create your own controller, independent of the package's controller, which adds more actions
- Mezzio lets you define an array of middleware for a route, so you can register this controller before the package's controller

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.
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)
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.
If this is the last controller, and the action does not match here, it will go to the default 404 Not found page (handled by NotFoundDelegate).
6 changes: 2 additions & 4 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

## Supported Versions


| Version | Supported | PHP Version |
|---------|--------------------|----------------------------------------------------------------------------------------------------------------|
| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.4.3) |
| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.6.0) |
| <= 2.x | :x: | |


## Reporting Potential Security Issues

If you have encountered a potential security vulnerability in this project,
Expand All @@ -24,7 +22,7 @@ When reporting issues, please provide the following information:
We request that you contact us via the email address above and give the
project contributors a chance to resolve the vulnerability and issue a new
release prior to any public exposure; this helps protect the project's
users, and provides them with a chance to upgrade and/or update in order to
users and provides them with a chance to upgrade and/or update to
protect their applications.


Expand Down
29 changes: 15 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dotkernel/dot-controller",
"type": "library",
"description": "DotKernel controller like middleware component with plugin support",
"description": "Dotkernel controller like middleware component with plugin support",
"license": "MIT",
"homepage": "https://github.com/dotkernel/dot-controller",
"keywords": [
Expand All @@ -13,23 +13,24 @@
],
"authors": [
{
"name": "DotKernel Team",
"name": "Dotkernel Team",
"email": "team@dotkernel.com"
}
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"psr/http-message": "^1.0 || ^2.0",
"laminas/laminas-servicemanager": "^3.11.2",
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
"dotkernel/dot-event": "^3.2.0",
"laminas/laminas-servicemanager": "^3.11.2",
"mezzio/mezzio-template": "^2.4.0",
"mezzio/mezzio-helpers": "^5.8.0"
"mezzio/mezzio-helpers": "^5.8.0",
"psr/http-message": "^1.0 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^10.2",
"vimeo/psalm": "^5.13",
"laminas/laminas-coding-standard": "^2.5",
"laminas/laminas-diactoros": "^3.0"
"laminas/laminas-coding-standard": "^3.0",
"laminas/laminas-diactoros": "^3.0",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.2"
},
"autoload": {
"psr-4": {
Expand All @@ -44,13 +45,13 @@
"scripts": {
"check": [
"@cs-check",
"@test"
"@test",
"@static-analysis"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"static-analysis": "psalm --shepherd --stats"
"static-analysis": "phpstan analyse --memory-limit 1G",
"test": "phpunit --colors=always"
},
"config": {
"sort-packages": true,
Expand Down
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

5 changes: 0 additions & 5 deletions docs/book/v3/configuration.md

This file was deleted.

Loading