4
4
5
5
namespace Cycle \ORM \Entity \Behavior \Identifier ;
6
6
7
+ use Cycle \Database \DatabaseInterface ;
7
8
use Cycle \ORM \Entity \Behavior \Schema \BaseModifier ;
8
9
use Cycle \ORM \Entity \Behavior \Schema \RegistryModifier ;
9
10
use Cycle \ORM \Schema \GeneratedField ;
10
11
use Cycle \Schema \Registry ;
11
- use Ramsey \Identifier \SnowflakeFactory ;
12
12
13
13
abstract class Snowflake extends BaseModifier
14
14
{
@@ -24,6 +24,7 @@ abstract class Snowflake extends BaseModifier
24
24
public function compute (Registry $ registry ): void
25
25
{
26
26
$ modifier = new RegistryModifier ($ registry , $ this ->role );
27
+ /** @var non-empty-string column */
27
28
$ this ->column = $ modifier ->findColumnName ($ this ->field , $ this ->column );
28
29
if (\is_string ($ this ->column ) && $ this ->column !== '' ) {
29
30
$ modifier ->addSnowflakeColumn (
@@ -32,11 +33,9 @@ public function compute(Registry $registry): void
32
33
$ this ->nullable ? null : GeneratedField::BEFORE_INSERT ,
33
34
)->nullable ($ this ->nullable );
34
35
35
- $ factory = $ this ->snowflakeFactory ();
36
-
37
36
$ modifier ->setTypecast (
38
37
$ registry ->getEntity ($ this ->role )->getFields ()->get ($ this ->field ),
39
- [$ factory , 'createFromInteger ' ],
38
+ [static ::class , 'fromInteger ' , $ this -> getTypecastArgs () ],
40
39
);
41
40
}
42
41
}
@@ -54,13 +53,20 @@ public function render(Registry $registry): void
54
53
$ this ->nullable ? null : GeneratedField::BEFORE_INSERT ,
55
54
)->nullable ($ this ->nullable );
56
55
57
- $ factory = $ this ->snowflakeFactory ();
58
-
59
56
$ modifier ->setTypecast (
60
57
$ registry ->getEntity ($ this ->role )->getFields ()->get ($ this ->field ),
61
- [$ factory , 'createFromInteger ' ],
58
+ [static ::class , 'fromInteger ' , $ this -> getTypecastArgs () ],
62
59
);
63
60
}
64
61
65
- abstract protected function snowflakeFactory (): SnowflakeFactory ;
62
+ /**
63
+ * @param int<0, max>|numeric-string $identifier
64
+ */
65
+ abstract public static function fromInteger (
66
+ int |string $ identifier ,
67
+ DatabaseInterface $ database ,
68
+ array $ arguments ,
69
+ ): \Ramsey \Identifier \Snowflake ;
70
+
71
+ abstract protected function getTypecastArgs (): array ;
66
72
}
0 commit comments