Description
Description
In our entities we create a lot of datetime values, typically:
public function __construct() {
$this->createdAt = new \DateTime();
}
Upgrading this to using a clock requires currently a refactoring of the domain layer, either using an entity listener to inject datetime values during flush, or pass it from the outside (in this case a new constructor argument).
Using an entity listener might break all kinds of domain logic that expect the datetime value to be set.
Passing it from the outside is plain boring for what is initializing a typed value (datetime datatype), and also impacts the domain layer signature wise.
To overcome i propose a static accesible system clock, which should make upgrading more easy.
static Clock::setSystemClock(self $clock): void
static Clock::getSysyemClock(): self
function sf/now(): \DateTimeImmutable;
$this->createtAt = sf/now();
This might be frowned upon, but it's really what happens today already. Constructing a datatype should not require a service layer on high level IMHO.
This is comparable to string datatype u('...')->toString()
.
Example
No response