Skip to content

Commit 19a370c

Browse files
committed
Replace Service classes with Resolver pattern
1 parent aaa8df0 commit 19a370c

6 files changed

Lines changed: 114 additions & 39 deletions

File tree

src/Resolver.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Utopia\Proxy;
4+
5+
use Utopia\Proxy\Resolver\Exception;
6+
use Utopia\Proxy\Resolver\Result;
7+
8+
/**
9+
* Backend Resolver Interface
10+
*
11+
* Platform-agnostic interface for resolving resource identifiers to backend endpoints.
12+
* Implement this interface to integrate your platform with the proxy.
13+
*/
14+
interface Resolver
15+
{
16+
/**
17+
* Resolve a resource identifier to a backend endpoint
18+
*
19+
* @param string $resourceId Protocol-specific identifier (database ID, hostname, etc.)
20+
* @return Result Backend endpoint and metadata
21+
*
22+
* @throws Exception If resource not found or unavailable
23+
*/
24+
public function resolve(string $resourceId): Result;
25+
26+
/**
27+
* Called when a new connection is established
28+
*
29+
* @param string $resourceId The resource identifier
30+
* @param array<string, mixed> $metadata Additional connection metadata
31+
*/
32+
public function onConnect(string $resourceId, array $metadata = []): void;
33+
34+
/**
35+
* Called when a connection is closed
36+
*
37+
* @param string $resourceId The resource identifier
38+
* @param array<string, mixed> $metadata Additional disconnection metadata
39+
*/
40+
public function onDisconnect(string $resourceId, array $metadata = []): void;
41+
42+
/**
43+
* Track activity for a resource
44+
*
45+
* @param string $resourceId The resource identifier
46+
* @param array<string, mixed> $metadata Activity metadata
47+
*/
48+
public function trackActivity(string $resourceId, array $metadata = []): void;
49+
50+
/**
51+
* Invalidate cached resolution data for a resource
52+
*
53+
* @param string $resourceId The resource identifier
54+
*/
55+
public function invalidateCache(string $resourceId): void;
56+
57+
/**
58+
* Get resolver statistics
59+
*
60+
* @return array<string, mixed> Statistics data
61+
*/
62+
public function getStats(): array;
63+
}

src/Resolver/Exception.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Utopia\Proxy\Resolver;
4+
5+
/**
6+
* Exception thrown during resolution
7+
*/
8+
class Exception extends \Exception
9+
{
10+
public const NOT_FOUND = 404;
11+
12+
public const UNAVAILABLE = 503;
13+
14+
public const TIMEOUT = 504;
15+
16+
public const FORBIDDEN = 403;
17+
18+
public const INTERNAL = 500;
19+
20+
/**
21+
* @param array<string, mixed> $context
22+
*/
23+
public function __construct(
24+
string $message,
25+
int $code = self::INTERNAL,
26+
public readonly array $context = []
27+
) {
28+
parent::__construct($message, $code);
29+
}
30+
}

src/Resolver/Result.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Utopia\Proxy\Resolver;
4+
5+
/**
6+
* Result of resource resolution
7+
*/
8+
class Result
9+
{
10+
/**
11+
* @param string $endpoint Backend endpoint in format "host:port"
12+
* @param array<string, mixed> $metadata Optional metadata about the resolved backend
13+
* @param int|null $timeout Optional connection timeout override in seconds
14+
*/
15+
public function __construct(
16+
public readonly string $endpoint,
17+
public readonly array $metadata = [],
18+
public readonly ?int $timeout = null
19+
) {
20+
}
21+
}

src/Service/HTTP.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Service/SMTP.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Service/TCP.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)