DomTemplate icon indicating copy to clipboard operation
DomTemplate copied to clipboard

Register stringification for different classes

Open g105b opened this issue 3 years ago • 1 comments

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.

g105b avatar Oct 17 '22 11:10 g105b

Note that at the current time, DateTimeInterface has its own handler, which defaults to RFC7231 thanks to the new BindValue class.

g105b avatar Jan 30 '23 19:01 g105b