|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 7.1 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2017 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\Data\Entity\ApplicationEntity; |
|
20
|
|
|
use WebHemi\Data\Storage\ApplicationStorage; |
|
21
|
|
|
use WebHemi\Environment\ServiceInterface as EnvironmentInterface; |
|
22
|
|
|
use WebHemi\Middleware\Action\AbstractMiddlewareAction; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class DeleteAction. |
|
26
|
|
|
*/ |
|
27
|
|
View Code Duplication |
class DeleteAction extends AbstractMiddlewareAction |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
/** @var ConfigurationInterface */ |
|
30
|
|
|
private $configuration; |
|
31
|
|
|
/** @var AuthInterface */ |
|
32
|
|
|
private $authAdapter; |
|
33
|
|
|
/** @var EnvironmentInterface */ |
|
34
|
|
|
private $environmentManager; |
|
35
|
|
|
/** @var ApplicationStorage */ |
|
36
|
|
|
private $applicationStorage; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* DeleteAction constructor. |
|
40
|
|
|
* |
|
41
|
|
|
* @param ConfigurationInterface $configuration |
|
42
|
|
|
* @param AuthInterface $authAdapter |
|
43
|
|
|
* @param EnvironmentInterface $environmentManager |
|
44
|
|
|
* @parem ApplicationStorage $applicationStorage |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct( |
|
47
|
|
|
ConfigurationInterface $configuration, |
|
48
|
|
|
AuthInterface $authAdapter, |
|
49
|
|
|
EnvironmentInterface $environmentManager, |
|
50
|
|
|
ApplicationStorage $applicationStorage |
|
51
|
|
|
) { |
|
52
|
|
|
$this->configuration = $configuration; |
|
53
|
|
|
$this->authAdapter = $authAdapter; |
|
54
|
|
|
$this->environmentManager = $environmentManager; |
|
55
|
|
|
$this->applicationStorage = $applicationStorage; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Gets template map name or template file path. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getTemplateName() : string |
|
64
|
|
|
{ |
|
65
|
|
|
return 'admin-applications-delete'; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Gets template data. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getTemplateData() : array |
|
74
|
|
|
{ |
|
75
|
|
|
$params = $this->getRoutingParameters(); |
|
76
|
|
|
$applicationName = $params['name'] ?? ''; |
|
77
|
|
|
$applicationEntity = $this->applicationStorage->getApplicationByName($applicationName); |
|
78
|
|
|
|
|
79
|
|
|
if (!$applicationEntity instanceof ApplicationEntity) { |
|
80
|
|
|
throw new InvalidArgumentException( |
|
81
|
|
|
sprintf('%s is not a valid application name', $applicationName), |
|
82
|
|
|
404 |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return [ |
|
87
|
|
|
'application' => $applicationEntity |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.