You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-12Lines changed: 36 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,17 +48,23 @@ The protocol-proxy uses the **Adapter Pattern** - similar to [utopia-php/databas
48
48
<?php
49
49
require 'vendor/autoload.php';
50
50
51
-
use Utopia\Proxy\Adapter\HTTP;
51
+
use Utopia\Platform\Action;
52
+
use Utopia\Proxy\Adapter\HTTP\Swoole as HTTPAdapter;
53
+
use Utopia\Proxy\Server\HTTP\Swoole as HTTPServer;
54
+
use Utopia\Proxy\Service\HTTP as HTTPService;
52
55
53
-
$adapter = new HTTP($cache, $dbPool);
56
+
$adapter = new HTTPAdapter();
57
+
$service = $adapter->getService() ?? new HTTPService();
54
58
55
59
// Required: Provide backend resolution logic
56
-
$adapter->hook('resolve', function (string $hostname) {
57
-
// Your resolution logic here (database, K8s, config, etc.)
58
-
return $backend->getEndpoint($hostname);
59
-
});
60
+
$service->addAction('resolve', (new class extends Action {})
61
+
->callback(function (string $hostname) use ($backend): string {
62
+
return $backend->getEndpoint($hostname);
63
+
}));
60
64
61
-
$server = new HttpServer(
65
+
$adapter->setService($service);
66
+
67
+
$server = new HTTPServer(
62
68
host: '0.0.0.0',
63
69
port: 80,
64
70
workers: swoole_cpu_num() * 2,
@@ -74,9 +80,9 @@ $server->start();
74
80
<?php
75
81
require 'vendor/autoload.php';
76
82
77
-
use Utopia\Proxy\Tcp\TcpServer;
83
+
use Utopia\Proxy\Server\TCP\Swoole as TCPServer;
78
84
79
-
$server = new TcpServer(
85
+
$server = new TCPServer(
80
86
host: '0.0.0.0',
81
87
ports: [5432, 3306], // PostgreSQL, MySQL
82
88
workers: swoole_cpu_num() * 2
@@ -91,9 +97,9 @@ $server->start();
91
97
<?php
92
98
require 'vendor/autoload.php';
93
99
94
-
use Utopia\Proxy\Smtp\SmtpServer;
100
+
use Utopia\Proxy\Server\SMTP\Swoole as SMTPServer;
95
101
96
-
$server = new SmtpServer(
102
+
$server = new SMTPServer(
97
103
host: '0.0.0.0',
98
104
port: 25,
99
105
workers: swoole_cpu_num() * 2
@@ -120,7 +126,7 @@ $config = [
120
126
// Routing cache
121
127
'cache_ttl' => 1, // 1 second
122
128
123
-
// Database connection (for cache and resolution hooks)
129
+
// Database connection (for cache and resolution actions)
124
130
'db_host' => 'localhost',
125
131
'db_port' => 3306,
126
132
'db_user' => 'appwrite',
@@ -133,6 +139,24 @@ $config = [
133
139
];
134
140
```
135
141
142
+
## ✅ Testing
143
+
144
+
```bash
145
+
composer test
146
+
```
147
+
148
+
Integration tests (Docker Compose):
149
+
150
+
```bash
151
+
composer test:integration
152
+
```
153
+
154
+
Coverage (requires Xdebug or PCOV):
155
+
156
+
```bash
157
+
vendor/bin/phpunit --coverage-text
158
+
```
159
+
136
160
## 🎨 Architecture
137
161
138
162
The protocol-proxy follows the **Adapter Pattern** used throughout utopia-php libraries (Database, Messaging, Storage), providing a clean and extensible architecture for protocol-specific implementations.
0 commit comments