1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WebHemi. |
4
|
|
|
* |
5
|
|
|
* PHP version 7.2 |
6
|
|
|
* |
7
|
|
|
* @copyright 2012 - 2019 Gixx-web (http://www.gixx-web.com) |
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
9
|
|
|
* |
10
|
|
|
* @link http://www.gixx-web.com |
11
|
|
|
*/ |
12
|
|
|
declare(strict_types = 1); |
13
|
|
|
|
14
|
|
|
namespace WebHemi\Middleware\Action\Admin\ControlPanel\Applications; |
15
|
|
|
|
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
use WebHemi\Auth\ServiceInterface as AuthInterface; |
18
|
|
|
use WebHemi\Configuration\ServiceInterface as ConfigurationInterface; |
19
|
|
|
use WebHemi\CSRF\ServiceInterface as CSRFInterface; |
20
|
|
|
use WebHemi\Data\Entity\ApplicationEntity; |
21
|
|
|
use WebHemi\Data\Storage\ApplicationStorage; |
22
|
|
|
use WebHemi\Environment\ServiceInterface as EnvironmentInterface; |
23
|
|
|
use WebHemi\Form\PresetInterface; |
24
|
|
|
use WebHemi\Middleware\Action\AbstractMiddlewareAction; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class ViewAction. |
28
|
|
|
*/ |
29
|
|
|
class ViewAction extends AbstractMiddlewareAction |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var ConfigurationInterface |
33
|
|
|
*/ |
34
|
|
|
private $configuration; |
35
|
|
|
/** |
36
|
|
|
* @var AuthInterface |
37
|
|
|
*/ |
38
|
|
|
private $authAdapter; |
39
|
|
|
/** |
40
|
|
|
* @var EnvironmentInterface |
41
|
|
|
*/ |
42
|
|
|
private $environmentManager; |
43
|
|
|
/** |
44
|
|
|
* @var ApplicationStorage |
45
|
|
|
*/ |
46
|
|
|
private $applicationStorage; |
47
|
|
|
/** |
48
|
|
|
* @var PresetInterface |
49
|
|
|
*/ |
50
|
|
|
private $applicationFormPreset; |
51
|
|
|
/** |
52
|
|
|
* @var CSRFInterface |
53
|
|
|
*/ |
54
|
|
|
private $csrfAdapter; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* ViewAction constructor. |
58
|
|
|
* |
59
|
|
|
* @param ConfigurationInterface $configuration |
60
|
|
|
* @param AuthInterface $authAdapter |
61
|
|
|
* @param EnvironmentInterface $environmentManager |
62
|
|
|
* @param ApplicationStorage $applicationStorage |
63
|
|
|
* @param PresetInterface $applicationFormPreset |
64
|
|
|
* @param CSRFInterface $csrfAdapter |
65
|
|
|
*/ |
66
|
|
|
public function __construct( |
67
|
|
|
ConfigurationInterface $configuration, |
68
|
|
|
AuthInterface $authAdapter, |
69
|
|
|
EnvironmentInterface $environmentManager, |
70
|
|
|
ApplicationStorage $applicationStorage, |
71
|
|
|
PresetInterface $applicationFormPreset, |
72
|
|
|
CSRFInterface $csrfAdapter |
73
|
|
|
) { |
74
|
|
|
$this->configuration = $configuration; |
75
|
|
|
$this->authAdapter = $authAdapter; |
76
|
|
|
$this->environmentManager = $environmentManager; |
77
|
|
|
$this->applicationStorage = $applicationStorage; |
78
|
|
|
$this->applicationFormPreset = $applicationFormPreset; |
79
|
|
|
$this->csrfAdapter = $csrfAdapter; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Gets template map name or template file path. |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getTemplateName() : string |
88
|
|
|
{ |
89
|
|
|
return 'admin-control-panel-applications-view'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Gets template data. |
94
|
|
|
* |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
public function getTemplateData() : array |
98
|
|
|
{ |
99
|
|
|
$params = $this->getRoutingParameters(); |
100
|
|
|
|
101
|
|
|
$applicationName = $params['name'] ?? ''; |
102
|
|
|
$applicationEntity = $this->applicationStorage->getApplicationByName($applicationName); |
103
|
|
|
|
104
|
|
|
if (!$applicationEntity instanceof ApplicationEntity) { |
|
|
|
|
105
|
|
|
throw new InvalidArgumentException( |
106
|
|
|
sprintf('%s is not a valid application name', $applicationName), |
107
|
|
|
404 |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return [ |
112
|
|
|
'data' => $applicationEntity, |
113
|
|
|
'csrf' => $this->csrfAdapter->generate() |
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|