public function testSet() { $this->config->set('foo.bar2', 'test2'); $this->assertEquals($this->config->get('foo.bar2'), 'test2'); $this->config->offsetSet('foo.bar', 'test3'); $this->assertTrue($this->config->offsetExists('foo.bar')); $this->assertEquals($this->config->offsetGet('foo.bar'), 'test3'); $this->config->offsetUnset('foo.bar'); $this->assertEquals($this->config->offsetGet('foo.bar'), null); }
/** * @Request({"config": "array", "options": "array"}, csrf=true) */ public function saveAction($values = [], $options = []) { $config = new Config(); $config->merge(include $file = App::get('config.file')); foreach ($values as $module => $value) { $config->set($module, $value); } file_put_contents($file, $config->dump()); foreach ($options as $module => $value) { $this->configAction($module, $value); } if (function_exists('opcache_invalidate')) { opcache_invalidate($file); } return ['message' => 'success']; }
/** * @Request({"config": "array", "option": "array", "user": "******"}) */ public function installAction($config = [], $option = [], $user = []) { $status = $this->checkAction($config); $message = $status['message']; $status = $status['status']; try { if ('no-connection' == $status) { App::abort(400, __('No database connection.')); } if ('tables-exist' == $status) { App::abort(400, $message); } $scripts = new PackageScripts(App::path() . '/app/system/scripts.php'); $scripts->install(); App::db()->insert('@system_user', ['name' => $user['username'], 'username' => $user['username'], 'password' => App::get('auth.password')->hash($user['password']), 'status' => 1, 'email' => $user['email'], 'registered' => date('Y-m-d H:i:s'), 'roles' => '2,3']); $option['system']['version'] = App::version(); $option['system']['extensions'] = ['blog']; $option['system']['site']['theme'] = 'theme-one'; foreach ($option as $name => $values) { App::config()->set($name, App::config($name)->merge($values)); } if ($this->packages) { $installer = new PackageManager(new NullOutput()); $installer->install($this->packages); } if (file_exists(__DIR__ . '/../../install.php')) { require_once __DIR__ . '/../../install.php'; } if (!$this->config) { $configuration = new Config(); $configuration->set('application.debug', false); foreach ($config as $key => $value) { $configuration->set($key, $value); } $configuration->set('system.secret', App::get('auth.random')->generateString(64)); if (!file_put_contents($this->configFile, $configuration->dump())) { $status = 'write-failed'; App::abort(400, __('Can\'t write config.')); } } App::module('system/cache')->clearCache(); $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]; }