File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodeIgniter \Shield \Entities \Cast ;
4+
5+ use CodeIgniter \Entity \Cast \BaseCast ;
6+
7+ /**
8+ * Int Bool Cast
9+ *
10+ * DB column: int (0/1) <--> Class property: bool
11+ */
12+ final class IntBoolCast extends BaseCast
13+ {
14+ /**
15+ * @param int $value
16+ */
17+ public static function get ($ value , array $ params = []): bool
18+ {
19+ return (bool ) $ value ;
20+ }
21+
22+ /**
23+ * @param bool|int|string $value
24+ */
25+ public static function set ($ value , array $ params = []): int
26+ {
27+ return (int ) $ value ;
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodeIgniter \Shield \Entities ;
4+
5+ use CodeIgniter \Entity \Entity as FrameworkEntity ;
6+ use CodeIgniter \Shield \Entities \Cast \IntBoolCast ;
7+
8+ /**
9+ * Base Entity
10+ */
11+ abstract class Entity extends FrameworkEntity
12+ {
13+ /**
14+ * Custom convert handlers
15+ *
16+ * @var array<string, string>
17+ * @phpstan-var array<string, class-string>
18+ */
19+ protected $ castHandlers = [
20+ 'int_bool ' => IntBoolCast::class,
21+ ];
22+ }
You can’t perform that action at this time.
0 commit comments