PHPackages                             nubox/laminas-controller-injector - 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. nubox/laminas-controller-injector

ActiveLibrary

nubox/laminas-controller-injector
=================================

Inject Route parameters into Controller methods

1.0.0(2y ago)03BSD-3-ClausePHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0

Since Jan 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/nusphere/laminas-controller-injector)[ Packagist](https://packagist.org/packages/nubox/laminas-controller-injector)[ Fund](https://funding.communitybridge.org/projects/laminas-project)[ RSS](/packages/nubox-laminas-controller-injector/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laminas Controller Injector
===========================

[](#laminas-controller-injector)

Description
-----------

[](#description)

The core feature of this “plugin” is the ability to set parameters for controller methods. Primarily to pass the value of a variable of a route directly to the method at the dispatch event as an argument. The new `AbstractInjectorController` must be used for this usage.

In addition, with the new dispatcher you can also do without the “Action” postfix for these methods.

Requirements
------------

[](#requirements)

- PHP 8.1 or above
- Laminas MVC 3.7.0 or above

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

[](#installation)

Use composer to install the package:

`composer require nubox/laminas-controller-injector`

Activate Plugin in our Laminas Application
------------------------------------------

[](#activate-plugin-in-our-laminas-application)

```
return [
    // Retrieve list of modules used in this application.
    'modules' => [
        ...,
        Laminas\Mvc\Injector\Module::class, // or 'Laminas\Mvc\Injector'
    ],
    ...
];
```

Usage
-----

[](#usage)

Suppose you have a controller that looks like this:

```
class MyController extends AbstractInjectorController
{
    public function myMethod(string $param) {
        // ...
    }
}
```

You can map routes to this controller method using the format `controller::method` and pass parameters from the routes directly into the method:

```
return [
    'router' => [
        'routes' => [
            'my-route' => [
                'type' => Laminas\Router\Http\Segment::class,
                'options' => [
                    'route' => '/my-route/:param',
                    'defaults' => [
                        'controller' => MyController::class,
                        'action' => 'myMethod'
                    ]
                ]
            ]
        ]
    ],
];
```

In the example above, the `:param` placeholder in the route gets passed directly as the `$param` argument to `myMethod()`.

AbstractInjectorController
--------------------------

[](#abstractinjectorcontroller)

The provided `\Laminas\Mvc\Injector\Controller\AbstractInjectorController` is required as Controller extension. It matches the given parameter values into the requested action. The same variable name is required.

As soon as the `AbstractInjectorController` is used, in addition to the route parameters, objects from the `ServiceManager` are also injected into the corresponding controller method - regardless of the route. This reduces the processes necessary to access a service from the ServiceManager.

The respective request can also be injected as a complete request object.

```
class MyController extends AbstractInjectorController
{
    public function serviceParameter(DemoService $demoService): Response
    {
        $response = new Response();
        $response->setContent($demoService->getValue());

        return $response;
    }
}
```

Available ArgumentResolver -&gt; (configurable `controller_argument_resolver`)
------------------------------------------------------------------------------

[](#available-argumentresolver---configurable-controller_argument_resolver)

Every argument of a controller method is analyzed and can be determined by the activated ArgumentResolver. The following ArgumentResolvers are activated by default. However, additional ArgumentResolvers can also be added.

#### Activated by default:

[](#activated-by-default)

- IntegerArgumentResolver - inject a `int`, parsed from Route parameters (`int` required)
- StringArgumentResolver - inject a `string` , parsed from Route parameters (no typehint or `string` required)
- RequestArgumentResolver - inject the responding `Request` object into the method (`Request` required)
- ServiceArgumentResolver - inject an `object` from the container (ServiceManager) (explicit object Typehint required)

```
return [
    /**
     * each resolver need to implement ArgumentResolverInterface:class
     */
    'controller_argument_resolver' => [
        StringArgumentResolver::class,
        IntegerArgumentResolver::class,
        RequestArgumentResolver::class,
        ServiceArgumentResolver::class,
    ],
];
```

Normally you need a corresponding type hint to determine the correct ArgumentResolver. In the event that no suitable type can be found, you can use the MarkUp interface `NonTypeArgumentResolverInterface`for your own ArgumentResolver. this would then also be “queried” in such a case.

Suggestion
----------

[](#suggestion)

Use [nubox/laminas-router-attributes](https://github.com/nusphere/laminas-router-attributes) for reduce configuration overhead with symfony route attributes.

```
class MyController extends AbstractInjectorController
{
    #[Route(path: 'calc-optional/{operand1}/{operand2?100}', name: 'calc-optional-route')]
    public function calculateWithRouteDefault(int $operand1, int $operand2 = 100): Response
    {
        $response = new Response();
        $response->setContent($operand1 * $operand2);

        return $response;
    }

    #[Route(path: 'default', name: 'default-route')]
    public function somedefaults(Request $request, string $default = 'defaults'): Response
    {
        $response = new Response();
        $response->setContent($request->getUri()->getPath() . ' - ' . $default);

        return $response;
    }
}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Unknown

Total

1

Last Release

858d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/981e7d33e845cbf63bb52f9d61b32a41421f88392f488970a9023858aa0e30d3?d=identicon)[Nusphere](/maintainers/Nusphere)

---

Top Contributors

[![nusphere](https://avatars.githubusercontent.com/u/5822825?v=4)](https://github.com/nusphere "nusphere (10 commits)")

###  Code Quality

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nubox-laminas-controller-injector/health.svg)

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

###  Alternatives

[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[doctrine/doctrine-orm-module

Laminas Module that provides Doctrine ORM functionality

4407.3M292](/packages/doctrine-doctrine-orm-module)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[laminas/laminas-mvc

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

17224.4M364](/packages/laminas-laminas-mvc)[rwoverdijk/assetmanager

An assetmanager module for Laminas.

2142.1M49](/packages/rwoverdijk-assetmanager)[doctrine/doctrine-mongo-odm-module

Laminas Module which provides Doctrine MongoDB ODM functionality

86676.6k35](/packages/doctrine-doctrine-mongo-odm-module)

PHPackages © 2026

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