samburns/dirty-needle

Dependency Injection container for PHP

3.0.3 2015-03-15 17:50 UTC

This package is auto-updated.

Last update: 2024-10-24 04:12:56 UTC


README

Build Status Coverage Status Scrutinizer Code Quality

dirty-needle

Introduction

Dependency Injection container for PHP

Set up a config file which returns a PHP array, like this:

<?php
return array(
    'dirty-needle' => array(
        '@dependency' => array(
            'class' => '\Dependency'
        ),
        '@class-with-dependency' => array(
            'class' => '\ClassWithDependency',
            'arguments' => array(
                '@dependency'
            )
        ),
    ),
);

Then get stuff out of your container, like this:

$diContainer = \DirtyNeedle\DiContainer()::getInstance();
$diContainer->addConfigFile('/path/to/config.php');
$classWithDependency = $diContainer->get('class-with-dependency');

You can also do inject mock objects:

$diContainer->set('service-id', $mockObject);

Reseting definitions and mocks:

$diContainer->reset();

Releases are available supporting PHP5.3-5.6, with the 5.6-compatible releases being significantly faster in their implementation.

Versioning

The project uses semantic versioning.