1616 */
1717class CliRunner
1818{
19- /** @var array */
20- public $ defaults = [
19+ public array $ defaults = [
2120 'local ' => '' ,
2221 'fileOutputDir ' => '' ,
2322 'passivemode ' => true ,
@@ -34,19 +33,17 @@ class CliRunner
3433 ];
3534
3635 /** @var string[] */
37- public $ ignoreMasks = ['*.bak ' , '.svn ' , '.git* ' , 'Thumbs.db ' , '.DS_Store ' , '.idea ' ];
36+ public array $ ignoreMasks = ['*.bak ' , '.svn ' , '.git* ' , 'Thumbs.db ' , '.DS_Store ' , '.idea ' ];
3837
39- /** @var Logger */
40- private $ logger ;
38+ private Logger $ logger ;
4139
42- /** @var string */
43- private $ configFile ;
40+ private string $ configFile ;
4441
45- /** @var string|null test|generate|null */
46- private $ mode ;
42+ /** test|generate|null */
43+ private ? string $ mode ;
4744
4845 /** @var array[] */
49- private $ batches = [];
46+ private array $ batches = [];
5047
5148
5249 public function run (): ?int
@@ -72,50 +69,48 @@ public function run(): ?int
7269 $ time = time ();
7370 $ this ->logger ->log ('Started at ' . date ('[Y/m/d H:i] ' ));
7471 $ this ->logger ->log ("Config file is $ this ->configFile " );
72+ $ res = 0 ;
7573
76- $ returnCode = 1 ;
7774
78- try {
79- foreach ($ this ->batches as $ name => $ batch ) {
80- $ this ->logger ->log ("\nDeploying $ name " );
75+ foreach ($ this ->batches as $ name => $ batch ) {
76+ $ this ->logger ->log ("\nDeploying $ name " );
8177
82- $ deployment = $ this ->createDeployer ($ batch );
83- $ deployment ->tempDir = $ tempDir ;
78+ $ deployment = $ this ->createDeployer ($ batch );
79+ $ deployment ->tempDir = $ tempDir ;
8480
85- if ($ this ->mode === 'generate ' ) {
86- $ this ->logger ->log ('Scanning files ' );
87- $ localPaths = $ deployment ->collectPaths ();
88- $ this ->logger ->log ('Saved ' . $ deployment ->writeDeploymentFile ($ localPaths ));
89- continue ;
90- }
91-
92- if ($ deployment ->testMode ) {
93- $ this ->logger ->log ('Test mode ' , 'lime ' );
94- } else if ($ deployment ->fileOutputDir ) {
95- $ this ->logger ->log ('File Output mode ' , 'teal ' );
96- } else {
97- $ this ->logger ->log ('Live mode ' , 'aqua ' );
98- }
99- if (!$ deployment ->allowDelete ) {
100- $ this ->logger ->log ('Deleting disabled ' );
101- }
81+ if ($ this ->mode === 'generate ' ) {
82+ $ this ->logger ->log ('Scanning files ' );
83+ $ localPaths = $ deployment ->collectPaths ();
84+ $ this ->logger ->log ('Saved ' . $ deployment ->writeDeploymentFile ($ localPaths ));
85+ continue ;
86+ }
10287
88+ if ($ deployment ->testMode ) {
89+ $ this ->logger ->log ('Test mode ' , 'lime ' );
90+ } else if ($ deployment ->fileOutputDir ) {
91+ $ this ->logger ->log ('File Output mode ' , 'teal ' );
92+ } else {
93+ $ this ->logger ->log ('Live mode ' , 'aqua ' );
94+ }
95+ if (!$ deployment ->allowDelete ) {
96+ $ this ->logger ->log ('Deleting disabled ' );
97+ }
10398
99+ try {
104100 $ deployment ->deploy ();
105- $ this ->logger ->log ("\n\n" );
101+ } catch (JobException | ServerException $ e ) {
102+ $ this ->logger ->log ("Error: {$ e ->getMessage ()} in {$ e ->getFile ()}: {$ e ->getLine ()}\n\n$ e " , 'red ' );
103+ $ res = 1 ;
106104 }
107- $ returnCode = 0 ;
108- } catch (JobException | ServerException $ e ) {
109- $ this ->logger ->log ("Error: {$ e ->getMessage ()} in {$ e ->getFile ()}: {$ e ->getLine ()}\n\n$ e " , 'red ' );
110105 $ this ->logger ->log ("\n\n" );
111106 }
112107
113108 $ time = time () - $ time ;
114109 $ this ->logger ->log (
115110 'Finished at ' . date ('[Y/m/d H:i] ' ) . " (in $ time seconds) \n---------------------------------------------- \n\n" ,
116- $ returnCode === 0 ? 'lime ' : 'red '
111+ $ res === 0 ? 'lime ' : 'red '
117112 );
118- return $ returnCode ;
113+ return $ res ;
119114 }
120115
121116
@@ -124,7 +119,7 @@ private function createDeployer(array $config): Deployer
124119 if (
125120 empty ($ config ['remote ' ])
126121 || !($ urlParts = parse_url ($ config ['remote ' ]))
127- || !isset ($ urlParts ['scheme ' ], $ urlParts [ ' host ' ] )
122+ || !isset ($ urlParts ['scheme ' ])
128123 ) {
129124 throw new \Exception ("Missing or invalid 'remote' URL in config. " );
130125 }
@@ -191,8 +186,10 @@ private function createDeployer(array $config): Deployer
191186 $ deployment ->deploymentFile = empty ($ config ['deploymentfile ' ])
192187 ? $ deployment ->deploymentFile
193188 : $ config ['deploymentfile ' ];
194- $ deployment ->allowDelete = $ config ['allowdelete ' ];
195- $ deployment ->alwaysRunActions = $ config ['alwaysrunactions ' ];
189+
190+ $ deployment ->allowDelete = (bool ) $ config ['allowdelete ' ];
191+ $ deployment ->alwaysRunActions = (bool )$ config ['alwaysrunactions ' ];
192+
196193 $ deployment ->toPurge = self ::toArray ($ config ['purge ' ], true );
197194 $ deployment ->runBefore = self ::toArray ($ config ['before ' ], true );
198195 $ deployment ->runAfterUpload = self ::toArray ($ config ['afterupload ' ], true );
@@ -241,23 +238,24 @@ private function setupPhp(): void
241238
242239 private function loadConfig (): ?array
243240 {
244- $ cmd = new CommandLine (<<<'XX'
245241
246- FTP deployment v3.4 - Pavel Kutáč edit
242+ $ cmd = new CommandLine (
243+ <<<'XX'
244+ FTP deployment v3.5 - Pavel Kutáč edit
247245
248- See more on https://github.com/arxeiss/ftp-deployment
249- and original on https://github.com/dg/ftp-deployment
250- -------------------
251- Usage:
252- deployment <config_file> [-t | --test]
246+ See more on https://github.com/arxeiss/ftp-deployment
247+ and original on https://github.com/dg/ftp-deployment
248+ -------------------
249+ Usage:
250+ deployment <config_file> [-t | --test]
253251
254- Options:
255- -t | --test Run in test-mode.
256- --section <name> Only deploys the named section.
257- --generate Only generates deployment file.
258- --no-progress Hide the progress indicators.
252+ Options:
253+ -t | --test Run in test-mode.
254+ --section <name> Only deploys the named section.
255+ --generate Only generates deployment file.
256+ --no-progress Hide the progress indicators.
259257
260- XX
258+ XX
261259 , [
262260 'config ' => [CommandLine::REALPATH => true ],
263261 ]);
0 commit comments