Added Injector class
This commit is contained in:
parent
8edf81e75e
commit
c70554330c
2 changed files with 23 additions and 5 deletions
|
@ -5,9 +5,5 @@ define('DS', DIRECTORY_SEPARATOR);
|
||||||
require_once(__DIR__ . DS . '..' . DS . 'vendor' . DS . 'autoload.php');
|
require_once(__DIR__ . DS . '..' . DS . 'vendor' . DS . 'autoload.php');
|
||||||
require_once(__DIR__ . DS . '..' . DS . 'src' . DS . 'AutoLoader.php');
|
require_once(__DIR__ . DS . '..' . DS . 'src' . DS . 'AutoLoader.php');
|
||||||
|
|
||||||
$builder = new \DI\ContainerBuilder();
|
$dispatcher = \Szurubooru\Injector::get(\Szurubooru\Dispatcher::class);
|
||||||
$builder->setDefinitionCache(new Doctrine\Common\Cache\ArrayCache());
|
|
||||||
$builder->addDefinitions(__DIR__ . DS . '..' . DS . 'src' . DS . 'di.php');
|
|
||||||
$container = $builder->build();
|
|
||||||
$dispatcher = $container->get('Szurubooru\Dispatcher');
|
|
||||||
$dispatcher->run();
|
$dispatcher->run();
|
||||||
|
|
22
src/Injector.php
Normal file
22
src/Injector.php
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru;
|
||||||
|
|
||||||
|
final class Injector
|
||||||
|
{
|
||||||
|
private static $container;
|
||||||
|
|
||||||
|
public static function init()
|
||||||
|
{
|
||||||
|
$builder = new \DI\ContainerBuilder();
|
||||||
|
$builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache());
|
||||||
|
$builder->addDefinitions(__DIR__ . DS . '..' . DS . 'src' . DS . 'di.php');
|
||||||
|
self::$container = $builder->build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get($className)
|
||||||
|
{
|
||||||
|
return self::$container->get($className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Injector::init();
|
Loading…
Reference in a new issue