PHPackages                             devmachine/services-injector-bundle - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. devmachine/services-injector-bundle

AbandonedSymfony-bundle[Utility &amp; Helpers](/categories/utility)

devmachine/services-injector-bundle
===================================

Inject services in controllers using annotations.

1.1.0(8y ago)013MITPHP &gt;=5.4

Since Oct 20Compare

[ Source](https://github.com/lakiboy/devmachine-services-injector-bundle)[ Packagist](https://packagist.org/packages/devmachine/services-injector-bundle)[ Docs](https://github.com/lakiboy/devmachine-services-injector-bundle)[ RSS](/packages/devmachine-services-injector-bundle/feed)WikiDiscussions Synced 1w ago

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

DevmachineServicesInjectorBundle
================================

[](#devmachineservicesinjectorbundle)

[![Build Status](https://camo.githubusercontent.com/7e069d6f3f1421b98c06c8cbac8952fac3cdc4269d66536883ae51c75e8597be/68747470733a2f2f7472617669732d63692e6f72672f6c616b69626f792f6465766d616368696e652d73657276696365732d696e6a6563746f722d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lakiboy/devmachine-services-injector-bundle) [![Coverage Status](https://camo.githubusercontent.com/0738448fe50cdb18d69500fc496de07e69df67a188da7e6d0286069e2dd9209b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6c616b69626f792f6465766d616368696e652d73657276696365732d696e6a6563746f722d62756e646c652f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/lakiboy/devmachine-services-injector-bundle?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/358f3b0e8a29513b6ef3c793a347a00640091414dbe61fd0a8c1688f9776c603/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c616b69626f792f6465766d616368696e652d73657276696365732d696e6a6563746f722d62756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lakiboy/devmachine-services-injector-bundle/?branch=master) [![SensioLabsInsight](https://camo.githubusercontent.com/043ad34a9a891ea05f5b8986f995e5be701097c91da1eb14acce7728cac24d39/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33643063643237372d396664382d343639312d393061362d6632356337353935346430642f6d696e692e706e67)](https://insight.sensiolabs.com/projects/3d0cd277-9fd8-4691-90a6-f25c75954d0d)

Inject services into controllers using annotations on top of [SensioFrameworkExtraBundle](https://github.com/sensiolabs/SensioFrameworkExtraBundle).

2017 update
-----------

[](#2017-update)

As of Symfony 3.3 you can type hint a controller argument to receive a service. [Read more](http://symfony.com/doc/current/controller.html#fetching-services-as-controller-arguments)

Preambule
---------

[](#preambule)

There are many ways how to retrieve services in controllers. The easiest one is to extend default container aware `Symfony\Bundle\FrameworkBundle\Controller\Controller` controller and use `get('')` method to get a service. This approach is not favoured by purists as injecting a container considers a bad practice (as they say). It is recommended to inject controller dependencies instead in same way you do with other services.

However, this could lead to far too many injections. `Controller#actionOne()` and `Controller#actionTwo()` requirements could be completely different. There is a way to mitigate this by implementing controller utilities class. More info [in this article](http://www.whitewashing.de/2013/06/27/extending_symfony2__controller_utilities.html) by *Doctrine* author.

About
-----

[](#about)

This bundle tries to satisfy both camps. It injects service locator as a request attribute into controller, configured to retrieve defined set of services. Using this approach there is no need to inject container into controller, and each action can retrieve services it actually needs.

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

[](#installation)

Add the following to your composer.json:

```
{
    "require": {
        "devmachine/services-injector-bundle": "~1.0"
    }
}
```

Register bundle in the kernel:

```
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...

        new Devmachine\Bundle\ServicesInjectorBundle\DevmachineServicesInjectorBundle(),
    );
}
```

Example usage
-------------

[](#example-usage)

```
namespace Acme\UserBundle\Controller;

use Devmachine\Bundle\ServicesInjectorBundle\Configuration\Service;
use Devmachine\Bundle\ServicesInjectorBundle\Request\Services;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Inject to all actions.
 *
 * @Service(user_manager="fos_user.user_manager")
 */
class UserController
{
    /**
     * Multiple definitions.
     *
     * @Service("twig")
     * @Service("translator")
     */
    public function indexAction(Services $services)
    {
        $params = [
            // Use explicit service name.
            'title' => $services->get('translator')->trans('users'),

            // Use __call() i.e. same as $services->get('user_manager').
            'users' => $services->getUserManager()->findAll(),
        ];

        return new Response($services->getTwig()->render('AcmeUserBundle:User:index', $params));
    }

    /**
     * Array definition.
     *
     * @Service({"ff"="form.factory", "url_generator"="router", "translator", "twig"})
     */
    public function editAction(Request $request, $username, Services $services)
    {
        $user = $services->getUserManager()->findByUsername($username);
        $form = $services->get('ff')->createForm('acme_user', $user);

        // ...
    }
}
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity60

Established project with proven stability

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 ~353 days

Total

3

Last Release

3247d ago

### Community

Maintainers

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

---

Tags

controllerannotation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/devmachine-services-injector-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/devmachine-services-injector-bundle/health.svg)](https://phpackages.com/packages/devmachine-services-injector-bundle)
```

###  Alternatives

[aimeos/ai-controller-frontend

Aimeos business controller logic for frontend

1.0k355.8k21](/packages/aimeos-ai-controller-frontend)[koriym/attributes

An annotation/attribute reader

423.7M15](/packages/koriym-attributes)[hyperf/di

A DI for Hyperf.

183.1M735](/packages/hyperf-di)[aura/dispatcher

Creates objects from a factory and invokes methods using named parameters; also provides a trait for invoking closures and object methods with named parameters.

3698.6k3](/packages/aura-dispatcher)[gomachan46/state-machine

simple state machine with annotations for PHP, inspired by AASM known as a Ruby state machine.

2099.3k](/packages/gomachan46-state-machine)[marcin-orlowski/lombok-php

Never write boilerplate code for your data class again!

3220.3k1](/packages/marcin-orlowski-lombok-php)

PHPackages © 2026

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