/**
  * @Request({"config": "array", "option": "array", "tab": "int"}, csrf=true)
  */
 public function saveAction($data, $option, $tab = 0)
 {
     // TODO: validate
     $data['app.debug'] = @$data['app.debug'] ?: '0';
     $data['profiler.enabled'] = @$data['profiler.enabled'] ?: '0';
     $data['app.nocache'] = @$data['app.nocache'] ?: '0';
     $data['cache.cache.storage'] = @$data['cache.cache.storage'] ?: 'auto';
     $option['system:app.site_title'] = @$option['system:app.site_title'] ?: '';
     $option['system:maintenance.enabled'] = @$option['system:maintenance.enabled'] ?: '0';
     foreach ($data as $key => $value) {
         $this->config->set($key, $value);
     }
     file_put_contents($this->configFile, $this->config->dump());
     foreach ($option as $key => $value) {
         $this['option']->set($key, $value, true);
     }
     if ($data['cache.cache.storage'] != $this['config']->get('cache.cache.storage') || $data['app.debug'] != $this['config']->get('app.debug')) {
         $this['system']->clearCache();
     }
     if (function_exists('opcache_invalidate')) {
         opcache_invalidate($this->configFile);
     }
     $this['message']->success(__('Settings saved.'));
     return $this->redirect('@system/settings', compact('tab'));
 }
 protected function getCookieConfig()
 {
     $config = new Config();
     $config->set('cookie.path', 'path/to/cookie');
     $config->set('cookie.domain', 'localhost');
     return $config;
 }
 public function getConfig($settings)
 {
     $config = new Config();
     foreach ($settings as $key => $value) {
         $config->set($key, $value);
     }
     return $config;
 }
 /**
  * @Request({"config": "array", "option": "array", "user": "******"})
  * @Response("json")
  */
 public function installAction($config = [], $option = [], $user = [])
 {
     $status = $this->checkAction($config, false);
     $message = '';
     try {
         foreach (['blog', 'page', 'system'] as $extension) {
             $this['extensions']->load($extension);
         }
         if ('no-connection' == $status) {
             throw new Exception(__('No database connection.'));
         }
         if ('tables-exist' == $status) {
             $this['extensions']->get('system')->enable();
         } else {
             $this['option']->set('system:version', $this['migrator']->create('extension://system/migrations')->run());
             $this['option']->set('system:extensions', ['blog', 'page'], true);
             $this['db']->insert('@system_user', ['name' => $user['username'], 'username' => $user['username'], 'password' => $this['auth.password']->hash($user['password']), 'status' => 1, 'email' => $user['email'], 'registered' => new \DateTime()], ['string', 'string', 'string', 'string', 'string', 'datetime']);
             $id = $this['db']->lastInsertId();
             $this['db']->insert('@system_user_role', ['user_id' => $id, 'role_id' => RoleInterface::ROLE_AUTHENTICATED]);
             $this['db']->insert('@system_user_role', ['user_id' => $id, 'role_id' => RoleInterface::ROLE_ADMINISTRATOR]);
             $this['extensions']->get('system')->enable();
             // sample data
             $sql = file_get_contents('extension://installer/sample_data.sql');
             foreach (explode(';', $sql) as $query) {
                 if ($query = trim($query)) {
                     $this['db']->executeUpdate($query);
                 }
             }
         }
         if (!$this->config) {
             $configuration = new Config();
             foreach ($config as $key => $value) {
                 $configuration->set($key, $value);
             }
             $configuration->set('app.key', $this['auth.random']->generateString(64));
             if (!file_put_contents($this->configFile, $configuration->dump())) {
                 $status = 'write-failed';
                 throw new Exception(__('Can\'t write config.'));
             }
         }
         foreach ($option as $key => $value) {
             $this['option']->set($key, $value, true);
         }
         $status = 'success';
     } catch (DBALException $e) {
         $status = 'db-sql-failed';
         $message = __('Database error: %error%', ['%error%' => $e->getMessage()]);
     } catch (\Exception $e) {
         $message = $e->getMessage();
     }
     return ['status' => $status, 'message' => $message];
 }
 public function testDump()
 {
     $this->config->dump();
 }
Exemple #6
0
<?php

use Pagekit\Component\Config\Config;
$values = array_map('realpath', ['path' => __DIR__ . '/..', 'path.cache' => __DIR__ . '/cache', 'path.logs' => __DIR__ . '/logs', 'path.temp' => __DIR__ . '/temp', 'path.extensions' => __DIR__ . '/../extensions', 'path.storage' => __DIR__ . '/../storage', 'path.themes' => __DIR__ . '/../themes', 'path.vendor' => __DIR__ . '/../vendor', 'config.file' => __DIR__ . '/../config.php']);
$config = new Config($values);
$config->load(__DIR__ . '/config/app.php');
if ($values['config.file']) {
    $config->load($values['config.file']);
}
if ($config['app.nocache']) {
    $config->set('cache.storage', 'array');
}
$values['config'] = $config;
return $values;