protected function getSettingPrototype($path, $plugin = null) { $defaults = ['title' => null, 'description' => null, 'cell' => null, 'default' => null, 'options' => null, 'hidden' => false]; //TODO: maybe implement cache for reader results or remember results in table class in future $settingsReader = new PhpConfig(); $input = 'settings'; if (!empty($plugin)) { $input = $plugin . '.settings'; } $settingPrototypes = $settingsReader->read($input); if ($setting = Hash::extract($settingPrototypes, '{n}[path=' . $path . ']')[0]) { return array_merge($defaults, $setting); } return []; }
public function import() { $settingsFile = 'settings'; if (!empty($this->plugin)) { $settingsFile = $this->plugin . '.' . $settingsFile; $settingsFileDir = Plugin::path($this->plugin) . 'config'; } else { $settingsFileDir = ROOT . DS . 'config'; } $settingsDir = new Folder($settingsFileDir, false); if (!$settingsDir->find('settings.*')) { return false; } $config = new PhpConfig(); $data = $config->read($settingsFile); if (!$data) { return false; } if (!empty($this->plugin)) { $this->out(__d('platform', '- <success>Processing settings pool for {0} plugin</success>', $this->plugin)); } else { $this->out(__d('platform', '- <success>Processing settings pool for {0}</success>', 'App')); } $settingsTable = TableRegistry::get('Platform.Settings'); foreach ($data as $row) { if (!isset($row['plugin']) || empty($row['plugin'])) { $row['plugin'] = $this->plugin; } $data = ['plugin' => $row['plugin'], 'path' => $row['path']]; $setting = $settingsTable->find('all', ['conditions' => $data])->first(); if (!$setting) { $setting = $settingsTable->newEntity(); $data = array_merge($data, ['value' => isset($row['default']) ? $row['default'] : '']); } $setting = $settingsTable->patchEntity($setting, $data); $settingsTable->save($setting); } //TODO: Maybe chared method for settings save $settings = $settingsTable->find()->combine('path', 'value')->toArray(); ksort($settings); $settings = Hash::expand($settings); Settings::dump('config', 'default', $settings); }
/** * Load a config file containing templates. * * Template files should define a `$config` variable containing * all the templates to load. Loaded templates will be merged with existing * templates. * * @param string $file The file to load * @return void */ public function load($file) { $loader = new PhpConfig(); $templates = $loader->read($file); $this->add($templates); }
/** * Initialize method * * @param Component $Component Component instance * @return void */ public function initialize(Component $Component) { $adapter = $Component->config('adapter'); if (is_array($adapter)) { $this->options = $adapter + $this->options; } $engine = new PhpConfig(dirname($this->options['config']) . DS); $config = $engine->read(basename($this->options['config'])); $this->build($config); $Component->Aco = $this->Aco; $Component->Aro = $this->Aro; }
/** * Test that dump() makes files read() can read. * * @return void */ public function testDumpRead() { $engine = new PhpConfig(TMP); $engine->dump('test', $this->testData); $result = $engine->read('test'); unlink(TMP . 'test.php'); $this->assertEquals($this->testData, $result); }
/** * Load a config file containing widgets. * * Widget files should define a `$config` variable containing * all the widgets to load. Loaded widgets will be merged with existing * widgets. * * @param string $file The file to load * @return void */ public function load($file) { $loader = new PhpConfig(); $widgets = $loader->read($file); $this->add($widgets); }
/** * Load a config file containing editor options. * * @param string $file The file to load * @return void */ public function loadConfig($file) { $options = []; try { $loader = new PhpConfig(); $options = $loader->read($file); } catch (\Exception $e) { Log::warning($e->getMessage()); } $this->config('options', $options); }