|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of dimtrovich/db-dumper". |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2024 Dimitri Sitchet Tomkeu <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Dimtrovich\DbDumper\Exceptions; |
|
13
|
|
|
|
|
14
|
|
|
use Exception as BaseException; |
|
15
|
|
|
|
|
16
|
|
|
class Exception extends BaseException |
|
17
|
|
|
{ |
|
18
|
|
|
public const COMPRESSOR_DRIVER_MISSING = 301; |
|
19
|
|
|
public const COMPRESSOR_INVALID = 302; |
|
20
|
|
|
public const COMPRESSOR_DRIVER_UNAVAILABLE = 303; |
|
21
|
|
|
public const DATABASE_INVALID_ADAPTER = 401; |
|
22
|
|
|
public const DATABASE_TABLE_NOT_FOUND = 402; |
|
23
|
|
|
public const FILE_FAILL_TO_READ = 501; |
|
24
|
|
|
public const FILE_FAILL_TO_WRITE = 502; |
|
25
|
|
|
public const FILE_NOT_WRITABLE = 503; |
|
26
|
|
|
public const PDO_EXCEPTION = 1601; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Error meta informations |
|
30
|
|
|
*/ |
|
31
|
|
|
private array $meta = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get exception meta informations |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getMeta(): array |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->meta; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public static function invalidCompressor(string $compressor): self |
|
42
|
|
|
{ |
|
43
|
|
|
return new self(sprintf('Compression method "%s" is not defined yet', $compressor), self::COMPRESSOR_INVALID); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function compressionDriverMissing(string $driver): self |
|
47
|
|
|
{ |
|
48
|
|
|
return new self(sprintf('Compression is enabled, but "%s" lib is not installed or configured properly', $driver), self::COMPRESSOR_DRIVER_MISSING); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function unavailableDriverForcompression(string $extension): self |
|
52
|
|
|
{ |
|
53
|
|
|
return new self(sprintf('No driver found for "%s" extension', $extension), self::COMPRESSOR_DRIVER_UNAVAILABLE); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public static function fileNotWritable(string $filename): self |
|
57
|
|
|
{ |
|
58
|
|
|
return new self(sprintf('File "%s" is not writable.', $filename), self::FILE_NOT_WRITABLE); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public static function failledToWrite(): self |
|
62
|
|
|
{ |
|
63
|
|
|
return new self('Writting to file failed! Probably, there is no more free space left?', self::FILE_FAILL_TO_WRITE); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public static function failledToRead($filename): self |
|
67
|
|
|
{ |
|
68
|
|
|
return new self(sprintf('Couldn\'t open backup file %s', $filename), self::FILE_FAILL_TO_READ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public static function tableNotFound(string $table): self |
|
72
|
|
|
{ |
|
73
|
|
|
return new self(sprintf('Table "%s not found in database', $table), self::DATABASE_TABLE_NOT_FOUND); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public static function invalidAdapter(string $adapter): self |
|
77
|
|
|
{ |
|
78
|
|
|
return new self(sprintf('Database type support for "%s" not yet available', $adapter), self::DATABASE_INVALID_ADAPTER); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public static function pdoException(string $message, string $sql): self |
|
82
|
|
|
{ |
|
83
|
|
|
$message = trim($message); |
|
84
|
|
|
$sql = trim($sql); |
|
85
|
|
|
|
|
86
|
|
|
$exception = new self(sprintf('Error during request "%s" execution. Error: "%s"', $sql, $message), self::PDO_EXCEPTION); |
|
87
|
|
|
$exception->meta = compact('message', 'sql'); |
|
88
|
|
|
|
|
89
|
|
|
return $exception; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|