Passed
Push — master ( d5adc1...45b033 )
by Fabio
06:12
created

TAppAction::performAction()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 17
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 22
rs 9.7
1
<?php
2
/**
3
 * TAppAction class file
4
 *
5
 * @author Brad Anderson <[email protected]>
6
 * @link https://github.com/pradosoft/prado
7
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
8
 * @package Prado\Shell\Actions
9
 */
10
11
namespace Prado\Shell\Actions;
12
13
use Prado\Shell\TShellInterpreter;
14
use Prado\Shell\TShellAction;
15
16
/**
17
 * Creates and run Prado application specific commands.
18
 *
19
 * @author Brad Anderson <belisoful[at]icloud[dot]com>
20
 * @package Prado\Shell\Actions
21
 * @since 4.2.0
22
 */
23
class TAppAction extends TShellAction
24
{
25
	protected $action = 'app';
26
	protected $parameters = [];
27
	protected $optional = ['directory', 'app-action'];
28
	protected $description = 'Initializes the Prado application in the given [directory] and performs the app action';
29
30
	/**
31
	 * @param array $args parameters
32
	 * @return bool
33
	 */
34
	public function performAction($args)
35
	{
36
		$app = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $app is dead and can be removed.
Loading history...
37
		if (count($args) == 1) {
38
			$args[1] = '.';
39
		}
40
		if (false === ($xml = $this->getAppConfigFile($args[1]))) {
0 ignored issues
show
Unused Code introduced by
The assignment to $xml is dead and can be removed.
Loading history...
41
			echo "** Application '$args[1]' was not found. \n";
42
			return false;
43
		}
44
		$app = $this->initializePradoApplication($args[1]);
45
		TShellInterpreter::getInstance()->clearActionClass();
46
		TShellInterpreter::getInstance()->addActionClass('Prado\\Shell\\Actions\\TAppHelpAction');
47
		foreach ($app->getShellActionClasses() as $actions) {
48
			TShellInterpreter::getInstance()->addActionClass($actions);
49
		}
50
		$app->onLoadState();
51
		$app->onLoadStateComplete();
52
		TShellInterpreter::getInstance()->run($_SERVER['argv']);
53
		$app->onSaveState();
54
		$app->onSaveStateComplete();
55
		return true;
56
	}
57
}
58