-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminController.php
94 lines (76 loc) · 2.08 KB
/
AdminController.php
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
89
90
91
92
93
<?php
/**
* @package ImpressPages
*/
/**
* Created by PhpStorm.
* User: maskas
* Date: 16.2.26
* Time: 16.29
*/
namespace Plugin\Composer;
use Composer\Installer;
use Ip\Form;
use Ip\Form\Field;
use Ip\Response\Json;
class AdminController
{
public function index()
{
ipAddCss('assets/php.css');
ipAddCss('assets/codeEditorField.css');
ipAddJs('assets/src-noconflict/ace.js');
ipAddJs('assets/initCodeEditorField.js');
ipAddCss('assets/admin.css');
ipAddJs('assets/admin.js');
$form = new Form();
$form->addClass('composerJsonForm');
$form->addClass('ipsComposerJsonForm');
$form->addClass('hidden');
$field = new CodeEditor([
'name' => 'rawCode',
'layout' => Field::LAYOUT_NO_LABEL,
'value' => Service::getConfig(),
'mode' => 'json',
'css' => 'ipPluginPhp-editor',
]);
$form->addField($field);
$params = [
'composerJson' => Service::getConfig(),
'form' => $form
];
return ipView('view/admin.php', $params);
}
public function saveConfig()
{
ipRequest()->mustBePost();
$config = ipRequest()->getPost('config');
Service::setConfig($config);
}
public function executeComposerCommand()
{
ipRequest()->mustBePost();
$command = ipRequest()->getPost('command');
switch ($command) {
case 'install':
$answer = Service::install();
break;
case 'update':
$answer = Service::update();
break;
case 'clearcache':
$answer = Service::clearCache();
break;
case 'version':
$answer = Service::version();
break;
default:
throw new \Ip\Exception('Unknown Composer command');
}
$answer = nl2br(esc($answer));
$result = [
'result' => $answer
];
return new Json($result);
}
}