|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Console\Library\Printer\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Leonidas\Console\Library\Printer\Model\Abstracts\AbstractModelRepositoryPrinter; |
|
6
|
|
|
use Leonidas\Console\Library\Printer\Model\Abstracts\TypedClassPrinterTrait; |
|
7
|
|
|
use Leonidas\Library\System\Model\Abstracts\Attachment\AbstractAttachmentEntityRepository; |
|
8
|
|
|
use Leonidas\Library\System\Model\Abstracts\Comment\AbstractCommentModelRepositoryInterface; |
|
9
|
|
|
use Leonidas\Library\System\Model\Abstracts\Post\AbstractPostEntityRepository; |
|
10
|
|
|
use Leonidas\Library\System\Model\Abstracts\Term\AbstractTermEntityRepository; |
|
11
|
|
|
use Leonidas\Library\System\Model\Abstracts\User\AbstractUserModelRepository; |
|
12
|
|
|
use Nette\PhpGenerator\PhpNamespace; |
|
13
|
|
|
|
|
14
|
|
|
class ModelRepositoryPrinter extends AbstractModelRepositoryPrinter |
|
15
|
|
|
{ |
|
16
|
|
|
use TypedClassPrinterTrait; |
|
17
|
|
|
|
|
18
|
|
|
public const ABSTRACTS = [ |
|
19
|
|
|
'post' => AbstractPostEntityRepository::class, |
|
20
|
|
|
'post:h' => AbstractPostEntityRepository::class, |
|
21
|
|
|
'attachment' => AbstractAttachmentEntityRepository::class, |
|
22
|
|
|
'term' => AbstractTermEntityRepository::class, |
|
23
|
|
|
'term:h' => AbstractTermEntityRepository::class, |
|
24
|
|
|
'user' => AbstractUserModelRepository::class, |
|
25
|
|
|
'comment' => AbstractCommentModelRepositoryInterface::class, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
protected string $template; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct( |
|
31
|
|
|
string $model, |
|
32
|
|
|
string $collection, |
|
33
|
|
|
string $single, |
|
34
|
|
|
string $plural, |
|
35
|
|
|
string $namespace, |
|
36
|
|
|
string $class, |
|
37
|
|
|
string $type, |
|
38
|
|
|
string $template = 'post' |
|
39
|
|
|
) { |
|
40
|
|
|
parent::__construct( |
|
41
|
|
|
$model, |
|
42
|
|
|
$collection, |
|
43
|
|
|
$single, |
|
44
|
|
|
$plural, |
|
45
|
|
|
$namespace, |
|
46
|
|
|
$class, |
|
47
|
|
|
$template |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
$this->type = $type; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function setupClass(PhpNamespace $namespace): object |
|
54
|
|
|
{ |
|
55
|
|
|
return $namespace |
|
56
|
|
|
->addUse($this->model) |
|
57
|
|
|
->addUse($this->collection) |
|
58
|
|
|
->addUse($this->type) |
|
59
|
|
|
->addUse($parent = static::ABSTRACTS[$this->template]) |
|
60
|
|
|
->addClass($this->class) |
|
61
|
|
|
->setExtends($parent) |
|
62
|
|
|
->addImplement($this->type); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function finishClass($class): void |
|
66
|
|
|
{ |
|
67
|
|
|
$data = $class->addMethod('extractData') |
|
68
|
|
|
->setVisibility('protected') |
|
69
|
|
|
->setReturnType('array') |
|
70
|
|
|
->setBody('return [];'); |
|
71
|
|
|
|
|
72
|
|
|
$data->addParameter($this->single)->setType($this->model); |
|
73
|
|
|
|
|
74
|
|
|
if (in_array($this->template, ['post', 'attachment'])) { |
|
75
|
|
|
$tax = $class->addMethod('extractTaxInput') |
|
76
|
|
|
->setVisibility('protected') |
|
77
|
|
|
->setReturnType('array') |
|
78
|
|
|
->setBody('return [];'); |
|
79
|
|
|
|
|
80
|
|
|
$tax->addParameter($this->single)->setType($this->model); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$meta = $class->addMethod('extractMetaInput') |
|
84
|
|
|
->setVisibility('protected') |
|
85
|
|
|
->setReturnType('array') |
|
86
|
|
|
->setBody('return [];'); |
|
87
|
|
|
|
|
88
|
|
|
$meta->addParameter($this->single)->setType($this->model); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|