szurubooru/src/Injector.php

41 lines
937 B
PHP
Raw Normal View History

2014-09-05 20:33:05 +02:00
<?php
namespace Szurubooru;
use DI\ContainerBuilder;
use Doctrine\Common\Cache\ArrayCache;
2014-09-05 20:33:05 +02:00
final class Injector
{
private static $container;
2014-11-09 12:27:46 +01:00
private static $definitionCache;
2014-09-05 20:33:05 +02:00
public static function init()
{
$definitionsPath = __DIR__
. DIRECTORY_SEPARATOR . '..'
. DIRECTORY_SEPARATOR . 'src'
. DIRECTORY_SEPARATOR . 'di.php';
2014-11-09 12:27:46 +01:00
self::$definitionCache = new ArrayCache();
$builder = new ContainerBuilder();
2014-11-09 12:27:46 +01:00
$builder->setDefinitionCache(self::$definitionCache);
$builder->addDefinitions($definitionsPath);
2014-10-08 23:01:25 +02:00
$builder->useAutowiring(true);
$builder->useAnnotations(false);
2014-09-05 20:33:05 +02:00
self::$container = $builder->build();
}
public static function get($className)
{
return self::$container->get($className);
}
public static function set($className, $object)
{
2014-11-09 12:27:46 +01:00
self::$container->set($className, $object);
self::$definitionCache->delete($className);
self::$definitionCache->flushAll();
}
2014-09-05 20:33:05 +02:00
}
Injector::init();