44 lines
1,016 B
PHP
44 lines
1,016 B
PHP
|
<?php
|
||
|
// UnixEndPoint.php
|
||
|
// Created: 2021-04-30
|
||
|
// Updated: 2022-02-27
|
||
|
|
||
|
namespace Index\Net;
|
||
|
|
||
|
class UnixEndPoint extends EndPoint {
|
||
|
private string $path;
|
||
|
|
||
|
public function __construct(string $socketPath) {
|
||
|
$this->path = $socketPath;
|
||
|
}
|
||
|
|
||
|
public function getPath(): string {
|
||
|
return $this->path;
|
||
|
}
|
||
|
|
||
|
public function __serialize(): array {
|
||
|
return [$this->path];
|
||
|
}
|
||
|
public function __unserialize(array $serialized): void {
|
||
|
$this->path = $serialized[0];
|
||
|
}
|
||
|
|
||
|
public function equals(mixed $other): bool {
|
||
|
return $other instanceof UnixEndPoint
|
||
|
&& $this->path === $other->path;
|
||
|
}
|
||
|
|
||
|
public static function parse(string $socketPath): UnixEndPoint {
|
||
|
if(str_starts_with($socketPath, 'unix:')) {
|
||
|
$uri = parse_url($socketPath);
|
||
|
$socketPath = $uri['path'] ?? '';
|
||
|
}
|
||
|
|
||
|
return new UnixEndPoint($socketPath);
|
||
|
}
|
||
|
|
||
|
public function __toString(): string {
|
||
|
return $this->path;
|
||
|
}
|
||
|
}
|