feat: support BackedEnum values in database binds#10256
Conversation
- Allow database escaping to use BackedEnum backing values - Support BackedEnum values in query bindings and Query Builder binds - Add focused tests and user guide examples Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
michalsn
left a comment
There was a problem hiding this comment.
Seems like native prepared statements are not supported.
$query = $db->prepare(...);
$query->execute(StatusEnum::ACTIVE);
Thanks for the review. I pushed an update for adding prepared query support, object input coverage, and the SQL assertion helper. |
|
@memleakd Could you please implement the |
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
0f8817f to
7314bed
Compare
That was my natural first instinct too, but I somehow got the impression from the review wording that it might be preferred here 😅 Anyway, I reverted it now, so this PR is clean again and only keeps the enum-related changes. |
Description
This PR adds support for PHP
BackedEnumvalues in database escaping, query bindings, and escaped Query Builder values.It was inspired by @maniaba's forum post and #10223.
For apps that use native PHP enums for domain values, this makes database code a bit nicer to write:
CodeIgniter will use the enum's backing value when escaping it, so string-backed enums are treated like strings and int-backed enums are treated like integers.
This avoids repeating
->valueat every query call site, while keeping raw SQL and escape-disabled values in the caller's control.The implementation is intentionally small: enum cases are unwrapped during database escaping, so regular query bindings and escaped Query Builder values use the same existing path.
Checklist: