PHP code example of tarasterletskij / true-service-time
1. Go to this page and download the library: Download tarasterletskij/true-service-time library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tarasterletskij / true-service-time example snippets
use GuzzleHttp\Client;
use TrueServiceTime\Application\Factory\TimeServiceFactory;
$httpClient = new Client([
'timeout' => 10.0,
'verify' => true,
]);
$service = TimeServiceFactory::create($httpClient);
$clock = $service->getServerTime();
use GuzzleHttp\Client;
use TrueServiceTime\Application\Service\TimeService;
use TrueServiceTime\Infrastructure\TimeProvider\TimeApiIoProvider;
use TrueServiceTime\Infrastructure\IpDetector\IpApiDetector;
$httpClient = new Client(['timeout' => 5.0]);
$timeProvider = new TimeApiIoProvider($httpClient);
$ipDetector = new IpApiDetector($httpClient);
$service = new TimeService($timeProvider, $ipDetector);
$clock = $service->getServerTime();
use TrueServiceTime\Domain\Exception\TimeProviderException;
use TrueServiceTime\Domain\Exception\IpDetectionException;
$service = TimeServiceFactory::create();
try {
$clock = $service->getServerTime();
} catch (TimeProviderException $e) {
// Handle time provider API failure
} catch (IpDetectionException $e) {
// Handle IP detection failure
} catch (\InvalidArgumentException $e) {
// Handle invalid IP address
}