Skip to content

Commit 90a98d3

Browse files
committed
Virtual field support for converting standard PHP types if needed
1 parent b43ffde commit 90a98d3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/PHPFUI/ORM/Enum.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
class Enum extends \PHPFUI\ORM\VirtualField
66
{
7+
/**
8+
* @param array<mixed> $parameters
9+
**/
10+
public function fromPHPValue(mixed $value, array $parameters) : mixed
11+
{
12+
$enum = $parameters[0];
13+
14+
return $enum::from($value);
15+
}
16+
717
/**
818
* @param array<mixed> $parameters optional
919
*/

src/PHPFUI/ORM/VirtualField.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ public function __construct(protected \PHPFUI\ORM\Record $currentRecord, protect
88
{
99
}
1010

11+
/**
12+
* Override to do a custom conversion from a base PHP type (string, int, float, bool, ect)
13+
*
14+
* @param array<mixed> $parameters optional
15+
*/
16+
public function fromPHPValue(mixed $value, array $parameters) : mixed
17+
{
18+
return $value;
19+
}
20+
1121
/**
1222
* @param array<mixed> $parameters optional
1323
*/

0 commit comments

Comments
 (0)