-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.php
43 lines (30 loc) · 1.32 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\Psr18Client;
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/PerformanceMeasurementClient.php');
require(__DIR__ . '/../helpers/get-content-ids.php');
$http_client_autodiscover = getenv('AUTODISCOVER') === 'true';
$http_client_timeout = getenv('TIMEOUT');
$http_client_measure_performance = getenv('MEASURE_PERFORMANCE') === 'true';
if ($http_client_autodiscover && ($http_client_timeout || $http_client_measure_performance)) {
throw new LogicException('It is not possible to set timeout on autodiscovered http client');
}
$config = \Joystick\ClientConfig::create()
->setApiKey(getenv('JOYSTICK_API_KEY'))
->setSemVer("0.0.1");
if (!$http_client_autodiscover) {
$httpClient = HttpClient::create(['timeout' => $http_client_timeout ?: 5]);
$symfonyHttpClient = new Psr18Client($httpClient);
$psr18Client = $http_client_measure_performance
? new PerformanceMeasurementClient($symfonyHttpClient)
: $symfonyHttpClient;
$config->setHttpClient($psr18Client);
}
$client = \Joystick\Client::create($config);
$fetchedData = $client->getContents(getContentIdsFromEnv(), [
'serialized' => true,
'fullResponse' => true,
]);
echo json_encode($fetchedData, JSON_PRETTY_PRINT);