psr/clock
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The "psr/clock" is a composer package that provides a common interface for reading the clock in PHP. It's important to understand that psr/clock is not a clock on its own, but rather an interface that describes one. The purpose of this package is to provide a standard across PHP development for handling time and events that are based on a certain timeframe.
To use psr/clock, you would first need to install it using the composer command: composer require psr/clock
. Once installed, you can make use of it by implementing the Psr\Clock\ClockInterface
into your class and use the now
method to get the current date and time. Here is an example code snippet shows how it could be utilized:
<?php
use Psr\Clock\ClockInterface;
class Foo
{
private ClockInterface $clock;
public function __construct(ClockInterface $clock)
{
$this->clock = $clock;
}
public function doSomething()
{
/** @var DateTimeImmutable $currentDateAndTime */
$currentDateAndTime = $this->clock->now(); // fetches the current date and time
// do something useful with that information
}
}
Note, to create an implementation for the clock, you should add psr/clock-implementation
to your composer.json
s provides
-section to indicate that your code fulfills this functionality.
The primary source of documentation for psr/clock is contained within the official GitHub repository available at https://github.com/php-fig/clock.git. In terms of more detailed implementation documentation, you'd want to check the specification text at https://github.com/php-fig/fig-standards/blob/master/proposed/clock.md. These sources should provide guidance on how to correctly integrate and use this composer package within your PHP development projects.