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
|
|
|
public function __construct( |
43
|
|
|
EngineInterface $templating, |
44
|
|
|
CommandExecuterInterface $commandExecuter, |
45
|
|
|
Application $application, |
46
|
|
|
$environment |
47
|
|
|
) { |
48
|
|
|
$this->templating = $templating; |
49
|
|
|
$this->commandExecuter = $commandExecuter; |
50
|
|
|
$this->application = $application; |
51
|
|
|
$this->environment = $environment; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function consoleAction() |
55
|
|
|
{ |
56
|
|
|
return new Response( |
57
|
|
|
$this->templating->render('CoreSphereConsoleBundle:Console:console.html.twig', [ |
58
|
|
|
'working_dir' => getcwd(), |
59
|
|
|
'environment' => $this->environment, |
60
|
|
|
'commands' => $this->application->all(), |
61
|
|
|
]) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function execAction(Request $request) |
66
|
|
|
{ |
67
|
|
|
$commands = $request->request->get('commands'); |
68
|
|
|
$executedCommandsOutput = []; |
69
|
|
|
|
70
|
|
|
foreach ($commands as $command) { |
71
|
|
|
$result = $this->commandExecuter->execute($command); |
72
|
|
|
$executedCommandsOutput[] = $result; |
73
|
|
|
|
74
|
|
|
if (0 !== $result['error_code']) { |
75
|
|
|
break; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return new Response( |
80
|
|
|
$this->templating->render( |
81
|
|
|
'CoreSphereConsoleBundle:Console:result.json.twig', |
82
|
|
|
['commands' => $executedCommandsOutput] |
83
|
|
|
) |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|