Commit 409e165 1 parent ced8008 commit 409e165 Copy full SHA for 409e165
File tree 2 files changed +6
-4
lines changed
2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -94,14 +94,14 @@ class Policy
94
94
) {
95
95
}
96
96
97
- public static function initSchema (\Tarantool\Mapper\Space $space)
97
+ public static function initialize (\Tarantool\Mapper\Space $space)
98
98
{
99
99
$space->addIndex(['nick'], ['unique' => true]);
100
100
}
101
101
}
102
102
103
103
$policy = $mapper->createSpace('policy');
104
- $policy->setClass(Policy::class);
104
+ $policy->setClass(Policy::class, 'initialize'); // use custom initialize method
105
105
$policy->migrate();
106
106
```
107
107
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class Space
23
23
private array $ indexes = [];
24
24
25
25
private ?string $ class = null ;
26
+ private ?string $ init = null ;
26
27
private ?ReflectionMethod $ constructor = null ;
27
28
28
29
public function __construct (public readonly Mapper $ mapper , array $ meta = [])
@@ -322,17 +323,18 @@ public function migrate()
322
323
323
324
$ this ->addProperty ($ property ->getName (), $ tarantoolType , $ opts );
324
325
}
325
- $ init = $ reflection ->getMethod (' initSchema ' );
326
+ $ init = $ reflection ->getMethod ($ this -> init );
326
327
327
328
if ($ init && $ init ->isStatic ()) {
328
329
$ init ->invoke (null , $ this );
329
330
}
330
331
}
331
332
332
- public function setClass (string $ class )
333
+ public function setClass (string $ class, string $ init = ' initSchema ' )
333
334
{
334
335
$ reflection = new ReflectionClass ($ class );
335
336
$ this ->class = $ class ;
337
+ $ this ->init = $ init ;
336
338
$ this ->constructor = $ reflection ->getConstructor ();
337
339
}
338
340
You can’t perform that action at this time.
0 commit comments