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