From c70554330c820329e8cc3d985185165a50732d68 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 5 Sep 2014 20:33:05 +0200 Subject: [PATCH] Added Injector class --- public_html/api-dispatch.php | 6 +----- src/Injector.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/Injector.php diff --git a/public_html/api-dispatch.php b/public_html/api-dispatch.php index 41da5375..dc7066b0 100644 --- a/public_html/api-dispatch.php +++ b/public_html/api-dispatch.php @@ -5,9 +5,5 @@ define('DS', DIRECTORY_SEPARATOR); require_once(__DIR__ . DS . '..' . DS . 'vendor' . DS . 'autoload.php'); require_once(__DIR__ . DS . '..' . DS . 'src' . DS . 'AutoLoader.php'); -$builder = new \DI\ContainerBuilder(); -$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 = \Szurubooru\Injector::get(\Szurubooru\Dispatcher::class); $dispatcher->run(); diff --git a/src/Injector.php b/src/Injector.php new file mode 100644 index 00000000..d6a41483 --- /dev/null +++ b/src/Injector.php @@ -0,0 +1,22 @@ +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();