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

Accept only string|null as template value strictly #1989

Closed mvorisek closed 1 year ago

mvorisek commented 1 year ago

part of #1987

template cannot judge what persistence/type to use for typecasting

mkrecek234 commented 1 year ago

@mvorisek Why do we need this BC-break? It is very common to run set and just pass any model field to fill in template variables. The BC-break leads to an error because each and every set variable has to be first converted to string.

Use Case: You have a HTML invoice template and want to set the integer order number.

Before: $template->set('invoice_no', $model->get('invoice_no'))

Now: $template->set('invoice_no', (string) $model->get('invoice_no'))

What is the benefit justifying this BC-break?

mvorisek commented 1 year ago

Please read the PR description and let's continue the discussion in a private chat, as the real impact should be minimal with the best atk4/ui usage.

mvorisek commented 1 year ago

image

mkrecek234 commented 1 year ago

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')]);