|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the CoreSphereConsoleBundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Laszlo Korte <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CoreSphere\ConsoleBundle\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use CoreSphere\ConsoleBundle\Contract\Executer\CommandExecuterInterface; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
18
|
|
|
use Symfony\Component\Templating\EngineInterface; |
|
19
|
|
|
|
|
20
|
|
|
class ConsoleController |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var EngineInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
private $templating; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var CommandExecuterInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $commandExecuter; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var Application |
|
34
|
|
|
*/ |
|
35
|
|
|
private $application; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
private $environment; |
|
41
|
|
|
|
|
42
|
5 |
|
public function __construct( |
|
43
|
|
|
EngineInterface $templating, |
|
44
|
|
|
CommandExecuterInterface $commandExecuter, |
|
45
|
|
|
Application $application, |
|
46
|
|
|
$environment |
|
47
|
|
|
) { |
|
48
|
5 |
|
$this->templating = $templating; |
|
49
|
5 |
|
$this->commandExecuter = $commandExecuter; |
|
50
|
5 |
|
$this->application = $application; |
|
51
|
5 |
|
$this->environment = $environment; |
|
52
|
5 |
|
} |
|
53
|
|
|
|
|
54
|
3 |
|
public function consoleAction() |
|
55
|
|
|
{ |
|
56
|
3 |
|
return new Response( |
|
57
|
3 |
|
$this->templating->render('CoreSphereConsoleBundle:Console:console.html.twig', [ |
|
58
|
3 |
|
'working_dir' => getcwd(), |
|
59
|
3 |
|
'environment' => $this->environment, |
|
60
|
3 |
|
'commands' => $this->application->all(), |
|
61
|
3 |
|
]) |
|
62
|
3 |
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
2 |
|
public function execAction(Request $request) |
|
66
|
|
|
{ |
|
67
|
2 |
|
$commands = $request->request->get('commands'); |
|
68
|
2 |
|
$executedCommandsOutput = []; |
|
69
|
|
|
|
|
70
|
2 |
|
foreach ($commands as $command) { |
|
71
|
2 |
|
$result = $this->commandExecuter->execute($command); |
|
72
|
2 |
|
$executedCommandsOutput[] = $result; |
|
73
|
|
|
|
|
74
|
2 |
|
if (0 !== $result['error_code']) { |
|
75
|
1 |
|
break; |
|
76
|
|
|
} |
|
77
|
2 |
|
} |
|
78
|
|
|
|
|
79
|
2 |
|
return new Response( |
|
80
|
2 |
|
$this->templating->render( |
|
81
|
2 |
|
'CoreSphereConsoleBundle:Console:result.json.twig', |
|
82
|
2 |
|
['commands' => $executedCommandsOutput] |
|
83
|
2 |
|
) |
|
84
|
2 |
|
); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|