PHPackages                             gabidj/dot-controller - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gabidj/dot-controller

ActiveLibrary

gabidj/dot-controller
=====================

DotKernel controller like middleware component with plugin support

v1.0.0(8y ago)015MITPHPPHP ^7.1CI failing

Since Mar 8Pushed 7y ago1 watchersCompare

[ Source](https://github.com/gabidj/dot-controller)[ Packagist](https://packagist.org/packages/gabidj/dot-controller)[ RSS](/packages/gabidj-dot-controller/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (8)Versions (9)Used By (0)

dot-controller
==============

[](#dot-controller)

This package contains controller like middleware to be used inside a DotKernel or Expressive application. It provides base classes for action based controllers similar to ZF3 controller component. It is more lightweight though, but supports controller plugins.

Installation
------------

[](#installation)

Run the following composer command in your project directory

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

Merge the `ConfigProvider` to your configuration aggregate.

Usage
-----

[](#usage)

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

- register controllers in the routes array just like any expressive 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`.
- 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`

##### Example 1

[](#example-1)

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

##### UserController.php

[](#usercontrollerphp)

```
use DotKernel\DotController\AbstractActionController;

class UserController extends AbstractActionController
{
    public function indexAction()
    {
        //...
    }

    public function registerAction()
    {
        //...
    }
}
```

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

### Multiple controllers for the same 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

- create your own controller, independent of the package's controller which adds more actions
- Zend Expressive 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)

Controller plugins
------------------

[](#controller-plugins)

Controllers support controller plugins, much like controllers in a ZF3 application. The module comes packed with a few common plugins, but you can extend controller functionality with your own plugins too.

### Usage

[](#usage-1)

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 ZF3 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`.

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)

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.

##### Example

[](#example)

```
//inside a controller
//assume we've already registered a plugin called testPlugin
$this->testPlugin(); //will return the TestPlugin class so you can call any public defined method on it
$this->testPlugin()->someMethod();
```

### Built-in plugins

[](#built-in-plugins)

Note: Each of these plugins requires the associated ZE packages to be installed and available in your project. Although these are optional, if a package is missing, the controller will not have the associated functionality available

- `template` wraps TemplateInterface provided by ZE, to make template engine accessible to any controller
- `url` wraps the UrlHelper class provided by ZE helpers package. Used to generate URIs from routes

Controller Events
-----------------

[](#controller-events)

// @TODO

###  Health Score

27

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 94.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~63 days

Recently: every ~93 days

Total

7

Last Release

2923d ago

Major Versions

0.3.1 → v1.0.02018-03-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/c173326fcc83c5ab97ccbd334b00bb594e020aaf0abb05590856b4f70586f648?d=identicon)[gabidj](/maintainers/gabidj)

---

Top Contributors

[![n3vrax](https://avatars.githubusercontent.com/u/5805542?v=4)](https://github.com/n3vrax "n3vrax (35 commits)")[![gabidj](https://avatars.githubusercontent.com/u/3998573?v=4)](https://github.com/gabidj "gabidj (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gabidj-dot-controller/health.svg)

```
[![Health](https://phpackages.com/badges/gabidj-dot-controller/health.svg)](https://phpackages.com/packages/gabidj-dot-controller)
```

###  Alternatives

[ppi/framework

PPI Framework - The PHP Interoperability Framework!

1542.4k2](/packages/ppi-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
