astina/injection-bundle

Lets you inject services and container parameters into controllers.

Installs: 5 984

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 10

Forks: 0

Type:symfony-bundle

0.2.0 2013-05-11 09:51 UTC

README

Lets you inject services and container parameters into controllers.

Installation

Step 1: Add to composer.json

"require" :  {
    // ...
    "astina/injection-bundle":"dev-master",
}

Step 2: Enable the bundle

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Astina\Bundle\InjectionBundle\AstinaInjectionBundle(),
    );
}

##Usage

use Astina\Bundle\InjectionBundle\Annotation as Inject;

class DefaultController
{
    /**
     * @Inject\Service("session")
     * @var SessionInterface
     */
    private $session;

    /**
     * @Inject\Parameter("acme_foo")
     */
    private $foo;

    /**
     * @Route("/foo", name="foo")
     * @Template
     */
    public function indexAction()
    {
        $foo = $this->session->get($this->foo);

        return array(
            'foo' => $foo,
        );
    }
}