PHP code example of vladyslav-dyba / server-clock

1. Go to this page and download the library: Download vladyslav-dyba/server-clock 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/ */

    

vladyslav-dyba / server-clock example snippets




// Include the Composer autoloader
 for the next steps
$ipSource = new ExternalIpSource(IpInfoDataProviderFactory::make());
    
// Source of time
// Current example works based on defined IP
// Though, a client of the library can use its own implementation for TimeSourceDataProviderInterface
$timeSource = new DefaultTimeSource(TimeApiDataProviderFactory::make($ipSource));

// ServerClock is the core of the library
// It provides time based on TimeSourceInterface
// As well, a client of the library can use its own implementation for TimeSourceInterface

$serverClock = new ServerClock($timeSource);
$time = $serverClock->now();

echo $time->format(DateTime::ATOM) . "\n";

// Include the Composer autoloader
$argv[1];

// IpSource object provides an IP for the next steps
$ipSource = new CustomIpSource($ip);
    
// Source of time
// Current example works based on defined IP
// Though, a client of the library can use its own implementation for TimeSourceDataProviderInterface
$timeSource = new DefaultTimeSource(TimeApiDataProviderFactory::make($ipSource));

// ServerClock is the core of the library
// It provides time based on TimeSourceInterface
// As well, a client of the library can use its own implementation for TimeSourceInterface

$serverClock = new ServerClock($timeSource);
$time = $serverClock->now();

echo $time->format(DateTime::ATOM) . "\n";
bash
  php ./bin/console.php 8.8.8.8
  php ./vendor/vladyslav-dyba/server-clock/bin/console.php 8.8.8.8
bash
  php ./bin/console.php
  php ./vendor/vladyslav-dyba/server-clock/bin/console.php