PHPackages                             mitsuki/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. [Framework](/categories/framework)
4. /
5. mitsuki/controller

ActiveLibrary[Framework](/categories/framework)

mitsuki/controller
==================

The core controller component for the Mitsuki framework, providing automated action resolution using Mitsuki Attributes and HTTP components.

v1.0.1(4mo ago)19MITPHPPHP &gt;=8.1CI passing

Since Feb 20Pushed 4mo agoCompare

[ Source](https://github.com/zgeniuscoders/mitsuki-controller)[ Packagist](https://packagist.org/packages/mitsuki/controller)[ RSS](/packages/mitsuki-controller/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (3)Used By (0)

Mitsuki Controller
==================

[](#mitsuki-controller)

**Core controller layer for the Mitsuki Framework.**

This package provides the base controller abstraction and the automatic controller discovery system used by the Mitsuki Router. It integrates seamlessly with the `mitsuki/attributes` package to build your routing table from PHP 8 Attributes.

---

✨ Features
----------

[](#-features)

- **Automatic Controller Discovery**: Recursively scans your project to find valid controllers.
- **Attribute-Driven**: Fully compatible with `#[Controller]` and `#[Route]` attributes.
- **Zero Configuration**: No manual controller registration required.
- **Lightweight &amp; Framework-Oriented**: Designed specifically for the Mitsuki ecosystem.
- **Tested &amp; Reliable**: Includes automated tests for discovery edge cases.

---

🚀 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require mitsuki/controller
```

> Requires `mitsuki/attributes` for controller and route metadata.

---

🛠 Usage
-------

[](#-usage)

### 1️⃣ BaseController

[](#1️⃣-basecontroller)

The `BaseController` provides convenient helper methods to create HTTP responses.

```
use Mitsuki\Controller\BaseController;

class UserController extends BaseController
{
    public function index()
    {
        return $this->response('Hello World');
    }

    public function api()
    {
        return $this->json(['status' => 'ok']);
    }
}
```

### Available Helpers

[](#available-helpers)

#### `response($body, int $status = 200, array $headers = []): Response`

[](#responsebody-int-status--200-array-headers---response)

Creates a standard HTTP response.

- Default `Content-Type`: `text/html`
- Fully customizable headers

#### `json($data, int $status = 200, array $headers = []): JsonResponse`

[](#jsondata-int-status--200-array-headers---jsonresponse)

Creates a JSON response.

- Automatically encodes data to JSON
- Automatically sets `Content-Type: application/json`

---

### 2️⃣ ControllerResolver

[](#2️⃣-controllerresolver)

The `ControllerResolver` is responsible for automatically discovering controllers inside your project.

```
use Mitsuki\Controller\Resolvers\ControllerResolver;

$resolver = new ControllerResolver(__DIR__ . '/src');
$controllers = $resolver->resolve();
```

---

🔍 How Controller Discovery Works
--------------------------------

[](#-how-controller-discovery-works)

A class is considered a controller if:

1. It is decorated with `#[Controller]`
2. **OR** it contains at least one method decorated with `#[Route]`

The resolver:

1. Recursively scans the provided root directory.
2. Ignores:

    - Non-PHP files
    - Directories
    - The `vendor/` directory
3. Extracts the Fully Qualified Class Name (FQCN).
4. Uses PHP `ReflectionClass` to inspect attributes.
5. Returns a unique list of valid controllers.

---

🏗 Architecture
--------------

[](#-architecture)

```
Project Source Directory
        ↓
ControllerResolver
        ↓
ReflectionClass
        ↓
#[Controller] / #[Route]
        ↓
Mitsuki Router builds routing table

```

This keeps your routing system:

- Decoupled
- Clean
- Fully metadata-driven

---

🧪 Testing
---------

[](#-testing)

The package includes automated tests that verify:

- ✅ Detection of classes with `#[Controller]`
- ✅ Detection of classes with `#[Route]` methods
- ✅ Ignoring classes without Mitsuki attributes
- ✅ Ignoring the `vendor/` directory
- ✅ Handling invalid directories safely

Example test scenario:

```
#[Controller('/admin')]
class AdminController {}
```

```
class BlogController {
    #[Route('blog_index', '/blog', ['GET'])]
    public function index() {}
}
```

---

📦 Package Structure
-------------------

[](#-package-structure)

```
src/
 ├── BaseController.php
 └── Resolvers/
     └── ControllerResolver.php

```

---

🤝 Contributing
--------------

[](#-contributing)

To contribute:

1. Fork the repository.
2. Improve or extend the resolver logic.
3. Add or update tests.
4. Submit a Pull Request.

---

📄 License
---------

[](#-license)

This project is licensed under the MIT License.

---

**Maintained by Zgenius Matondo**GitHub:

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance75

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

133d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59ea5d2ce29d5426a3d7feabbcc7b07772b03dd80e4cd13afd6f9ac5e0469998?d=identicon)[zgenius](/maintainers/zgenius)

---

Top Contributors

[![zgeniuscoders](https://avatars.githubusercontent.com/u/101071661?v=4)](https://github.com/zgeniuscoders "zgeniuscoders (1 commits)")

---

Tags

mvccontrollermitsukihttp-kernelaction-resolverphp8-attributes

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[laminas/laminas-mvc

Laminas's event-driven MVC layer, including MVC Applications, Controllers, and Plugins

17326.0M393](/packages/laminas-laminas-mvc)[martynbiz/slim3-controller

Provides controller functionality to Slim Framework v3. Also includes PHPUnit TestCase for testing controllers.

2515.1k1](/packages/martynbiz-slim3-controller)

PHPackages © 2026

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