brainexe/annotations

This package is abandoned and no longer maintained. The author suggests using the brainexe/core package instead.

Simple @annotation library based on doctrine annotations for symfony dependency injection container

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.*

Annotations

The files in this archive are released under the MIT license. You can find a copy of this license in the LICENSE file.

Example

// 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();

Tests

phpunit