Skip to content

Commit 7e00e2b

Browse files
authored
Merge pull request #2 from rtckit/v0.5.2
v0.5.2
2 parents 53794e4 + 42b850c commit 7e00e2b

12 files changed

+181
-84
lines changed

composer.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rtckit/eqivo",
33
"description": "Telephony API Platform",
4-
"version": "0.5.0",
4+
"version": "0.5.2",
55
"keywords": [
66
"telecommunications",
77
"voip",
@@ -31,10 +31,10 @@
3131
"ext-libxml": "*",
3232
"ext-pcre": "*",
3333
"ext-simplexml": "*",
34-
"monolog/monolog": "^2.3",
34+
"monolog/monolog": "^2.5",
3535
"nikic/fast-route": "^1.3",
36-
"ramsey/uuid": "^4.2",
37-
"react/event-loop": "^1.2",
36+
"ramsey/uuid": "^4.3",
37+
"react/event-loop": "^1.3",
3838
"react/http": "^1.6",
3939
"react/promise": "^2.9",
4040
"rtckit/esl": "^0.8",
@@ -46,10 +46,10 @@
4646
},
4747
"require-dev": {
4848
"clue/block-react": "^1.5",
49-
"phpstan/phpstan": "^1.4",
49+
"phpstan/phpstan": "^1.6",
5050
"phpunit/phpunit": "^9.5",
51-
"vimeo/psalm": "^4.20",
52-
"zircote/swagger-php": "^4.2"
51+
"vimeo/psalm": "^4.22",
52+
"zircote/swagger-php": "^4.3"
5353
},
5454
"suggest": {
5555
"ext-pcntl": "Enables daemonization support",
@@ -69,12 +69,16 @@
6969
"bin/eqivo"
7070
],
7171
"config": {
72-
"allow-plugins": false
72+
"allow-plugins": false,
73+
"platform": {
74+
"php": "8.1"
75+
}
7376
},
7477
"scripts": {
7578
"phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src",
7679
"psalm": "php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml --show-info=true",
7780
"phpunit": "php -d memory_limit=-1 ./vendor/bin/phpunit --debug -c ./etc/phpunit.xml.dist",
78-
"coverage": "php -d memory_limit=-1 ./vendor/bin/phpunit --debug -c ./etc/phpunit.xml.dist --coverage-text --coverage-html=reports/coverage"
81+
"coverage": "php -d memory_limit=-1 ./vendor/bin/phpunit --debug -c ./etc/phpunit.xml.dist --coverage-text --coverage-html=reports/coverage",
82+
"dev-docker": "docker build -f ./etc/Dockerfile.dev -t rtckit/eqivo ."
7983
}
8084
}

etc/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.1.4-cli-bullseye
1+
FROM php:8.1.5-cli-bullseye
22

33
RUN docker-php-ext-install pcntl
44

etc/Dockerfile.dev

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM php:8.1.5-cli-bullseye
2+
3+
RUN docker-php-ext-install pcntl
4+
5+
WORKDIR /opt/eqivo
6+
7+
COPY composer.json .
8+
9+
RUN apt-get update && apt-get install -y unzip && \
10+
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
11+
composer install --no-dev
12+
13+
COPY . .
14+
15+
ENTRYPOINT ["/opt/eqivo/bin/eqivo"]

src/Config/CliArguments.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,21 @@ function (string $value): bool {
253253
}
254254

255255
if (isset($args['outbound-advertised-address']) && is_string($args['outbound-advertised-address'])) {
256-
$err = Set::parseSocketAddr($args['outbound-advertised-address'], $ip, $port);
257-
258-
if ($err) {
259-
fwrite(STDERR, 'Malformed --outbound-advertised-address argument: ip:port required' . PHP_EOL);
260-
fwrite(STDERR, $err . PHP_EOL);
256+
if ($args['outbound-advertised-address'] === Set::INBOUND_SOCKET_ADDRESS) {
257+
$config->outboundServerAdvertisedIp = Set::INBOUND_SOCKET_ADDRESS;
261258
} else {
262-
assert(!is_null($ip));
263-
assert(!is_null($port));
259+
$err = Set::parseSocketAddr($args['outbound-advertised-address'], $ip, $port);
260+
261+
if ($err) {
262+
fwrite(STDERR, 'Malformed --outbound-advertised-address argument: ip:port or `inbound_socket_address` required' . PHP_EOL);
263+
fwrite(STDERR, $err . PHP_EOL);
264+
} else {
265+
assert(!is_null($ip));
266+
assert(!is_null($port));
264267

265-
$config->outboundServerAdvertisedIp = $ip;
266-
$config->outboundServerAdvertisedPort = $port;
268+
$config->outboundServerAdvertisedIp = $ip;
269+
$config->outboundServerAdvertisedPort = $port;
270+
}
267271
}
268272
}
269273

src/Config/ConfigFile.php

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88

99
use Monolog\Logger;
1010
use Symfony\Component\Yaml\Yaml;
11+
use Closure;
1112
use InvalidArgumentException;
1213

14+
/**
15+
* @phpstan-import-type Level from \Monolog\Logger
16+
*/
1317
class ConfigFile implements ResolverInterface
1418
{
1519
public function resolve(Set $config): void
@@ -62,33 +66,36 @@ public function resolve(Set $config): void
6266
}
6367
}
6468

