Skip to content
/ di Public

[READ ONLY] Subtree split of `Lucid\DI`

Notifications You must be signed in to change notification settings

lucidphp/di

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dependency Injection container (interop container).

Author Source Code Software License

Build Status Code Coverage HHVM

Installation

$ composer require lucid/di:dev-develop

Requirements

container-interop/container-interop

The Container

A simple container

<?php

use Lucid\DI\Container;

$container->set('foo', new Acme\Foo);

$container->get('foo'); // instance of Acme\Foo

Aliasing ids

<?php
$container->setAlias('foo', 'bar');

$container->get('bar'); // instance of Acme\Foo

Overriding services

<?php

// throws `Interop\Container\Exception\ContainerException`
$container->set('foo', new Acme\Bar);  

// use `replace` instead
$container->replace('foo', new Acme\Bar);  

// or use `$forcereplace`
$container->set('foo', new Acme\Bar, Container::FORCE_REPLACE_ON_DUPLICATE);  

The Container Builder

<?php

use Lucid\DI\ContainerBuilder;
use Lucid\DI\Definition\Service;

$container = new ContainerBuilder;

// define a service by id and class
$service = $container->define('foo', 'Acme\Foo');

// You can configure the service in detail
$service->...

// basically the same
$container->setService('foo', $service = new Service('Acme\Foo'));

About

[READ ONLY] Subtree split of `Lucid\DI`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages