atk4 / ui

Robust and easy to use PHP Framework for Web Apps
https://atk4-ui.readthedocs.io
MIT License
440 stars 105 forks source link

Default typecasting should be applied for any View on set #1990

Open mkrecek234 opened 1 year ago

mkrecek234 commented 1 year ago

Enforcing HTMLTemplate in #1989 to accept string only, makes coding unnecessarily cumbersome.

Why is PHP-standard typecasting not allowed here where model field is an integer?

\Atk4\Ui\Header::addTo($app, [$model->get('stock')]);

Simple code, simple PHP typecasting. Do we really want to enforce everyone to code like this? \Atk4\Ui\Header::addTo($app, [(string) $model->get('stock')]);

Either, any view which is set a value to should continue to use PHP-default typecasting or it should behind the scenes use uiPersistence typecasting.

mvorisek commented 1 year ago

with hintable, such problem is detected by phpstan, and was before #1989

in 95% of atk4/ui code we do accept string (strongly typed) strictly, so even if we fix this for Header/View constructor content/label, the issue will remain for other 95% cases

Also, opinionated, I wonder how purely numeric header is common/helpful to be supported - 'Stock #' . $model->get('stock') will cast the integer implicitly...