omerucel / di
There is no license information available for the latest version (1.2) of this package.
1.2
2017-07-05 19:20 UTC
Requires
- psr/container: 1.0.0
Requires (Dev)
- phpunit/php-code-coverage: 2.0.5
- phpunit/phpunit: 4.0.14
This package is not auto-updated.
Last update: 2024-12-29 09:09:47 UTC
README
About
A simple DI class.
Composer
{ "require": { "omerucel/di": "dev-master" } }
Usage
<?php $environment = getenv('APPLICATION_ENV'); $di = new OU\DI(); $di->setShared('config', function ($di) use ($environment) { return new Config(realpath(__DIR__ . '/' . $environment . '.php'); }); $di->setShared('logger', function ($di) { return new Logger($di->get('config')->file_path); }); /** * @var Logger $logger */ $logger = $di->get('logger'); $logger->info('Hello world!'); $di->reloadShared('logger')->info('Hello world!');
With Service implementation:
<?php namespace Project\Service; class ConfigService implements \OU\DI\Service { public function getService(\OU\DI $di) { $environment = $di->get('environment'); return new Config(realpath(__DIR__ . '/' . $environment . '.php'); } }
<?php $di = new OU\DI(); $di->setShared('environment', 'development'); $di->setSharedService('config', 'Project\Service\ConfigService'); $config = $di->get('config');