frizzy/container

1.0.0 2013-11-22 22:05 UTC

This package is not auto-updated.

Last update: 2024-04-22 13:41:42 UTC


README

Usage

Add the following to your root composer.json file:

{
    "require": {
        "frizzy/container": "~1.0"
    }
}

Add a factory:

<?php

$container = new \Frizzy\Container\Container;

$container->set(
    'myFactory',
    function ($container) {
        return new \stdClass
    }
);

?>

Add a shared factory:

<?php

$container = new \Frizzy\Container\Container;

$container->share(
    'mySharedFactory',
    function ($container) {
        return new \stdClass
    }
);

?>

Add a protected closure:

<?php

$container = new \Frizzy\Container\Container;

$container->protect(
    'myProtectedClosure',
    function ($value) {
        return ucfirst($value);
    }
);

?>

Extend a factory:

<?php

$container = new \Frizzy\Container\Container;

$container->share(
    'mySharedFactory',
    function ($container) {
        return new \stdClass
    }
);

$container->extend(
    'mySharedFactory',
    function ($container, $service) {
        $service->date = new \DateTime();
        $service->name = $container->get('otherService')->getName();
    }
);

?>