/** * @param array $paths * @param ContainerInterface|Forge $container * * @return array */ private function registerClasses(array $paths, $container) { // we'll start by loading the configuration into the Forge Container $container->add(ContainerInterface::class, function () { return Forge::getInstance(); }); $container->add([Scope::class, 'context'], function () { return new Scope(); }); $container->add('environment', function () use($container) { return $container['GlobalScope']; }); $container->singleton([GlobalScope::class, 'GlobalScope'], $global_scope = new GlobalScope($this)); $container->singleton([Paths::class, 'Paths'], new Paths($paths)); $container->singleton([Config::class, 'Config'], $config = Config::createFromFolder(\CONFIG)); $container->singleton([Events::class, 'Events'], $events = Events::getInstance()); $container->add('paths', function () use($container) { return $container['Paths']; }); $container->add('config', function () use($container) { return $container['Config']; }); return [$global_scope, $config, $events]; }
/** * @param array $paths * * @return Application */ private function makeApplication(array $paths) : Application { // this is the Illuminate Container $container = Forge::getInstance(); // we'll start by loading the configuration into the Forge Container $container->add([Scope::class, 'context'], function () { return new Scope(); }); $container->add('environment', function () use($container) { return $container['GlobalScope']; }); $container->singleton([GlobalScope::class, 'GlobalScope'], $global_scope = new GlobalScope($this)); $container->singleton([Paths::class, 'Paths'], new Paths($paths)); $container->singleton([Config::class, 'Config'], $config = Config::createFromFolder(\CONFIG)); $container->singleton([Events::class, 'Events'], $events = Events::getInstance()); $container->add('paths', function () use($container) { return $container['Paths']; }); $container->add('config', function () use($container) { return $container['Config']; }); // the reason we are here $app = new NineApplication($container, $config, $events, $global_scope); // align the Nine Events object with the Core EventDispatcher (Symfony) Events::setEventDispatcher($app['dispatcher']); $app['app.context'] = 'app'; // register the new Application $container->singleton([NineApplication::class, 'Application'], $app); // synchronize the Application instance with the forge. Forge::setApplication($app); // additional $app registrations. @formatter:off $app['container'] = $container; $app['global.scope'] = $global_scope; $app['app.factory'] = $this; $app['flashbag'] = $app->factory(function () use($app) { return $app['session']->getFlashBag(); }); $app['paths'] = $container['Paths']; //@formatter:on return $app; }