From 176dff3b70fe5ed8d7f012354e290c1bf4c7531e Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 22 Oct 2015 21:13:15 +0200 Subject: [PATCH] renaming config file to make updates easier, resolving #50 --- INSTALL.md | 6 ++++-- cfg/{conf.ini => conf.ini.sample} | 0 lib/configuration.php | 13 +++++++++---- tst/configuration.php | 7 +++++++ 4 files changed, 20 insertions(+), 6 deletions(-) rename cfg/{conf.ini => conf.ini.sample} (100%) diff --git a/INSTALL.md b/INSTALL.md index caca1cfd..3da4c6f8 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -16,8 +16,10 @@ and extract it in your web hosts folder were you want to install your ZeroBin in ### Configuration -In the file `cfg/conf.ini` you can configure ZeroBin. The config file is divided -into multiple sections, which are enclosed in square brackets. +In the file `cfg/conf.ini` you can configure ZeroBin. A `cfg/conf.ini.sample` +is provided containing all options on default values. You can copy it to +`cfg/conf.ini` and adapt it as needed. The config file is divided into multiple +sections, which are enclosed in square brackets. In the `[main]` section you can enable or disable the discussion feature, set the limit of stored pastes and comments in bytes. The `[traffic]` section lets you diff --git a/cfg/conf.ini b/cfg/conf.ini.sample similarity index 100% rename from cfg/conf.ini rename to cfg/conf.ini.sample diff --git a/lib/configuration.php b/lib/configuration.php index 2549eb1b..da2dd4b3 100644 --- a/lib/configuration.php +++ b/lib/configuration.php @@ -84,10 +84,15 @@ class configuration */ public function __construct() { - $config = parse_ini_file(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', true); - foreach (array('main', 'model') as $section) { - if (!array_key_exists($section, $config)) { - throw new Exception(i18n::_('ZeroBin requires configuration section [%s] to be present in configuration file.', $section), 2); + $config = array(); + $configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'; + if (is_readable($configFile)) + { + $config = parse_ini_file($configFile, true); + foreach (array('main', 'model') as $section) { + if (!array_key_exists($section, $config)) { + throw new Exception(i18n::_('ZeroBin requires configuration section [%s] to be present in configuration file.', $section), 2); + } } } foreach ($this->_defaults as $section => $values) diff --git a/tst/configuration.php b/tst/configuration.php index 61442dfd..13e3b0b2 100644 --- a/tst/configuration.php +++ b/tst/configuration.php @@ -75,6 +75,13 @@ class configurationTest extends PHPUnit_Framework_TestCase $this->assertEquals($this->_options, $conf->get(), 'newly generated configuration is correct'); } + public function testHandleMissingConfigFile() + { + @unlink(CONF); + $conf = new configuration; + $this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on missing file'); + } + /** * @expectedException Exception * @expectedExceptionCode 2