Skip to content

Commit 7409bea

Browse files
committed
fix!: add toDatabase() and fromDatabase() to CastInterface
1 parent 385c9ea commit 7409bea

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

system/Entity/Cast/BaseCast.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
abstract class BaseCast implements CastInterface
1818
{
1919
/**
20-
* Get
20+
* Returns value when getting the Entity property.
21+
* This method is normally returns the value as it is.
2122
*
2223
* @param array|bool|float|int|object|string|null $value Data
2324
* @param array $params Additional param
@@ -30,7 +31,7 @@ public static function get($value, array $params = [])
3031
}
3132

3233
/**
33-
* Set
34+
* Returns value for Entity property when setting the Entity property.
3435
*
3536
* @param array|bool|float|int|object|string|null $value Data
3637
* @param array $params Additional param
@@ -41,4 +42,30 @@ public static function set($value, array $params = [])
4142
{
4243
return $value;
4344
}
45+
46+
/**
47+
* Takes the Entity property value, returns its value for database.
48+
*
49+
* @param array|bool|float|int|object|string|null $value Data
50+
* @param array $params Additional param
51+
*
52+
* @return bool|float|int|string|null
53+
*/
54+
public static function toDatabase($value, array $params = [])
55+
{
56+
return $value;
57+
}
58+
59+
/**
60+
* Takes value from database, returns its value for the Entity property.
61+
*
62+
* @param bool|float|int|string|null $value Data
63+
* @param array $params Additional param
64+
*
65+
* @return array|bool|float|int|object|string|null
66+
*/
67+
public static function fromDatabase($value, array $params = [])
68+
{
69+
return $value;
70+
}
4471
}

system/Entity/Cast/CastInterface.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313

1414
/**
1515
* Interface CastInterface
16+
*
17+
* [App Code] --- set() --> [Entity] --- toDatabase() ---> [Database]
18+
* [App Code] <-- get() --- [Entity] <-- fromDatabase() -- [Database]
1619
*/
1720
interface CastInterface
1821
{
1922
/**
20-
* Get
23+
* Returns value when getting the Entity property.
24+
* This method is normally returns the value as it is.
2125
*
2226
* @param array|bool|float|int|object|string|null $value Data
2327
* @param array $params Additional param
@@ -27,12 +31,32 @@ interface CastInterface
2731
public static function get($value, array $params = []);
2832

2933
/**
30-
* Set
34+
* Returns value for the Entity property when setting the Entity property.
3135
*
3236
* @param array|bool|float|int|object|string|null $value Data
3337
* @param array $params Additional param
3438
*
3539
* @return array|bool|float|int|object|string|null
3640
*/
3741
public static function set($value, array $params = []);
42+
43+
/**
44+
* Takes the Entity property value, returns its value for database.
45+
*
46+
* @param array|bool|float|int|object|string|null $value Data
47+
* @param array $params Additional param
48+
*
49+
* @return bool|float|int|string|null
50+
*/
51+
public static function toDatabase($value, array $params = []);
52+
53+
/**
54+
* Takes value from database, returns its value for the Entity property.
55+
*
56+
* @param bool|float|int|string|null $value Data
57+
* @param array $params Additional param
58+
*
59+
* @return array|bool|float|int|object|string|null
60+
*/
61+
public static function fromDatabase($value, array $params = []);
3862
}

0 commit comments

Comments
 (0)