Exemple #1
0
 public function connect(Config $config)
 {
     $this->config = $config;
     $this->connection = new \PDO("mysql:host={$config->get('host')};dbname={$config->get('name')}" . ($config->get('port') != '' ? ';port=' . $config->get('port') : ''), $config->get('user'), $config->get('pass'), [\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"]);
     $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     return $this;
 }
Exemple #2
0
 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');
     }
 }
Exemple #3
0
 public function onAppStart()
 {
     $locale = $this->container->get('request')->getLocale();
     $localeUpper = strtoupper($locale);
     $translation = $this->container->get('translation');
     $translation->setLocale($locale);
     // Main language file
     if (file_exists(BASEPATH . "/app/Language/{$localeUpper}/definitions.ini")) {
         $translation->attachFromConfig(Config::fromFile(BASEPATH . "/app/Language/{$localeUpper}/definitions.ini"));
     }
     foreach ($this->container->get('package.module.manager')->all() as $module) {
         $filename = BASEPATH . "/app/App/Module/{$module->getName()}/Language/{$locale}.ini";
         if (file_exists($filename)) {
             $translation->attachFromConfig(Config::fromFile($filename));
         }
     }
 }
Exemple #4
0
 public function attachFromConfig(Config $config, $locale = null)
 {
     $locale = $locale ? $locale : $this->locale;
     $this->content[$locale] = isset($this->content[$locale]) ? array_merge($config->all(), $this->content[$locale]) : $config->all();
     return $this;
 }