/** * Apply and register `Application` settings. * * @throws CannotAddNonexistentClass */ private function bootSettings() { // contextual use for routes and di $app = $this; // load the local environment date_default_timezone_set($this['timezone']); mb_internal_encoding($this['mb_internal_encoding']); setlocale(LC_ALL, $this['locale']); $this['nine.container'] = $this->container; # Forge::getInstance(); $this['nine.events'] = function () { return $this->events; }; // For DI, associate the Pimple\Container with this instance of F9\Application. $this->container->add([\Pimple\Container::class, Application::class], function () use($app) { return $this; }); // set native dependencies $this->container->has('config') ?: $this->container->add([get_class($this->config), 'config'], $this->config); $this->container->add([self::class, 'app'], $this); }
/** * @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]; }