DomTemplate
DomTemplate copied to clipboard
Register stringification for different classes
Binding a value that isn't stringable causes an error currently, and so it should.
However, it would be nice to be able to register a callback to stringify a class, and provide defaults. This will be called within BindableCache, so #382 can be covered by this issue instead.
$documentBinder->registerToString(
DateTimeInterface::class,
fn(DateTimeInterface $dt) => $dt->format("H:i:s")
);
This is just an idea for the syntax.
There should also be the ability to register a default, which can be done by WebEngine for built in types like DateTimeInterface, DateInterval, SplFileObject, etc.
Note that at the current time, DateTimeInterface has its own handler, which defaults to RFC7231 thanks to the new BindValue class.