1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SensioLabs\AnsiConverter\AnsiToHtmlConverter; |
4
|
|
|
use Symfony\Component\Console\Application; |
5
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
6
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
7
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
8
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ConsoleController |
13
|
|
|
* The Central Command Access Point and Bootstrapper. |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
|
|
class ConsoleController extends Controller |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
private static $allowed_actions = [ |
|
|
|
|
22
|
|
|
'publish', |
23
|
|
|
'ConsoleForm', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var SilverstripeApplication |
28
|
|
|
*/ |
29
|
|
|
protected $application; |
30
|
|
|
|
31
|
|
|
public function init() |
32
|
|
|
{ |
33
|
|
|
parent::init(); |
34
|
|
|
|
35
|
|
|
$this->application = new SilverstripeApplication(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function index(SS_HTTPRequest $request) |
39
|
|
|
{ |
40
|
|
|
/* |
41
|
|
|
* Lets be clear when calling commands |
42
|
|
|
*/ |
43
|
|
|
ini_set('display_errors', 1); |
44
|
|
|
|
45
|
|
|
if (!Director::is_cli()) { |
46
|
|
|
if (!Permission::check('ADMIN')) { |
47
|
|
|
return Security::permissionFailure(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->callFromBrowser($request); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->callFromConsole(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function callFromConsole() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
// remove the framework/cli-script.php argument |
59
|
|
|
array_shift($_SERVER['argv']); |
60
|
|
|
|
61
|
|
|
$this->application->run(new ArgvInput($_SERVER['argv']), new ConsoleOutput()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function callFromBrowser(SS_HTTPRequest $request) |
65
|
|
|
{ |
66
|
|
|
$input = new ArrayInput([ |
67
|
|
|
'command' => $request->param('ID'), |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
$output = new BufferedOutput( |
71
|
|
|
OutputInterface::VERBOSITY_NORMAL, |
72
|
|
|
true // true for decorated |
73
|
|
|
); |
74
|
|
|
$this->application->run($input, $output); |
75
|
|
|
|
76
|
|
|
// return the output |
77
|
|
|
$converter = new AnsiToHtmlConverter(); |
78
|
|
|
$content = $output->fetch(); |
79
|
|
|
|
80
|
|
|
return ['ConsoleOutput' => $converter->convert($content)]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return ConsoleForm |
85
|
|
|
*/ |
86
|
|
|
public function ConsoleForm() |
87
|
|
|
{ |
88
|
|
|
return new ConsoleForm($this, 'ConsoleForm'); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.