55class ConfigFactory
66{
77
8- /** @var mixed[] */
8+ /** @var object */
99 private $ data ;
1010
1111 /**
12- * @param mixed[] $data
12+ * @param object $data
1313 */
14- public function __construct (array $ data )
14+ public function __construct (object $ data )
1515 {
1616 $ this ->data = $ data ;
1717 }
@@ -22,57 +22,68 @@ public function create(): Config
2222 $ config = new Config ();
2323
2424 // Parse mode
25- switch ($ this ->data ['config ' ]['mode ' ]) {
26- case Config::MODE_GENERATE :
27- $ mode = Config::MODE_GENERATE ;
28- break ;
29- case Config::MODE_RUN :
30- $ mode = Config::MODE_RUN ;
31- break ;
32- default :
33- $ mode = Config::MODE_TEST ;
25+ if (isset ($ this ->data ->config ) && isset ($ this ->data ->config ->mode )) {
26+ switch ($ this ->data ->config ->mode ) {
27+ case Config::MODE_GENERATE :
28+ $ mode = Config::MODE_GENERATE ;
29+ break ;
30+ case Config::MODE_RUN :
31+ $ mode = Config::MODE_RUN ;
32+ break ;
33+ default :
34+ $ mode = Config::MODE_TEST ;
35+ }
36+
37+ // Set mode (run|generate|test)
38+ $ config ->setMode ($ mode );
39+ } else {
40+ $ config ->setMode (Config::MODE_TEST );
3441 }
3542
36- // Set mode (run|generate|test)
37- $ config ->setMode ($ mode );
38- $ config ->setLogFile ($ this ->data ['config ' ]['logFile ' ]);
39- $ config ->setTempDir ($ this ->data ['config ' ]['tempDir ' ] ?? sys_get_temp_dir () . '/deployment ' );
43+ $ config ->setLogFile ((isset ($ this ->data ->config ) && isset ($ this ->data ->config ->logFile )) ? $ this ->data ->config ->logFile : '' );
44+ $ config ->setTempDir ((isset ($ this ->data ->config ) && isset ($ this ->data ->config ->tempDir )) ? $ this ->data ->config ->tempDir : sys_get_temp_dir () . '/deployment ' );
4045
4146 // Set or detect colors support
42- if ($ this ->data [ ' config ' ][ ' colors ' ] !== null ) {
43- $ config ->setColors ((bool ) $ this ->data [ ' config ' ][ ' colors ' ] );
47+ if (isset ( $ this ->data -> config ) && isset ( $ this -> data -> config -> colors ) && $ this -> data -> config -> colors !== null ) {
48+ $ config ->setColors ((bool ) $ this ->data -> config -> colors );
4449 } else {
4550 $ config ->setColors (PHP_SAPI === 'cli ' && ((function_exists ('posix_isatty ' ) && posix_isatty (STDOUT ))
4651 || getenv ('ConEmuANSI ' ) === 'ON ' || getenv ('ANSICON ' ) !== false ));
4752 }
4853
4954 // Set user data
50- $ config ->setUserdata ($ this ->data ['userdata ' ]);
55+ if (isset ($ this ->data ->userdata )) {
56+ $ config ->setUserdata ($ this ->data ->userdata );
57+ }
5158
5259 // Set plugins
53- $ config ->setPlugins ($ this ->data ['plugins ' ]);
60+ if (isset ($ this ->data ->plugins )) {
61+ $ config ->setPlugins ($ this ->data ->plugins );
62+ }
5463
5564 // Parse sections
56- foreach ($ this ->data ['sections ' ] as $ name => $ sdata ) {
57- $ section = new Section ();
58- $ section ->setName ($ name );
59- $ section ->setTestMode ($ sdata ['testMode ' ]);
60- $ section ->setLocal ($ sdata ['local ' ]);
61- $ section ->setRemote ($ sdata ['remote ' ]);
62- $ section ->setPreprocess ($ sdata ['preprocess ' ]);
63- $ section ->setPreprocessMasks ($ sdata ['preprocess ' ] !== false ? $ sdata ['preprocess ' ] : []);
64- $ section ->setAllowDelete ($ sdata ['allowdelete ' ]);
65- $ section ->setIgnoreMasks ($ sdata ['ignore ' ]);
66- $ section ->setDeployFile ($ sdata ['deployFile ' ]);
67- $ section ->setAfterCallbacks ($ sdata ['after ' ]);
68- $ section ->setBeforeCallbacks ($ sdata ['before ' ]);
69- $ section ->setPassiveMode ($ sdata ['passiveMode ' ]);
70- $ section ->setPurges ($ sdata ['purge ' ]);
71- $ section ->setFilePermissions ($ sdata ['filePermissions ' ]);
72- $ section ->setDirPermissions ($ sdata ['dirPermissions ' ]);
65+ if (isset ($ this ->data ->sections )) {
66+ foreach ($ this ->data ->sections as $ name => $ sdata ) {
67+ $ section = new Section ();
68+ $ section ->setName ($ name );
69+ $ section ->setTestMode ($ sdata ->testMode );
70+ $ section ->setLocal ($ sdata ->local );
71+ $ section ->setRemote ($ sdata ->remote );
72+ $ section ->setPreprocess ($ sdata ->preprocess );
73+ $ section ->setPreprocessMasks ($ sdata ->preprocess !== false ? $ sdata ->preprocess : []);
74+ $ section ->setAllowDelete ($ sdata ->allowdelete );
75+ $ section ->setIgnoreMasks ($ sdata ->ignore );
76+ $ section ->setDeployFile ($ sdata ->deployFile );
77+ $ section ->setAfterCallbacks ($ sdata ->after );
78+ $ section ->setBeforeCallbacks ($ sdata ->before );
79+ $ section ->setPassiveMode ($ sdata ->passiveMode );
80+ $ section ->setPurges ($ sdata ->purge );
81+ $ section ->setFilePermissions ($ sdata ->filePermissions );
82+ $ section ->setDirPermissions ($ sdata ->dirPermissions );
7383
7484 // Add to config
75- $ config ->addSection ($ section );
85+ $ config ->addSection ($ section );
86+ }
7687 }
7788
7889 return $ config ;
0 commit comments