1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Leonidas\Console\Library\Printer\Model\Abstracts; |
4
|
|
|
|
5
|
|
|
abstract class AbstractModelRepositoryPrinter extends AbstractClassPrinter |
6
|
|
|
{ |
7
|
|
|
public const CORE = 'manager'; |
8
|
|
|
|
9
|
|
|
public const SIGNATURES = [ |
10
|
|
|
'select' => [ |
11
|
|
|
'take' => 'int $id', |
12
|
|
|
'give' => '@model', |
13
|
|
|
'pass' => '$id', |
14
|
|
|
], |
15
|
|
|
'whereIds' => [ |
16
|
|
|
'take' => 'int ...$ids', |
17
|
|
|
'give' => '@collection', |
18
|
|
|
'pass' => '...$ids', |
19
|
|
|
], |
20
|
|
|
'query' => [ |
21
|
|
|
'take' => 'array $query', |
22
|
|
|
'give' => '@collection', |
23
|
|
|
'pass' => '$query', |
24
|
|
|
], |
25
|
|
|
'all' => [ |
26
|
|
|
'give' => '@collection', |
27
|
|
|
], |
28
|
|
|
'make' => [ |
29
|
|
|
'take' => 'array $data', |
30
|
|
|
'give' => '@model', |
31
|
|
|
'call' => 'spawn', |
32
|
|
|
'pass' => '$data', |
33
|
|
|
], |
34
|
|
|
'insert' => [ |
35
|
|
|
'take' => '@model @single', |
36
|
|
|
'pass' => '$this->extractData($@single)', |
37
|
|
|
], |
38
|
|
|
'update' => [ |
39
|
|
|
'take' => '@model @single', |
40
|
|
|
'pass' => '$@single->getId(), $this->extractData($@single)', |
41
|
|
|
], |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
protected string $model; |
45
|
|
|
|
46
|
|
|
protected string $collection; |
47
|
|
|
|
48
|
|
|
protected string $single; |
49
|
|
|
|
50
|
|
|
protected string $plural; |
51
|
|
|
|
52
|
|
|
protected string $template; |
53
|
|
|
|
54
|
|
|
public function __construct( |
55
|
|
|
string $model, |
56
|
|
|
string $collection, |
57
|
|
|
string $single, |
58
|
|
|
string $plural, |
59
|
|
|
string $namespace, |
60
|
|
|
string $class, |
61
|
|
|
string $template |
62
|
|
|
) { |
63
|
|
|
parent::__construct($namespace, $class); |
64
|
|
|
|
65
|
|
|
$this->model = $model; |
66
|
|
|
$this->collection = $collection; |
67
|
|
|
$this->single = $single; |
68
|
|
|
$this->plural = $plural; |
69
|
|
|
$this->template = $template; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function getMethodPassReplacements(): array |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
['@single', '@plural'], |
76
|
|
|
[$this->single, $this->plural], |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function getMethodGiveReplacements(): array |
81
|
|
|
{ |
82
|
|
|
return [ |
83
|
|
|
['@model', '@collection'], |
84
|
|
|
[$this->model, $this->collection], |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function getParameterTypeReplacements(): array |
89
|
|
|
{ |
90
|
|
|
return [ |
91
|
|
|
['@model', '@type'], |
92
|
|
|
[$this->model, $this->getClassFqn()], |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
protected function getParameterNameReplacements(): array |
97
|
|
|
{ |
98
|
|
|
return [ |
99
|
|
|
['@single'], |
100
|
|
|
[$this->single], |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|