|
3 | 3 | namespace Blueprint\Generators\Statements;
|
4 | 4 |
|
5 | 5 | use Blueprint\Blueprint;
|
6 |
| -use Blueprint\Contracts\Generator; |
| 6 | +use Blueprint\Generators\StatementGenerator; |
7 | 7 | use Blueprint\Models\Statements\DispatchStatement;
|
8 | 8 | use Blueprint\Tree;
|
9 | 9 |
|
10 |
| -class JobGenerator implements Generator |
| 10 | +class JobGenerator extends StatementGenerator |
11 | 11 | {
|
12 |
| - /** |
13 |
| - * @var \Illuminate\Contracts\Filesystem\Filesystem |
14 |
| - */ |
15 |
| - private $files; |
16 |
| - |
17 |
| - public function __construct($files) |
18 |
| - { |
19 |
| - $this->files = $files; |
20 |
| - } |
| 12 | + protected $new_instance = 'new job instance'; |
21 | 13 |
|
22 | 14 | public function output(Tree $tree): array
|
23 | 15 | {
|
@@ -71,50 +63,4 @@ protected function populateStub(string $stub, DispatchStatement $dispatchStateme
|
71 | 63 |
|
72 | 64 | return $stub;
|
73 | 65 | }
|
74 |
| - |
75 |
| - protected function buildConstructor(DispatchStatement $dispatchStatement) |
76 |
| - { |
77 |
| - static $constructor = null; |
78 |
| - |
79 |
| - if (is_null($constructor)) { |
80 |
| - $constructor = str_replace('new instance', 'new job instance', $this->files->stub('partials/constructor.stub')); |
81 |
| - } |
82 |
| - |
83 |
| - if (empty($dispatchStatement->data())) { |
84 |
| - return trim($constructor); |
85 |
| - } |
86 |
| - |
87 |
| - $stub = $this->buildProperties($dispatchStatement->data()).PHP_EOL.PHP_EOL; |
88 |
| - $stub .= str_replace('__construct()', '__construct('.$this->buildParameters($dispatchStatement->data()).')', $constructor); |
89 |
| - $stub = str_replace('//', $this->buildAssignments($dispatchStatement->data()), $stub); |
90 |
| - |
91 |
| - return $stub; |
92 |
| - } |
93 |
| - |
94 |
| - private function buildProperties(array $data) |
95 |
| - { |
96 |
| - return trim(array_reduce($data, function ($output, $property) { |
97 |
| - $output .= ' public $'.$property.';'.PHP_EOL.PHP_EOL; |
98 |
| - |
99 |
| - return $output; |
100 |
| - }, '')); |
101 |
| - } |
102 |
| - |
103 |
| - private function buildParameters(array $data) |
104 |
| - { |
105 |
| - $parameters = array_map(function ($parameter) { |
106 |
| - return '$'.$parameter; |
107 |
| - }, $data); |
108 |
| - |
109 |
| - return implode(', ', $parameters); |
110 |
| - } |
111 |
| - |
112 |
| - private function buildAssignments(array $data) |
113 |
| - { |
114 |
| - return trim(array_reduce($data, function ($output, $property) { |
115 |
| - $output .= ' $this->'.$property.' = $'.$property.';'.PHP_EOL; |
116 |
| - |
117 |
| - return $output; |
118 |
| - }, '')); |
119 |
| - } |
120 | 66 | }
|
0 commit comments