loso/di-annotations-bundle

一个能够通过注解实现依赖注入的组件,适用于您的Symfony2项目。

dev-master 2012-12-20 12:48 UTC

This package is not auto-updated.

Last update: 2024-09-28 13:11:59 UTC


README

什么是LosoDiAnnotationsBundle?

一个能够通过注解实现依赖注入的组件,适用于您的Symfony2项目。

Build Status

需求

LosoDiAnnotationsBundle 需要 PHP 5.3 或更高版本。它已经与 Symfony v2.0.4 进行了测试。

您需要在您的 vendor 目录中至少安装以下库

  • Doctrine\Common
  • Symfony

如果您想使用与实体存储库相关的功能,您还需要

  • Doctrine\DBAL
  • Doctrine\ORM

许可证

此存档中的文件是在 MIT 许可证下发布的。您可以在 LICENSE 文件中找到此许可证的副本。

文档

您可以在 Resources/doc/index.rst 中阅读文档

测试

LosoDiAnnotationsBundle 经过大量测试!要运行测试,您需要设置 Tests/bootstrap.php 中 vendors 库的路径,并从项目的根目录运行以下命令

phpunit --colors --bootstrap Tests/bootstrap.php Tests

此外,LosoDiAnnotationsBundle 使用 Travis 进行持续集成,请参阅: Build Status

安装

1. 将 LosoDiAnnotationsBundle 添加到您的 vendor 库中

$ cp -r <path_to>/LosoDiAnnotationsBundle vendor/bundles/Loso/Bundle/DiAnnotationsBundle

或通过 Git

$ git submodule add git://github.com/loicfrering/LosoDiAnnotationsBundle.git vendor/bundles/Loso/Bundle/DiAnnotationsBundle

2. 在 app/autoload.php 中将 Loso 命名空间注册到自动加载器

<?php
$loader->registerNamespaces(array(
    // ...
    'Symfony'          => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
    'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
    'Loso'             => __DIR__.'/../vendor/bundles',
    // ...
));

3. 在 app/AppKernel.php 中将 LosoDiAnnotationsBundle 注册到应用程序的内核

<?php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Loso\Bundle\DiAnnotationsBundle\LosoDiAnnotationsBundle(),
        // ...
    );

    // ...

    return $bundles;
}

配置

您可以在以下方式之一中配置 LosoDiAnnotationsBundle,在 app/config/config.yml 中

# app/config/config.yml
loso_di_annotations:
    service_scan:
        DemoBundle: ~
        MyBundle:
            base_namespace: [Prefix1, Prefix2\SubPrefix]
        arbitrary_key:
            dir:
                - dir1
                - dir2