Initial commit

This commit is contained in:
root
2026-01-04 22:05:37 -05:00
committed by Sebastian Krupinski
commit 4f979ced22
57 changed files with 11076 additions and 0 deletions

View File

@@ -0,0 +1,153 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderJmapc\Providers;
use KTXF\Resource\Provider\ResourceServiceLocationUri;
/**
* JMAP Service Location
*
* Connection details for JMAP server.
*/
class ServiceLocation implements ResourceServiceLocationUri
{
public function __construct(
private string $host = '',
private int $port = 443,
private string $scheme = 'https',
private string $path = '/.well-known/jmap',
private bool $verifyPeer = true,
private bool $verifyHost = true,
) {
$testing = 'test';
}
public function toStore(): array
{
return $this->jsonSerialize();
}
public function fromStore(array $data): static
{
return $this->jsonDeserialize($data);
}
public function jsonSerialize(): array
{
return array_filter([
'type' => self::TYPE_URI,
'host' => $this->host ?? '',
'port' => $this->port ?? 443,
'scheme' => $this->scheme,
'path' => $this->path,
'verifyPeer' => $this->verifyPeer,
'verifyHost' => $this->verifyHost,
], fn($v) => $v !== null && $v !== '');
}
public function jsonDeserialize(array|string $data): static
{
if (is_string($data)) {
$data = json_decode($data, true);
}
$this->host = $data['host'] ?? '';
$this->port = (int)($data['port'] ?? 443);
$this->scheme = $data['scheme'] ?? 'https';
$this->path = $data['path'] ?? '';
$this->verifyPeer = $data['verifyPeer'] ?? true;
$this->verifyHost = $data['verifyHost'] ?? true;
return $this;
}
public function type(): string
{
return self::TYPE_URI;
}
public function location(): string
{
$uri = $this->scheme . '://' . $this->host;
// Add port if not default for scheme
if (($this->scheme === 'https' && $this->port !== 443) ||
($this->scheme === 'http' && $this->port !== 80)) {
$uri .= ':' . $this->port;
}
// Add path if present
if ($this->path !== '') {
$uri .= '/' . ltrim($this->path, '/');
}
return $uri;
}
public function getScheme(): string
{
return $this->scheme;
}
public function setScheme(string $value): void
{
$this->scheme = $value;
}
public function getHost(): string
{
return $this->host;
}
public function setHost(string $value): void
{
$this->host = $value;
}
public function getPort(): int
{
return $this->port;
}
public function setPort(int $value): void
{
$this->port = $value;
}
public function getPath(): string
{
return $this->path;
}
public function setPath(string $value): void
{
$this->path = $value;
}
public function getVerifyPeer(): bool
{
return $this->verifyPeer;
}
public function setVerifyPeer(bool $value): void
{
$this->verifyPeer = $value;
}
public function getVerifyHost(): bool
{
return $this->verifyHost;
}
public function setVerifyHost(bool $value): void
{
$this->verifyHost = $value;
}
}