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\PageCategory as Entity; |
10
|
|
|
use AbterPhp\Website\Orm\PageCategoryRepo as GridRepo; |
11
|
|
|
use AbterPhp\Website\Validation\Factory\PageCategory as ValidatorFactory; |
12
|
|
|
use Cocur\Slugify\Slugify; |
13
|
|
|
use Opulence\Events\Dispatchers\IEventDispatcher; |
14
|
|
|
use Opulence\Orm\IUnitOfWork; |
15
|
|
|
|
16
|
|
|
class PageCategory extends RepoServiceAbstract |
17
|
|
|
{ |
18
|
|
|
/** @var Slugify */ |
19
|
|
|
protected $slugify; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* PageCategory constructor. |
23
|
|
|
* |
24
|
|
|
* @param GridRepo $repo |
25
|
|
|
* @param ValidatorFactory $validatorFactory |
26
|
|
|
* @param IUnitOfWork $unitOfWork |
27
|
|
|
* @param IEventDispatcher $eventDispatcher |
28
|
|
|
* @param Slugify $slugify |
29
|
|
|
*/ |
30
|
|
|
public function __construct( |
31
|
|
|
GridRepo $repo, |
32
|
|
|
ValidatorFactory $validatorFactory, |
33
|
|
|
IUnitOfWork $unitOfWork, |
34
|
|
|
IEventDispatcher $eventDispatcher, |
35
|
|
|
Slugify $slugify |
36
|
|
|
) { |
37
|
|
|
parent::__construct($repo, $validatorFactory, $unitOfWork, $eventDispatcher); |
38
|
|
|
|
39
|
|
|
$this->slugify = $slugify; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $entityId |
45
|
|
|
* |
46
|
|
|
* @return Entity |
47
|
|
|
*/ |
48
|
|
|
protected function createEntity(string $entityId): IStringerEntity |
49
|
|
|
{ |
50
|
|
|
return new Entity($entityId, '', ''); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Entity $entity |
55
|
|
|
* @param array $data |
56
|
|
|
* |
57
|
|
|
* @return Entity |
58
|
|
|
*/ |
59
|
|
|
protected function fillEntity(IStringerEntity $entity, array $data): IStringerEntity |
60
|
|
|
{ |
61
|
|
|
if (empty($data['identifier'])) { |
62
|
|
|
$data['identifier'] = $data['name']; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$identifier = $this->slugify->slugify((string)$data['identifier']); |
66
|
|
|
|
67
|
|
|
$entity |
68
|
|
|
->setIdentifier($identifier) |
|
|
|
|
69
|
|
|
->setName((string)$data['name']) |
70
|
|
|
; |
71
|
|
|
|
72
|
|
|
return $entity; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|