65-
if (isset($input['userName'])) {
69+
if (isset($input['userName']) && is_string($input['userName'])) {
6670
$config->userName = trim($input['userName']);
6771
}
6872

69-
if (isset($input['groupName'])) {
73+
if (isset($input['groupName']) && is_string($input['groupName'])) {
7074
$config->groupName = trim($input['groupName']);
7175
}
7276

73-
if (isset($input['appPrefix'])) {
77+
if (isset($input['appPrefix']) && is_string($input['appPrefix'])) {
7478
$config->appPrefix = trim($input['appPrefix']);
7579
}
7680

77-
if (isset($input['pidFile'])) {
81+
if (isset($input['pidFile']) && is_string($input['pidFile'])) {
7882
$config->pidFile = trim($input['pidFile']);
7983
}
8084

8185
if (isset($input['cores']) && is_array($input['cores'])) {
8286
foreach ($input['cores'] as $coreConfig) {
83-
if (!isset($coreConfig['eslPassword'], $coreConfig['eslHost'], $coreConfig['eslPort'])) {
87+
if (
88+
!is_array($coreConfig) || !isset($coreConfig['eslPassword'], $coreConfig['eslHost'], $coreConfig['eslPort']) ||
89+
!is_string($coreConfig['eslPassword']) || !is_string($coreConfig['eslHost']) || !is_string($coreConfig['eslPort'])
90+
) {
8491
fwrite(STDERR, 'Malformed `cores` parameter entry in configuration file: password, host and port are mandatory' . PHP_EOL);
8592

8693
continue;
8794
}
8895

8996
$core = new Core;
9097

91-
if (isset($coreConfig['eslUser'])) {
98+
if (isset($coreConfig['eslUser']) && is_string($coreConfig['eslUser'])) {
9299
$core->eslUser = $coreConfig['eslUser'];
93100
}
94101

@@ -100,19 +107,19 @@ public function resolve(Set $config): void
100107
}
101108
}
102109

103-
if (isset($input['defaultHttpMethod'])) {
110+
if (isset($input['defaultHttpMethod']) && is_string($input['defaultHttpMethod'])) {
104111
$config->defaultHttpMethod = trim($input['defaultHttpMethod']);
105112
}
106113

107-
if (isset($input['defaultAnswerUrl'])) {
114+
if (isset($input['defaultAnswerUrl']) && is_string($input['defaultAnswerUrl'])) {
108115
if (!filter_var($input['defaultAnswerUrl'], FILTER_VALIDATE_URL)) {
109116
fwrite(STDERR, 'Malformed `defaultAnswerUrl` parameter in configuration file' . PHP_EOL);
110117
} else {
111118
$config->defaultAnswerUrl = $input['defaultAnswerUrl'];
112119
}
113120
}
114121

115-
if (isset($input['defaultHangupUrl'])) {
122+
if (isset($input['defaultHangupUrl']) && is_string($input['defaultHangupUrl'])) {
116123
if (!filter_var($input['defaultHangupUrl'], FILTER_VALIDATE_URL)) {
117124
fwrite(STDERR, 'Malformed `defaultHangupUrl` parameter in configuration file' . PHP_EOL);
118125
} else {
@@ -121,12 +128,18 @@ public function resolve(Set $config): void
121128
}
122129

123130
if (isset($input['extraChannelVars']) && is_array($input['extraChannelVars'])) {
124-
$config->extraChannelVars = array_filter(
125-
array_map('trim', $input['extraChannelVars']),
126-
function (string $value): bool {
127-
return strlen($value) > 0;
131+
/* array_map() used to work fine here, but now it breaks the static analysis:
132+
* https://github.com/phpstan/phpstan/issues/4376
133+
*/
134+
foreach ($input['extraChannelVars'] as $var) {
135+
if (is_string($var)) {
136+
$var = trim($var);
137+
138+
if (isset($var[0])) {
139+
$config->extraChannelVars[] = $var;
140+
}
128141
}
129-
);
142+
}
130143
}
131144

132145
if (isset($input['verifyPeer'])) {
@@ -145,25 +158,25 @@ function (string $value): bool {
145158
}
146159
}
147160

148-
if (isset($input['restServerBindIp'])) {
161+
if (isset($input['restServerBindIp']) && is_string($input['restServerBindIp'])) {
149162
if (filter_var($input['restServerBindIp'], FILTER_VALIDATE_IP)) {
150163
$config->restServerBindIp = $input['restServerBindIp'];
151164
} else {
152165
fwrite(STDERR, 'Malformed `restServerBindIp` parameter in configuration file: valid IP address required' . PHP_EOL);
153166
}
154167
}
155168

156-
if (isset($input['restServerBindPort'])) {
169+
if (isset($input['restServerBindPort']) && is_scalar($input['restServerBindPort'])) {
157170
$port = (int)$input['restServerBindPort'];
158171

159172
if (!$port || ($port > 65535)) {
160173
fwrite(STDERR, 'Malformed `restServerBindPort` parameter in configuration file: valid port number required' . PHP_EOL);
161174
} else {
162-
$config->restServerBindPort = $input['restServerBindPort'];
175+
$config->restServerBindPort = $port;
163176
}
164177
}
165178

166-
if (isset($input['restServerAdvertisedHost'])) {
179+
if (isset($input['restServerAdvertisedHost']) && is_string($input['restServerAdvertisedHost'])) {
167180
$config->restServerAdvertisedHost = trim($input['restServerAdvertisedHost']);
168181
}
169182

@@ -185,7 +198,9 @@ function (string $value): bool {
185198

186199
if (isset($input['restServerLogLevel'])) {
187200
try {
188-
$config->restServerLogLevel = Logger::toMonologLevel($input['restServerLogLevel']);
201+
/** @var Level */
202+
$restServerLogLevel = $input['restServerLogLevel'];
203+
$config->restServerLogLevel = Logger::toMonologLevel($restServerLogLevel);
189204
} catch (InvalidArgumentException $e) {
190205
fwrite(STDERR, 'Malformed `restServerLogLevel` parameter in configuration file: ' . $e->getMessage() . PHP_EOL);
191206
}
@@ -203,75 +218,81 @@ function (string $value): bool {
203218
}
204219
}
205220

206-
if (isset($input['restAuthId'])) {
221+
if (isset($input['restAuthId']) && is_string($input['restAuthId'])) {
207222
$config->restAuthId = trim($input['restAuthId']);
208223
}
209224

210-
if (isset($input['restAuthToken'])) {
225+
if (isset($input['restAuthToken']) && is_string($input['restAuthToken'])) {
211226
$config->restAuthToken = trim($input['restAuthToken']);
212227
}
213228

214-
if (isset($input['recordUrl'])) {
229+
if (isset($input['recordUrl']) && is_string($input['recordUrl'])) {
215230
if (!filter_var($input['recordUrl'], FILTER_VALIDATE_URL)) {
216231
fwrite(STDERR, 'Malformed `recordUrl` parameter in configuration file' . PHP_EOL);
217232
} else {
218233
$config->recordUrl = $input['recordUrl'];
219234
}
220235
}
221236

222-
if (isset($input['outboundServerBindIp'])) {
237+
if (isset($input['outboundServerBindIp']) && is_string($input['outboundServerBindIp'])) {
223238
if (filter_var($input['outboundServerBindIp'], FILTER_VALIDATE_IP)) {
224239
$config->outboundServerBindIp = $input['outboundServerBindIp'];
225240
} else {
226241
fwrite(STDERR, 'Malformed `outboundServerBindIp` parameter in configuration file: valid IP address required' . PHP_EOL);
227242
}
228243
}
229244

230-
if (isset($input['outboundServerBindPort'])) {
245+
if (isset($input['outboundServerBindPort']) && is_scalar($input['outboundServerBindPort'])) {
231246
$port = (int)$input['outboundServerBindPort'];
232247

233248
if (!$port || ($port > 65535)) {
234249
fwrite(STDERR, 'Malformed `outboundServerBindPort` parameter in configuration file: valid port number required' . PHP_EOL);
235250
} else {
236-
$config->outboundServerBindPort = $input['outboundServerBindPort'];
251+
$config->outboundServerBindPort = $port;
237252
}
238253
}
239254

240-
if (isset($input['outboundServerAdvertisedIp'])) {
255+
if (isset($input['outboundServerAdvertisedIp']) && is_string($input['outboundServerAdvertisedIp'])) {
241256
if (filter_var($input['outboundServerAdvertisedIp'], FILTER_VALIDATE_IP)) {
242257
$config->outboundServerAdvertisedIp = $input['outboundServerAdvertisedIp'];
258+
} else if ($input['outboundServerAdvertisedIp'] === Set::INBOUND_SOCKET_ADDRESS) {
259+
$config->outboundServerAdvertisedIp = Set::INBOUND_SOCKET_ADDRESS;
243260
} else {
244-
fwrite(STDERR, 'Malformed `outboundServerAdvertisedIp` parameter in configuration file: valid IP address required' . PHP_EOL);
261+
fwrite(STDERR, 'Malformed `outboundServerAdvertisedIp` parameter in configuration file: valid IP address or `' . Set::INBOUND_SOCKET_ADDRESS . '` required' . PHP_EOL);
245262
}
246263
}
247264

248-
if (isset($input['outboundServerAdvertisedPort'])) {
265+
if (isset($input['outboundServerAdvertisedPort']) && is_scalar($input['outboundServerAdvertisedPort'])) {
249266
$port = (int)$input['outboundServerAdvertisedPort'];
250267

251268
if (!$port || ($port > 65535)) {
252269
fwrite(STDERR, 'Malformed `outboundServerAdvertisedPort` parameter in configuration file: valid port number required' . PHP_EOL);
253270
} else {
254-
$config->outboundServerAdvertisedPort = $input['outboundServerAdvertisedPort'];
271+
$config->outboundServerAdvertisedPort = $port;
255272
}
256273
}
257274

258275
if (isset($input['outboundServerLogLevel'])) {
259276
try {
260-
$config->outboundServerLogLevel = Logger::toMonologLevel($input['outboundServerLogLevel']);
277+
/** @var Level */
278+
$outboundServerLogLevel = $input['outboundServerLogLevel'];
279+
$config->outboundServerLogLevel = Logger::toMonologLevel($outboundServerLogLevel);
261280
} catch (InvalidArgumentException $e) {
262281
fwrite(STDERR, 'Malformed `outboundServerLogLevel` parameter in configuration file: ' . $e->getMessage() . PHP_EOL);
263282
}
264283
}
265284

266285
if (isset($input['inboundServerLogLevel'])) {
267286
try {
268-
$config->inboundServerLogLevel = Logger::toMonologLevel($input['inboundServerLogLevel']);
287+
/** @var Level */
288+
$inboundServerLogLevel = $input['inboundServerLogLevel'];
289+
$config->inboundServerLogLevel = Logger::toMonologLevel($inboundServerLogLevel);
269290
} catch (InvalidArgumentException $e) {
270291
fwrite(STDERR, 'Malformed `inboundServerLogLevel` parameter in configuration file: ' . $e->getMessage() . PHP_EOL);
271292
}
272293
}
273294

274-
if (isset($input['callHeartbeatUrl'])) {
295+
if (isset($input['callHeartbeatUrl']) && is_string($input['callHeartbeatUrl'])) {
275296
if (!filter_var($input['callHeartbeatUrl'], FILTER_VALIDATE_URL)) {
276297
fwrite(STDERR, 'Malformed `callHeartbeatUrl` parameter in configuration file' . PHP_EOL);
277298
} else {

src/Config/EnvironmentVars.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,21 @@ function (string $value): bool {
177177
}
178178

179179
if (isset($env[self::PREFIX . 'OUTBOUND_ADVERTISED_ADDRESS'])) {
180-
$err = Set::parseSocketAddr($env[self::PREFIX . 'OUTBOUND_ADVERTISED_ADDRESS'], $ip, $port);
181-
182-
if ($err) {
183-
fwrite(STDERR, 'Malformed ' . self::PREFIX . 'OUTBOUND_ADVERTISED_ADDRESS environment variable' . PHP_EOL);
184-
fwrite(STDERR, $err . PHP_EOL);
180+
if ($env[self::PREFIX . 'OUTBOUND_ADVERTISED_ADDRESS'] === Set::INBOUND_SOCKET_ADDRESS) {
181+
$config->outboundServerAdvertisedIp = Set::INBOUND_SOCKET_ADDRESS;
185182
} else {
186-
assert(!is_null($ip));
187-
assert(!is_null($port));
183+
$err = Set::parseSocketAddr($env[self::PREFIX . 'OUTBOUND_ADVERTISED_ADDRESS'], $ip, $port);
184+
185+
if ($err) {
186+
fwrite(STDERR, 'Malformed ' . self::PREFIX . 'OUTBOUND_ADVERTISED_ADDRESS environment variable' . PHP_EOL);
187+
fwrite(STDERR, $err . PHP_EOL);
188+
} else {
189+
assert(!is_null($ip));
190+
assert(!is_null($port));
188191

189-
$config->outboundServerAdvertisedIp = $ip;
190-
$config->outboundServerAdvertisedPort = $port;
192+
$config->outboundServerAdvertisedIp = $ip;
193+
$config->outboundServerAdvertisedPort = $port;
194+
}
191195
}
192196
}
193197

0 commit comments

Comments
 (0)