brainexe/annotations

此包已被弃用且不再维护。作者建议使用 brainexe/core 包。

基于doctrine注解的symfony依赖注入容器的简单@annotation库

1.0.11 2017-01-09 20:32 UTC

This package is not auto-updated.

Last update: 2017-02-23 18:49:48 UTC


README

Scrutinizer Code Quality Code Coverage Build Status

composer require brainexe/annotations 1.0.*

注解

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

示例

// Logger.php
/**
 * @Service(public=false)
 */
class Logger
{
    /**
     * @Inject("%log.file%")
     */
    public function __construct($logFile);

    public function log();
}

// Command.php
class Command
{
    /**
     * @var Logger
     */
    private $logger;

    /**
     * @Inject("@Logger")
     */
    __construct(Logger $logger)
    {
        $this->logger = $logger;
    }

    public function run()
    {
        $this->logger->log("Start");
        // do something...
        $this->logger->log("Done");
    }
}

// run.php
use BrainExe\Annotations\Loader;

$container = new ContainerBuilder();
$container->setParameter("log.file", "logs/file.log");

$loader = new Loader($container)
$loader->load('src/');

/** @var Command */
$command = $dic->get('Command');
$command->run();

测试

phpunit