定制 vladyslav-dyba/server-clock 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vladyslav-dyba/server-clock

最新稳定版本:1.2

Composer 安装命令:

composer require vladyslav-dyba/server-clock

包简介

Provide correct server time based on its external IP

README 文档

README

Packagist

Provide correct server time based on its external IP

Table of Contents

Installation

Composer Installation

To install the package, you can use Composer:

composer require vladyslav-dyba/server-clock

This will add the package to your composer.json file and download it into the vendor directory. Manual Installation

In case you want to include it manually, you can also follow these steps:

 - Download the package files.
 - Include the Composer autoloader in your project:
require 'vendor/autoload.php';

Test run

Once you clone the package sepparetly, you can perform a test run to get local time based on an IP

To get local time for specific IP

  php ./bin/console.php 8.8.8.8
  php ./vendor/vladyslav-dyba/server-clock/bin/console.php 8.8.8.8

To get local time for external server IP

  php ./bin/console.php
  php ./vendor/vladyslav-dyba/server-clock/bin/console.php

Usage

Here, explain how to use your package with practical examples. Provide some basic functionality and advanced use cases.

To get a local time of the external server IP:

// Include the Composer autoloader
require 'vendor/autoload.php';

// IpSource object provides an IP 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";

To get a local time of the provided a specific IP:

// Include the Composer autoloader
require 'vendor/autoload.php';

// Receiving a specific IP
$ip = $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";

Structure

Core

The core of the package is ServerClock object that implements TimeSourceInterface interface

TimeSource

ServerClock gets a time from a $timeSource that implements TimeSourceInterface

Package has only one basic implementation of the TimeSourceInterface - DefaultTimeSource and its TimeSourse DataProvider: TimeApi service

Client can substitute the DataProvider with their own solution that implements the TimeSourceInterface

IpSource

Since TimeSource works based on an IP information, IpSourceInterface implementation has to be provided.

Package has two basic implementation of the IpSourceInterface:

  • CustomIpSource - provides any specific IP address
  • ExternalIpSource - uses IpInfo service as IpSource DataProvider to get and provide the external server IP

Configuration

Regardless, the package has its own TimeSourceInterface and IpSourceInterface implementations,

there is no any configuration that can be applied for the package because the package was created with minimum dependencies and its the primary approach to configure the package is substituting the interfaces implementations on a client side

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-04-09