clrghouz/app/Classes/Sock/SocketException.php
2021-06-13 01:31:32 +10:00

28 lines
793 B
PHP

<?php
namespace App\Classes\Sock;
final class SocketException extends \Exception {
public const CANT_CREATE_SOCKET = 1;
public const CANT_BIND_SOCKET = 2;
public const CANT_LISTEN = 3;
public const CANT_ACCEPT = 4;
public const CANT_CONNECT = 5;
private array $messages = [
self::CANT_CREATE_SOCKET => 'Can\'t create socket: "%s"',
self::CANT_BIND_SOCKET => 'Can\'t bind socket: "%s"',
self::CANT_LISTEN => 'Can\'t listen: "%s"',
self::CANT_ACCEPT => 'Can\'t accept connections: "%s"',
self::CANT_CONNECT => 'Can\'t connect: "%s"',
];
public function __construct(int $code,string $params=NULL) {
$message = $params
? call_user_func_array('sprintf',[$this->messages[$code],$params])
: $this->messages[$code];
parent::__construct($message,$code);
}
}