Mozart Dependency Injection Library

v0.1.1 2013-08-26 04:35 UTC

README

Small and Simple Dependency Injection Library

Build Status- Latest Stable Version

usage

<?php
use Mozart\Library\DI\Container;

class Builder
{
    protected $parameter;
    protected $argument;

    public function setParameter($parameter)
    {
        $this->parameter = $parameter;

        return $this;
    }

    public function setArgument($argument)
    {
        $this->argument = $argument;

        return $this;
    }

    public function execute()
    {
        return $this->parameter . ' - ' . $this->argument;
    }
}

class MyService
{
    public function indexAction()
    {
        return 'GET';
    }
}

$container = new Container();
$container->set('builder', function() use($container) {
        return $container->instance('Builder');
    });

$builder = $container->get('builder');
echo $builder
        ->setParameter('parameter')
        ->setArgument('argument')
        ->execute();


$container = new Container();
$container->set('service', function () use ($container) {
        $container->instance('MyService');
        // defined instance class with fully namespaces
        // $container->instance(Namespace\\Source)
    });
$service = $container->get('service');
$service->indexAction();