Download the PHP package baldinof/clock without Composer
On this page you can find all versions of the php package baldinof/clock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download baldinof/clock
More information about baldinof/clock
Files in baldinof/clock
Package clock
Short Description Simple clock abstraction
License MIT
Homepage https://github.com/baldinof/clock
Informations about the package clock
PHP Clock abstraction
Get current time in a static and testable way.
Installation
You can install the package via composer:
Static usage
Why static calls instead of dependency injection?
Static calls are very convenient when defining models:
Testing
You can use the FrozenClockTrait
in your test to freeze the clock a the begining of your tests and manipulate time.
You can allso explicitly manipulate the clock
Timezones
Out of the box Clock::now()
does not pass the timezone argument to the DateTimeImmutable
constructor, so the php default timezone is used.
You can change the default timezone in your php.ini
.
Otherwise, call date_default_timezone_set()
or call Clock::set()
in your application bootstrap code:
Usage with dependency injection
You can get the actual clock instance and registers it in your dependency injection container by calling Clock::get()
.
For example with Symfony PHP DSL:
Or with Laravel:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
This package is inspired by lcobucci/clock and ramsey/uuid for the static usage.
License
The MIT License (MIT). Please see License File for more information.