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 Exception; |
17
|
|
|
use WebHemi\Form\ServiceAdapter\Base\ServiceAdapter as HtmlForm; |
18
|
|
|
use WebHemi\Http\ServerRequestInterface; |
19
|
|
|
use WebHemi\Http\ResponseInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class AddAction. |
23
|
|
|
*/ |
24
|
|
|
class AddAction extends ListAction |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Gets template map name or template file path. |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function getTemplateName() : string |
32
|
|
|
{ |
33
|
|
|
return 'admin-control-panel-applications-add'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Gets template data. |
38
|
|
|
* |
39
|
|
|
* @throws Exception |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public function getTemplateData() : array |
43
|
|
|
{ |
44
|
|
|
// TODO complete form |
45
|
|
|
/** @var array $postData */ |
46
|
|
|
$postData = $this->request->getParsedBody(); |
47
|
|
|
/** @var HtmlForm $form */ |
48
|
|
|
$form = $this->applicationFormPreset->getPreset(); |
49
|
|
|
$form->loadData($postData); |
50
|
|
|
|
51
|
|
|
if ($form->validate()) { |
|
|
|
|
52
|
|
|
// TODO validate name |
53
|
|
|
// * in case of domain: no other application with the same domain (== name) |
54
|
|
|
// * in case of directory: no other application with the same path (== name) |
55
|
|
|
// + no filesystem path within the same path |
56
|
|
|
} else { |
57
|
|
|
throw new Exception('Form validation failed', ResponseInterface::STATUS_BAD_REQUEST); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$applicationUri = $this->request->getAttribute(ServerRequestInterface::REQUEST_ATTR_APPLICATION_URI); |
61
|
|
|
|
62
|
|
|
$this->response = $this->response |
63
|
|
|
->withStatus(ResponseInterface::STATUS_REDIRECT, 'Found') |
64
|
|
|
->withHeader('Location', $applicationUri.'applications'); |
65
|
|
|
|
66
|
|
|
return []; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.