mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
all the types
This commit is contained in:
parent
515b42586e
commit
84fa890ea7
28 changed files with 330 additions and 110 deletions
|
|
@ -7,16 +7,36 @@
|
|||
|
||||
namespace Icewind\SMB\Exception;
|
||||
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @psalm-consistent-constructor
|
||||
*/
|
||||
class Exception extends \Exception {
|
||||
public static function unknown(?string $path, $error) {
|
||||
$message = 'Unknown error (' . $error . ')';
|
||||
public function __construct(string $message = "", int $code = 0, Throwable $previous = null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $path
|
||||
* @param string|int|null $error
|
||||
* @return Exception
|
||||
*/
|
||||
public static function unknown(?string $path, $error): Exception {
|
||||
$message = 'Unknown error (' . (string)$error . ')';
|
||||
if ($path) {
|
||||
$message .= ' for ' . $path;
|
||||
}
|
||||
|
||||
return new Exception($message, is_string($error) ? 0 : $error);
|
||||
return new Exception($message, is_int($error) ? $error : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, class-string<Exception>> $exceptionMap
|
||||
* @param string|int|null $error
|
||||
* @param string|null $path
|
||||
* @return Exception
|
||||
*/
|
||||
public static function fromMap(array $exceptionMap, $error, ?string $path): Exception {
|
||||
if (isset($exceptionMap[$error])) {
|
||||
$exceptionClass = $exceptionMap[$error];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue