1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Leonidas\Console\Library\Printer\Model; |
4
|
|
|
|
5
|
|
|
use Leonidas\Console\Library\Printer\Model\Abstracts\AbstractClassPrinter; |
6
|
|
|
use Leonidas\Contracts\System\Model\CommentableInterface; |
7
|
|
|
use Leonidas\Contracts\System\Model\FilterableInterface; |
8
|
|
|
use Leonidas\Contracts\System\Model\HierarchicalInterface; |
9
|
|
|
use Leonidas\Contracts\System\Model\MimeInterface; |
10
|
|
|
use Leonidas\Contracts\System\Model\MutableAuthoredInterface; |
11
|
|
|
use Leonidas\Contracts\System\Model\MutableContentInterface; |
12
|
|
|
use Leonidas\Contracts\System\Model\MutableDatableInterface; |
13
|
|
|
use Leonidas\Contracts\System\Model\MutablePostModelInterface; |
14
|
|
|
use Leonidas\Contracts\System\Model\MutableTermModelInterface; |
15
|
|
|
use Leonidas\Contracts\System\Model\MutableUserModelInterface; |
16
|
|
|
use Leonidas\Contracts\System\Model\PingableInterface; |
17
|
|
|
use Leonidas\Contracts\System\Model\RestrictableInterface; |
18
|
|
|
use Nette\PhpGenerator\PhpNamespace; |
19
|
|
|
use Stringable; |
20
|
|
|
|
21
|
|
|
class ModelInterfacePrinter extends AbstractClassPrinter |
22
|
|
|
{ |
23
|
|
|
protected const PARTIALS = [ |
24
|
|
|
'post' => [ |
25
|
|
|
FilterableInterface::class, |
26
|
|
|
MutableAuthoredInterface::class, |
27
|
|
|
MutableContentInterface::class, |
28
|
|
|
MutablePostModelInterface::class, |
29
|
|
|
PingableInterface::class, |
30
|
|
|
CommentableInterface::class, |
31
|
|
|
RestrictableInterface::class, |
32
|
|
|
MimeInterface::class, |
33
|
|
|
MutableDatableInterface::class, |
34
|
|
|
], |
35
|
|
|
'post:h' => [ |
36
|
|
|
'@post', |
37
|
|
|
HierarchicalInterface::class, |
38
|
|
|
], |
39
|
|
|
'attachment' => [ |
40
|
|
|
'@post', |
41
|
|
|
], |
42
|
|
|
'term' => [ |
43
|
|
|
MutableTermModelInterface::class, |
44
|
|
|
], |
45
|
|
|
'term:h' => [ |
46
|
|
|
'@term', |
47
|
|
|
HierarchicalInterface::class, |
48
|
|
|
], |
49
|
|
|
'user' => [ |
50
|
|
|
MutableUserModelInterface::class, |
51
|
|
|
], |
52
|
|
|
'comment' => [ |
53
|
|
|
HierarchicalInterface::class, |
54
|
|
|
Stringable::class, |
55
|
|
|
], |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
protected string $template; |
59
|
|
|
|
60
|
|
|
public function __construct(string $namespace, string $class, string $template = 'post') |
61
|
|
|
{ |
62
|
|
|
parent::__construct($namespace, $class); |
63
|
|
|
|
64
|
|
|
$this->template = $template; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function setupClass(PhpNamespace $namespace): object |
68
|
|
|
{ |
69
|
|
|
$interface = $namespace->addInterface($this->class); |
70
|
|
|
|
71
|
|
|
foreach ($this->getResolvedPartials() as $partial) { |
72
|
|
|
$namespace->addUse($partial); |
73
|
|
|
$interface->addExtend($partial); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $interface; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function getResolvedPartials(): array |
80
|
|
|
{ |
81
|
|
|
$partials = []; |
82
|
|
|
|
83
|
|
|
foreach (static::PARTIALS[$this->template] as $partial) { |
84
|
|
|
if (str_starts_with($partial, '@')) { |
85
|
|
|
$inherit = static::PARTIALS[substr($partial, 1)]; |
86
|
|
|
|
87
|
|
|
$partials = [...array_values($inherit), ...$partials]; |
88
|
|
|
} else { |
89
|
|
|
$partials[] = $partial; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $partials; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|