namespacing: \Shaarli\Exceptions\IOException

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
This commit is contained in:
VirtualTam 2018-12-02 23:31:40 +01:00
parent bdc5152d48
commit f3d2f25794
11 changed files with 24 additions and 10 deletions

View File

@ -1,5 +1,7 @@
<?php <?php
use Shaarli\Exceptions\IOException;
require_once 'exceptions/IOException.php'; require_once 'exceptions/IOException.php';
/** /**

View File

@ -1,4 +1,7 @@
<?php <?php
use Shaarli\Exceptions\IOException;
/** /**
* Data storage for links. * Data storage for links.
* *

View File

@ -2,6 +2,7 @@
use Shaarli\Config\ConfigJson; use Shaarli\Config\ConfigJson;
use Shaarli\Config\ConfigPhp; use Shaarli\Config\ConfigPhp;
use Shaarli\Config\ConfigManager; use Shaarli\Config\ConfigManager;
use Shaarli\Exceptions\IOException;
use Shaarli\Thumbnailer; use Shaarli\Thumbnailer;
/** /**

View File

@ -47,7 +47,7 @@ class ConfigJson implements ConfigIO
$print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
$data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix();
if (!file_put_contents($filepath, $data)) { if (!file_put_contents($filepath, $data)) {
throw new \IOException( throw new \Shaarli\Exceptions\IOException(
$filepath, $filepath,
t('Shaarli could not create the config file. '. t('Shaarli could not create the config file. '.
'Please make sure Shaarli has the right to write in the folder is it installed in.') 'Please make sure Shaarli has the right to write in the folder is it installed in.')

View File

@ -207,7 +207,7 @@ class ConfigManager
* *
* @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf.
* @throws UnauthorizedConfigException: user is not authorize to change configuration. * @throws UnauthorizedConfigException: user is not authorize to change configuration.
* @throws \IOException: an error occurred while writing the new config file. * @throws \Shaarli\Exceptions\IOException: an error occurred while writing the new config file.
*/ */
public function write($isLoggedIn) public function write($isLoggedIn)
{ {

View File

@ -124,7 +124,7 @@ class ConfigPhp implements ConfigIO
if (!file_put_contents($filepath, $configStr) if (!file_put_contents($filepath, $configStr)
|| strcmp(file_get_contents($filepath), $configStr) != 0 || strcmp(file_get_contents($filepath), $configStr) != 0
) { ) {
throw new \IOException( throw new \Shaarli\Exceptions\IOException(
$filepath, $filepath,
t('Shaarli could not create the config file. '. t('Shaarli could not create the config file. '.
'Please make sure Shaarli has the right to write in the folder is it installed in.') 'Please make sure Shaarli has the right to write in the folder is it installed in.')

View File

@ -1,4 +1,7 @@
<?php <?php
namespace Shaarli\Exceptions;
use Exception;
/** /**
* Exception class thrown when a filesystem access failure happens * Exception class thrown when a filesystem access failure happens
@ -17,6 +20,6 @@ class IOException extends Exception
{ {
$this->path = $path; $this->path = $path;
$this->message = empty($message) ? t('Error accessing') : $message; $this->message = empty($message) ? t('Error accessing') : $message;
$this->message .= ' "' . $this->path .'"'; $this->message .= ' "' . $this->path . '"';
} }
} }

View File

@ -36,6 +36,7 @@
"Shaarli\\Api\\Exceptions\\": "application/api/exceptions", "Shaarli\\Api\\Exceptions\\": "application/api/exceptions",
"Shaarli\\Config\\": "application/config/", "Shaarli\\Config\\": "application/config/",
"Shaarli\\Config\\Exception\\": "application/config/exception", "Shaarli\\Config\\Exception\\": "application/config/exception",
"Shaarli\\Exceptions\\": "application/exceptions",
"Shaarli\\Security\\": "application/security" "Shaarli\\Security\\": "application/security"
} }
} }

View File

@ -1,5 +1,7 @@
<?php <?php
use Shaarli\Exceptions\IOException;
require_once 'application/FileUtils.php'; require_once 'application/FileUtils.php';
/** /**
@ -48,7 +50,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
/** /**
* File not writable: raise an exception. * File not writable: raise an exception.
* *
* @expectedException IOException * @expectedException Shaarli\Exceptions\IOException
* @expectedExceptionMessage Error accessing "sandbox/flat.db" * @expectedExceptionMessage Error accessing "sandbox/flat.db"
*/ */
public function testWriteWithoutPermission() public function testWriteWithoutPermission()
@ -61,7 +63,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
/** /**
* Folder non existent: raise an exception. * Folder non existent: raise an exception.
* *
* @expectedException IOException * @expectedException Shaarli\Exceptions\IOException
* @expectedExceptionMessage Error accessing "nopefolder" * @expectedExceptionMessage Error accessing "nopefolder"
*/ */
public function testWriteFolderDoesNotExist() public function testWriteFolderDoesNotExist()
@ -72,7 +74,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
/** /**
* Folder non writable: raise an exception. * Folder non writable: raise an exception.
* *
* @expectedException IOException * @expectedException Shaarli\Exceptions\IOException
* @expectedExceptionMessage Error accessing "sandbox" * @expectedExceptionMessage Error accessing "sandbox"
*/ */
public function testWriteFolderPermission() public function testWriteFolderPermission()

View File

@ -3,6 +3,8 @@
* Link datastore tests * Link datastore tests
*/ */
use Shaarli\Exceptions\IOException;
require_once 'application/Cache.php'; require_once 'application/Cache.php';
require_once 'application/FileUtils.php'; require_once 'application/FileUtils.php';
require_once 'application/LinkDB.php'; require_once 'application/LinkDB.php';
@ -100,7 +102,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
/** /**
* Attempt to instantiate a LinkDB whereas the datastore is not writable * Attempt to instantiate a LinkDB whereas the datastore is not writable
* *
* @expectedException IOException * @expectedException Shaarli\Exceptions\IOException
* @expectedExceptionMessageRegExp /Error accessing "null"/ * @expectedExceptionMessageRegExp /Error accessing "null"/
*/ */
public function testConstructDatastoreNotWriteable() public function testConstructDatastoreNotWriteable()

View File

@ -111,7 +111,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase
/** /**
* Write to invalid path. * Write to invalid path.
* *
* @expectedException \IOException * @expectedException \Shaarli\Exceptions\IOException
*/ */
public function testWriteInvalidArray() public function testWriteInvalidArray()
{ {
@ -122,7 +122,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase
/** /**
* Write to invalid path. * Write to invalid path.
* *
* @expectedException \IOException * @expectedException \Shaarli\Exceptions\IOException
*/ */
public function testWriteInvalidBlank() public function testWriteInvalidBlank()
{ {