@@ -32,8 +32,40 @@ class ServerFactory {
32
32
Server::class
33
33
];
34
34
35
- /** @var System|null */
36
- private $ system = null ;
35
+ /** @var System */
36
+ private $ system ;
37
+
38
+ /** @var IOptions */
39
+ private $ options ;
40
+
41
+ /** @var ITimeZoneProvider */
42
+ private $ timeZoneProvider ;
43
+
44
+ /**
45
+ * ServerFactory constructor.
46
+ *
47
+ * @param IOptions|null $options
48
+ * @param ISystem|null $system
49
+ * @param ITimeZoneProvider|null $timeZoneProvider
50
+ */
51
+ public function __construct (
52
+ IOptions $ options = null ,
53
+ ISystem $ system = null ,
54
+ ITimeZoneProvider $ timeZoneProvider = null
55
+ ) {
56
+ if (is_null ($ options )) {
57
+ $ options = new Options ();
58
+ }
59
+ if (is_null ($ system )) {
60
+ $ system = new System ();
61
+ }
62
+ if (is_null ($ timeZoneProvider )) {
63
+ $ system = new TimeZoneProvider ($ system );
64
+ }
65
+ $ this ->options = $ options ;
66
+ $ this ->system = $ system ;
67
+ }
68
+
37
69
38
70
/**
39
71
* @param $host
@@ -43,8 +75,8 @@ class ServerFactory {
43
75
*/
44
76
public function createServer ($ host , IAuth $ credentials ) {
45
77
foreach (self ::BACKENDS as $ backend ) {
46
- if (call_user_func ("$ backend::available " , $ this ->getSystem () )) {
47
- return new $ backend ($ host , $ credentials , $ this ->getSystem (), new TimeZoneProvider ( $ host , $ this ->getSystem ()) );
78
+ if (call_user_func ("$ backend::available " , $ this ->system )) {
79
+ return new $ backend ($ host , $ credentials , $ this ->system , $ this ->timeZoneProvider );
48
80
}
49
81
}
50
82
@@ -55,10 +87,6 @@ public function createServer($host, IAuth $credentials) {
55
87
* @return System
56
88
*/
57
89
private function getSystem () {
58
- if (is_null ($ this ->system )) {
59
- $ this ->system = new System ();
60
- }
61
-
62
90
return $ this ->system ;
63
91
}
64
92
}
0 commit comments