public function register() { $configPath = $this->configPath; $this->di->set('config.debugbar', function () use($configPath) { $base = new Php(__DIR__ . '/config/debugbar.php'); $base['collectors']['phpinfo'] = true; $base['collectors']['time'] = true; $base['collectors']['messages'] = true; if (is_string($configPath) && is_file($configPath)) { $config = new Php($configPath); $base->merge($config); } elseif (is_object($configPath) && $configPath instanceof Php) { $base->merge($configPath); } else { } return $base; }, true); $this->di->set('debugbar', function () { $di = Version::getId() > 2010000 ? $this : $this->di; $debugbar = new PhalconDebugbar($di); $debugbar->setHttpDriver(new PhalconHttpDriver()); return $debugbar; }); $this->setRoute(); return $this; }
public function register() { $configPath = $this->configPath; $this->di->set('config.debugbar', function () use($configPath) { $base = new Php(__DIR__ . '/config/debugbar.php'); $base['collectors']['phpinfo'] = true; $base['collectors']['time'] = true; $base['collectors']['messages'] = true; if (is_string($configPath) && is_file($configPath)) { $extension = strtolower(pathinfo($configPath, PATHINFO_EXTENSION)); switch ($extension) { case 'ini': $config = new Ini($configPath); break; case 'json': $config = new Json($configPath); break; case 'php': case 'php5': case 'inc': $config = new Php($configPath); break; case 'yml': case 'yaml': $config = new Yaml($configPath); break; default: throw new \RuntimeException(sprintf('Config adapter for %s files is not support', $extension)); } $base->merge($config); } elseif (is_object($configPath) && $configPath instanceof Config) { $base->merge($configPath); } else { } return $base; }, true); $this->di->set('debugbar', function () { $di = Version::getId() > 2010000 ? $this : $this->di; $debugbar = new PhalconDebugbar($di); $debugbar->setHttpDriver(new PhalconHttpDriver()); return $debugbar; }); $this->setRoute(); return $this; }
public function saveConfig($arrayConfig) { $filename = ROOT_DIR . 'content/options/options.php'; if (!file_exists($filename)) { $makeFile = ZFunction::makeFile($filename); file_put_contents($filename, "<?php return [];"); } if (file_exists($filename)) { $data = new AdapterPhp($filename); $result = array_merge($data->toArray(), $arrayConfig); $result = '<?php return ' . var_export($result, true) . ';'; if (!file_put_contents($filename, $result)) { return false; } return true; } }
<?php use Phalcon\Mvc\View\Simple as SimpleView; use Phalcon\Di\FactoryDefault; use Phalcon\Config\Adapter\Php as PhpConfig; $di = new FactoryDefault(); $di->set('config', function () { $config = new PhpConfig(__DIR__ . '/app.php'); if (is_readable(__DIR__ . '/app.development.php') && getenv('APPLICATION_ENV') == 'development') { $development = new PhpConfig(__DIR__ . '/app.development.php'); $config->merge($development); } return $config; }, true); $di->set('view', function () use($di) { $config = $di->get('config')['view']; $view = new SimpleView(); $view->setViewsDir($config['dir']); $view->setVar('appConfig', $di->get('config')['app']); $view->setVar('flashSession', $di->get('flashSession')); $engine = new $config['engine']($view); $engine->setOptions([$config['options']]); $view->registerEngines([$config['prefix'] => $engine]); return $view; }, true); $di->set('connection', function () use($di) { $config = $di->get('config')['database']; $adapter = new $config->adapter(["host" => $config->host, "username" => $config->username, "password" => $config->password, "dbname" => $config->db]); return $adapter; }, true);
/** * Make data configuration to file options.php inside directory config * * @return mixed */ public function saveAnalyticAction() { $this->view->disable(); //Is not $_POST if (!$this->request->isPost()) { return $this->currentRedirect(); } $filename = ROOT_DIR . 'common/config/options.php'; if (!file_exists($filename)) { $makeFile = ZFunction::makeFile($filename); } if (file_exists($filename)) { $analytic = ['googleAnalytic' => $this->request->getPost('analytic')]; $data = new AdapterPhp($filename); $result = array_merge($data->toArray(), $analytic); $result = '<?php return ' . var_export($result, true) . ';'; if (!file_put_contents($filename, $result)) { throw new \Exception("Data was not saved", 1); } $this->flashSession->success(t('Data was successfully deleted')); return $this->currentRedirect(); } return $this->currentRedirect(); }
/** * 設定ファイルを丸ごと配列で取得 * @return array */ public function getArray() { return $this->config->toArray(); }