1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Service\Execute; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Domain\Entities\IStringerEntity; |
8
|
|
|
use AbterPhp\Framework\Http\Service\Execute\RepoServiceAbstract; |
9
|
|
|
use AbterPhp\Website\Domain\Entities\PageLayout as Entity; |
10
|
|
|
use AbterPhp\Website\Domain\Entities\PageLayout\Assets; |
11
|
|
|
use AbterPhp\Website\Orm\PageLayoutRepo as GridRepo; |
12
|
|
|
use AbterPhp\Website\Validation\Factory\PageLayout as ValidatorFactory; |
13
|
|
|
use Cocur\Slugify\Slugify; |
14
|
|
|
use Opulence\Events\Dispatchers\IEventDispatcher; |
15
|
|
|
use Opulence\Http\Requests\UploadedFile; |
16
|
|
|
use Opulence\Orm\IUnitOfWork; |
17
|
|
|
|
18
|
|
|
class PageLayout extends RepoServiceAbstract |
19
|
|
|
{ |
20
|
|
|
/** @var Slugify */ |
21
|
|
|
protected $slugify; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* PageLayout constructor. |
25
|
|
|
* |
26
|
|
|
* @param GridRepo $repo |
27
|
|
|
* @param ValidatorFactory $validatorFactory |
28
|
|
|
* @param IUnitOfWork $unitOfWork |
29
|
|
|
* @param IEventDispatcher $eventDispatcher |
30
|
|
|
* @param Slugify $slugify |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
GridRepo $repo, |
34
|
|
|
ValidatorFactory $validatorFactory, |
35
|
|
|
IUnitOfWork $unitOfWork, |
36
|
|
|
IEventDispatcher $eventDispatcher, |
37
|
|
|
Slugify $slugify |
38
|
|
|
) { |
39
|
|
|
parent::__construct($repo, $validatorFactory, $unitOfWork, $eventDispatcher); |
40
|
|
|
|
41
|
|
|
$this->slugify = $slugify; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $entityId |
47
|
|
|
* |
48
|
|
|
* @return Entity |
49
|
|
|
*/ |
50
|
|
|
public function createEntity(string $entityId): IStringerEntity |
51
|
|
|
{ |
52
|
|
|
return new Entity($entityId, '', '', new Assets('', '', '', [], [])); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
57
|
|
|
* |
58
|
|
|
* @param Entity $entity |
59
|
|
|
* @param array $postData |
60
|
|
|
* @param UploadedFile[] $fileData |
61
|
|
|
* |
62
|
|
|
* @return Entity |
63
|
|
|
*/ |
64
|
|
|
protected function fillEntity(IStringerEntity $entity, array $postData, array $fileData): IStringerEntity |
65
|
|
|
{ |
66
|
|
|
$identifier = $this->slugify->slugify((string)$postData['identifier']); |
67
|
|
|
|
68
|
|
|
$assets = $this->createAssets($postData); |
69
|
|
|
|
70
|
|
|
$entity |
71
|
|
|
->setIdentifier($identifier) |
|
|
|
|
72
|
|
|
->setBody((string)$postData['body']) |
73
|
|
|
->setAssets($assets) |
74
|
|
|
; |
75
|
|
|
|
76
|
|
|
return $entity; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param array $postData |
81
|
|
|
* |
82
|
|
|
* @return Assets |
83
|
|
|
*/ |
84
|
|
|
protected function createAssets(array $postData): Assets |
85
|
|
|
{ |
86
|
|
|
if (is_string($postData['css-files'])) { |
87
|
|
|
$postData['css-files'] = explode('\r\n', $postData['css-files']); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (is_string($postData['js-files'])) { |
91
|
|
|
$postData['js-files'] = explode('\r\n', $postData['js-files']); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return new Assets( |
95
|
|
|
$postData['identifier'], |
96
|
|
|
$postData['header'], |
97
|
|
|
$postData['footer'], |
98
|
|
|
$postData['css-files'], |
99
|
|
|
$postData['js-files'] |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|