File tree 3 files changed +16
-7
lines changed
3 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 5
5
"license" : " MIT" ,
6
6
"require" : {
7
7
"php" : " >=8.0" ,
8
- "cycle/database" : " ^2.0 " ,
8
+ "cycle/database" : " ^2.3 " ,
9
9
"spiral/core" : " ^2.7" ,
10
10
"spiral/files" : " ^2.7" ,
11
11
"spiral/tokenizer" : " ^2.7" ,
Original file line number Diff line number Diff line change @@ -43,21 +43,27 @@ protected function declareColumn(AbstractTable $schema): AbstractColumn
43
43
//Type configuring
44
44
if (method_exists ($ column , $ this ->type )) {
45
45
$ arguments = [];
46
+ $ variadic = false ;
46
47
47
48
$ method = new \ReflectionMethod ($ column , $ this ->type );
48
49
foreach ($ method ->getParameters () as $ parameter ) {
49
50
if ($ this ->hasOption ($ parameter ->getName ())) {
50
- $ arguments [] = $ this ->getOption ($ parameter ->getName ());
51
+ $ arguments [$ parameter -> getName () ] = $ this ->getOption ($ parameter ->getName ());
51
52
} elseif (!$ parameter ->isOptional ()) {
52
53
throw new ColumnException (
53
54
"Option ' {$ parameter ->getName ()}' are required to define column with type ' {$ this ->type }' "
54
55
);
55
- } else {
56
- $ arguments [] = $ parameter ->getDefaultValue ();
56
+ } elseif ($ parameter ->isDefaultValueAvailable ()) {
57
+ $ arguments [$ parameter ->getName ()] = $ parameter ->getDefaultValue ();
58
+ } elseif ($ parameter ->isVariadic ()) {
59
+ $ variadic = true ;
57
60
}
58
61
}
59
62
60
- call_user_func_array ([$ column , $ this ->type ], $ arguments );
63
+ \call_user_func_array (
64
+ [$ column , $ this ->type ],
65
+ $ variadic ? $ arguments + $ this ->options + $ column ->getAttributes () : $ arguments ,
66
+ );
61
67
} else {
62
68
$ column ->type ($ this ->type );
63
69
}
Original file line number Diff line number Diff line change @@ -310,15 +310,18 @@ public function testCreateDatetimeNowColumn(): void
310
310
$ this ->migrator ->configure ();
311
311
312
312
$ schema = $ this ->schema ('sample ' );
313
- $ column = $ schema ->datetime ('value ' );
313
+ $ column = $ schema ->datetime ('value ' , size: 2 , foo: ' bar ' );
314
314
$ column ->defaultValue (new Fragment ($ column ::DATETIME_NOW ));
315
315
316
316
$ this ->atomize ('migration1 ' , [$ schema ]);
317
317
318
318
$ this ->migrator ->run ();
319
319
320
320
$ this ->assertTrue ($ this ->db ->hasTable ('sample ' ));
321
- $ this ->assertSame ((string )$ column ->getDefaultValue (), (string )$ this ->schema ('sample ' )->column ('value ' )->getDefaultValue ());
321
+ $ this ->assertSame (
322
+ (string )$ column ->getDefaultValue (),
323
+ (string )$ this ->schema ('sample ' )->column ('value ' )->getDefaultValue ()
324
+ );
322
325
323
326
$ this ->migrator ->rollback ();
324
327
$ this ->assertFalse ($ this ->db ->hasTable ('sample ' ));
You can’t perform that action at this time.
0 commit comments