astina/injection-bundle

此包已被废弃且不再维护。未建议替代包。

允许将服务和容器参数注入到控制器中。

安装数: 6,041

依赖者: 0

推荐者: 0

安全: 0

星标: 0

关注者: 12

分支: 0

类型:symfony-bundle

0.2.0 2013-05-11 09:51 UTC

This package is not auto-updated.

Last update: 2022-06-20 03:21:09 UTC


README

允许将服务和容器参数注入到控制器中。

安装

步骤 1: 添加到 composer.json

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

步骤 2: 启用该包

在内核中启用该包

<?php
// app/AppKernel.php

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

##使用

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,
        );
    }
}