10
10
class UserBuilder implements Builder {
11
11
private $ model ;
12
12
public $ data ;
13
- public function __construct (){
14
- $ this ->model = new UserModel ;
13
+ public function __construct ($ model = null ){
14
+ if ($ model === null ) {
15
+ $ this ->model = new UserModel ;
16
+ } else {
17
+ $ this ->model = $ model ;
18
+ }
15
19
}
16
- public function setName ($ name ){
20
+ public function setName ($ name ) : Builder {
17
21
$ this ->model ->set ('name ' ,UserName::main ($ name ));
22
+ return new UserBuilder ($ this ->model );
18
23
}
19
- public function setAge ($ age ){
24
+ public function setAge ($ age ) : Builder {
20
25
$ this ->model ->set ('age ' ,UserAge::main ($ age ));
26
+ return new UserBuilder ($ this ->model );
21
27
}
22
- public function setLevel ($ level ){
28
+ public function setLevel ($ level ) : Builder {
23
29
$ this ->model ->set ('level ' ,UserLevel::main ($ level ));
30
+ return new UserBuilder ($ this ->model );
24
31
}
25
- public function setLocation ($ location ){
32
+ public function setLocation ($ location ) : Builder {
26
33
$ this ->model ->set ('location ' ,UserLocation::main ($ location ));
34
+ return new UserBuilder ($ this ->model );
27
35
}
28
- public function setTodo ($ role = 'member ' ){
36
+ public function setTodo ($ role = 'member ' ) : Builder {
29
37
$ this ->model ->set ('todo ' ,UserTodo::main ($ role ));
38
+ return new UserBuilder ($ this ->model );
30
39
}
31
- public function build (){
32
- $ this -> data = $ this ->model ->data ;
40
+ public function build () : array {
41
+ return $ this ->model ->data ;
33
42
}
34
43
}
0 commit comments