|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 7.1 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2018 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\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\Middleware\Action\AbstractMiddlewareAction; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class EditAction |
|
27
|
|
|
*/ |
|
28
|
|
|
class EditAction extends AbstractMiddlewareAction |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var ConfigurationInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $configuration; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var AuthInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
private $authAdapter; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var EnvironmentInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $environmentManager; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var ApplicationStorage |
|
44
|
|
|
*/ |
|
45
|
|
|
private $applicationStorage; |
|
46
|
|
|
/** |
|
47
|
|
|
* @var CSRFInterface |
|
48
|
|
|
*/ |
|
49
|
|
|
private $csrfAdapter; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* EditAction constructor. |
|
53
|
|
|
* |
|
54
|
|
|
* @param ConfigurationInterface $configuration |
|
55
|
|
|
* @param AuthInterface $authAdapter |
|
56
|
|
|
* @param EnvironmentInterface $environmentManager |
|
57
|
|
|
* @parem ApplicationStorage $applicationStorage |
|
58
|
|
|
* @param CSRFInterface $csrfAdapter |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __construct( |
|
61
|
|
|
ConfigurationInterface $configuration, |
|
62
|
|
|
AuthInterface $authAdapter, |
|
63
|
|
|
EnvironmentInterface $environmentManager, |
|
64
|
|
|
ApplicationStorage $applicationStorage, |
|
65
|
|
|
CSRFInterface $csrfAdapter |
|
66
|
|
|
) { |
|
67
|
|
|
$this->configuration = $configuration; |
|
68
|
|
|
$this->authAdapter = $authAdapter; |
|
69
|
|
|
$this->environmentManager = $environmentManager; |
|
70
|
|
|
$this->applicationStorage = $applicationStorage; |
|
71
|
|
|
$this->csrfAdapter = $csrfAdapter; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Gets template map name or template file path. |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getTemplateName() : string |
|
80
|
|
|
{ |
|
81
|
|
|
return 'admin-applications-edit'; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Gets template data. |
|
86
|
|
|
* |
|
87
|
|
|
* @return array |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getTemplateData() : array |
|
90
|
|
|
{ |
|
91
|
|
|
$params = $this->getRoutingParameters(); |
|
92
|
|
|
$applicationName = $params['name'] ?? ''; |
|
93
|
|
|
$applicationEntity = $this->applicationStorage->getApplicationByName($applicationName); |
|
94
|
|
|
|
|
95
|
|
|
if (!$applicationEntity instanceof ApplicationEntity) { |
|
|
|
|
|
|
96
|
|
|
throw new InvalidArgumentException( |
|
97
|
|
|
sprintf('%s is not a valid application name', $applicationName), |
|
98
|
|
|
404 |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return [ |
|
103
|
|
|
'application' => $applicationEntity |
|
104
|
|
|
]; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|