public function onAppStart() { $request = $this->container->get('request'); $dispatcher = $this->container->get('eventDispatcher'); $this->container->set('database', new Database((new Connector())->connect(Config::fromFile(BASEPATH . '/db.php')))); $appProvider = new AppProvider($this->container->get('database')); $userProvider = new UserProvider($this->container->get('database')); $dispatcher->addListener('onUserAdd', $userProvider); $dispatcher->addListener('onUserDelete', $userProvider); $settings = $this->container->get('settings'); $settings->register('app', $appProvider); $settings->register('user', $userProvider); $session = new Session($this->container->get('database'), $request); $session->start(); $session->setBag('flashes', new FlashBag()); $settings->setCache(new SessionCache($session)); $settings->cache()->retrieve(); $request->setSession($session); if ($request->query->has('locale')) { $request->setLocale($request->query->get('locale')); } elseif ($session->has('locale')) { $request->setLocale($session->get('locale')); } else { $request->setLocale($settings->open('app')->get('language')); } $app = new Base(); $app->setContainer($this->container); $engine = new Engine(BASEPATH . '/app/Cache/templating', new Environment($app)); $engine->setDefinitionResolver(new DefinitionResolver($this->container->get('routing')->getRoute())); $engine->setDefaultExtends('master.base'); $engine->setDefaultData(['app' => $app]); $engine->setCached(false); $this->container->set('templating.engine', $engine); foreach ($this->container->get('package.module.manager')->all() as $module) { $filename = $module->getRoot() . '/services.php'; if (file_exists($filename)) { $this->container->registerFromArray(include $filename); } } $assetter = new Assetter(include BASEPATH . '/web/assetter.php', 0, 'body'); $assetter->registerNamespace('{ROOT}', rtrim($request->getUriForPath('/'), ' /')); $assetter->registerNamespace('{ASSETS}', $request->getUriForPath('/assets')); $this->container->set('assetter', $assetter); if ($session->isNewSession()) { $dispatcher->dispatch('onSessionCreateNew'); } }
/** * Sets the locale. * @param string $locale */ public function setLocale($locale) { $this->locale = $locale; if ($this->hasSession()) { $this->session->set('locale', $this->locale); } return $this; }