<?php
+use Shaarli\Config\ConfigJson;
+use Shaarli\Config\ConfigPhp;
/**
* Class Updater.
<?php
-
namespace Shaarli\Api;
use Shaarli\Api\Exceptions\ApiException;
use Shaarli\Api\Exceptions\ApiAuthorizationException;
+
use Slim\Container;
use Slim\Http\Request;
use Slim\Http\Response;
<?php
+namespace Shaarli\Config;
/**
* Interface ConfigIO
<?php
+namespace Shaarli\Config;
/**
* Class ConfigJson (ConfigIO implementation)
$data = json_decode($data, true);
if ($data === null) {
$error = json_last_error();
- throw new Exception('An error occurred while parsing JSON file: error code #'. $error);
+ throw new \Exception('An error occurred while parsing JSON file: error code #'. $error);
}
return $data;
}
$print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
$data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix();
if (!file_put_contents($filepath, $data)) {
- throw new IOException(
+ throw new \IOException(
$filepath,
'Shaarli could not create the config file.
Please make sure Shaarli has the right to write in the folder is it installed in.'
<?php
-
-// FIXME! Namespaces...
-require_once 'ConfigIO.php';
-require_once 'ConfigJson.php';
-require_once 'ConfigPhp.php';
+namespace Shaarli\Config;
/**
* Class ConfigManager
* @param bool $write Write the new setting in the config file, default false.
* @param bool $isLoggedIn User login state, default false.
*
- * @throws Exception Invalid
+ * @throws \Exception Invalid
*/
public function set($setting, $value, $write = false, $isLoggedIn = false)
{
if (empty($setting) || ! is_string($setting)) {
- throw new Exception('Invalid setting key parameter. String expected, got: '. gettype($setting));
+ throw new \Exception('Invalid setting key parameter. String expected, got: '. gettype($setting));
}
// During the ConfigIO transition, map legacy settings to the new ones.
*
* @throws MissingFieldConfigException: a mandatory field has not been provided in $conf.
* @throws UnauthorizedConfigException: user is not authorize to change configuration.
- * @throws IOException: an error occurred while writing the new config file.
+ * @throws \IOException: an error occurred while writing the new config file.
*/
public function write($isLoggedIn)
{
/**
* Exception used if a mandatory field is missing in given configuration.
*/
-class MissingFieldConfigException extends Exception
+class MissingFieldConfigException extends \Exception
{
public $field;
/**
* Exception used if an unauthorized attempt to edit configuration has been made.
*/
-class UnauthorizedConfigException extends Exception
+class UnauthorizedConfigException extends \Exception
{
/**
* Construct exception.
<?php
+namespace Shaarli\Config;
/**
* Class ConfigPhp (ConfigIO implementation)
if (!file_put_contents($filepath, $configStr)
|| strcmp(file_get_contents($filepath), $configStr) != 0
) {
- throw new IOException(
+ throw new \IOException(
$filepath,
'Shaarli could not create the config file.
Please make sure Shaarli has the right to write in the folder is it installed in.'
<?php
+namespace Shaarli\Config;
+
/**
* Plugin configuration helper functions.
*
/**
* Exception used if an error occur while saving plugin configuration.
*/
-class PluginConfigOrderException extends Exception
+class PluginConfigOrderException extends \Exception
{
/**
* Construct exception.
"Shaarli\\": "application",
"Shaarli\\Api\\": "application/api/",
"Shaarli\\Api\\Controllers\\": "application/api/controllers",
- "Shaarli\\Api\\Exceptions\\": "application/api/exceptions"
+ "Shaarli\\Api\\Exceptions\\": "application/api/exceptions",
+ "Shaarli\\Config\\": "application/config/"
}
}
}
require_once 'application/ApplicationUtils.php';
require_once 'application/Cache.php';
require_once 'application/CachedPage.php';
-require_once 'application/config/ConfigManager.php';
-require_once 'application/config/ConfigPlugin.php';
require_once 'application/FeedBuilder.php';
require_once 'application/FileUtils.php';
require_once 'application/HttpUtils.php';
require_once 'application/Router.php';
require_once 'application/Updater.php';
use \Shaarli\ThemeUtils;
+use \Shaarli\Config\ConfigManager;
// Ensure the PHP version is supported
try {
<?php
+use Shaarli\Config\ConfigManager;
+
/**
* ApplicationUtils' tests
*/
-require_once 'application/config/ConfigManager.php';
require_once 'application/ApplicationUtils.php';
/**
<?php
+use Shaarli\Config\ConfigManager;
/**
* Plugin Manager tests
<?php
+use Shaarli\Config\ConfigJson;
+use Shaarli\Config\ConfigManager;
+use Shaarli\Config\ConfigPhp;
-require_once 'application/config/ConfigManager.php';
require_once 'tests/Updater/DummyUpdater.php';
require_once 'inc/rain.tpl.class.php';
<?php
-
namespace Shaarli\Api;
+use Shaarli\Config\ConfigManager;
+
use Slim\Container;
use Slim\Http\Environment;
use Slim\Http\Request;
*/
public function setUp()
{
- $this->conf = new \ConfigManager('tests/utils/config/configJson.json.php');
+ $this->conf = new ConfigManager('tests/utils/config/configJson.json.php');
$this->conf->set('api.secret', 'NapoleonWasALizard');
$this->refDB = new \ReferenceLinkDB();
namespace Shaarli\Api\Controllers;
+use Shaarli\Config\ConfigManager;
use Slim\Container;
use Slim\Http\Environment;
protected static $testDatastore = 'sandbox/datastore.php';
/**
- * @var \ConfigManager instance
+ * @var ConfigManager instance
*/
protected $conf;
*/
public function setUp()
{
- $this->conf = new \ConfigManager('tests/utils/config/configJson');
+ $this->conf = new ConfigManager('tests/utils/config/configJson');
$this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore);
<?php
-
namespace Shaarli\Api\Controllers;
+use Shaarli\Config\ConfigManager;
use Slim\Container;
use Slim\Http\Environment;
protected static $testDatastore = 'sandbox/datastore.php';
/**
- * @var \ConfigManager instance
+ * @var ConfigManager instance
*/
protected $conf;
*/
public function setUp()
{
- $this->conf = new \ConfigManager('tests/utils/config/configJson');
+ $this->conf = new ConfigManager('tests/utils/config/configJson');
$this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore);
<?php
-
namespace Shaarli\Api\Controllers;
+use Shaarli\Config\ConfigManager;
+
use Slim\Container;
use Slim\Http\Environment;
use Slim\Http\Request;
protected static $testDatastore = 'sandbox/datastore.php';
/**
- * @var \ConfigManager instance
+ * @var ConfigManager instance
*/
protected $conf;
*/
public function setUp()
{
- $this->conf = new \ConfigManager('tests/utils/config/configJson.json.php');
+ $this->conf = new ConfigManager('tests/utils/config/configJson.json.php');
$this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore);
$this->assertEquals('Shaarli', $data['settings']['title']);
$this->assertEquals('?', $data['settings']['header_link']);
$this->assertEquals('UTC', $data['settings']['timezone']);
- $this->assertEquals(\ConfigManager::$DEFAULT_PLUGINS, $data['settings']['enabled_plugins']);
+ $this->assertEquals(ConfigManager::$DEFAULT_PLUGINS, $data['settings']['enabled_plugins']);
$this->assertEquals(false, $data['settings']['default_private_links']);
$title = 'My links';
<?php
-
-require_once 'application/config/ConfigJson.php';
+namespace Shaarli\Config;
/**
* Class ConfigJsonTest
*/
-class ConfigJsonTest extends PHPUnit_Framework_TestCase
+class ConfigJsonTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ConfigJson
/**
* Read a non existent config file -> empty array.
*
- * @expectedException Exception
+ * @expectedException \Exception
* @expectedExceptionMessage An error occurred while parsing JSON file: error code #4
*/
public function testReadInvalidJson()
/**
* Write to invalid path.
*
- * @expectedException IOException
+ * @expectedException \IOException
*/
public function testWriteInvalidArray()
{
/**
* Write to invalid path.
*
- * @expectedException IOException
+ * @expectedException \IOException
*/
public function testWriteInvalidBlank()
{
<?php
+namespace Shaarli\Config;
/**
* Unit tests for Class ConfigManagerTest
* Note: it only test the manager with ConfigJson,
* ConfigPhp is only a workaround to handle the transition to JSON type.
*/
-class ConfigManagerTest extends PHPUnit_Framework_TestCase
+class ConfigManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ConfigManager
/**
* Set with an empty key.
*
- * @expectedException Exception
+ * @expectedException \Exception
* @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
*/
public function testSetEmptyKey()
/**
* Set with an array key.
*
- * @expectedException Exception
+ * @expectedException \Exception
* @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
*/
public function testSetArrayKey()
/**
* Try to write the config without mandatory parameter (e.g. 'login').
*
- * @expectedException MissingFieldConfigException
+ * @expectedException Shaarli\Config\MissingFieldConfigException
*/
public function testWriteMissingParameter()
{
<?php
-
-require_once 'application/config/ConfigPhp.php';
+namespace Shaarli\Config;
/**
* Class ConfigPhpTest
*/
-class ConfigPhpTest extends PHPUnit_Framework_TestCase
+class ConfigPhpTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ConfigPhp
<?php
+namespace Shaarli\Config;
+
/**
* Config' tests
*/
/**
* Unitary tests for Shaarli config related functions
*/
-class ConfigPluginTest extends PHPUnit_Framework_TestCase
+class ConfigPluginTest extends \PHPUnit_Framework_TestCase
{
/**
* Test save_plugin_config with valid data.
/**
* Test save_plugin_config with invalid data.
*
- * @expectedException PluginConfigOrderException
+ * @expectedException Shaarli\Config\PluginConfigOrderException
*/
public function testSavePluginConfigInvalid()
{
<?php
+use Shaarli\Config\ConfigManager;
require_once 'plugins/isso/isso.php';
<?php
+use Shaarli\Config\ConfigManager;
/**
* PluginMarkdownTest.php
<?php
+use Shaarli\Config\ConfigManager;
require_once 'plugins/pubsubhubbub/pubsubhubbub.php';
require_once 'application/Router.php';
<?php
-
/**
* PluginQrcodeTest.php
*/
<?php
+use Shaarli\Config\ConfigManager;
/**
* PluginReadityourselfTest.php.php
<?php
+use Shaarli\Config\ConfigManager;
/**
* PluginWallabagTest.php.php