|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Modelarium\Frontend; |
|
4
|
|
|
|
|
5
|
|
|
use Formularium\Model; |
|
6
|
|
|
use Formularium\FrameworkComposer; |
|
7
|
|
|
use Formularium\Frontend\Blade\Framework as FrameworkBlade; |
|
8
|
|
|
use Formularium\Frontend\Vue\Framework as FrameworkVue; |
|
9
|
|
|
use Modelarium\GeneratedCollection; |
|
10
|
|
|
use Modelarium\GeneratedItem; |
|
11
|
|
|
use Modelarium\GeneratorInterface; |
|
12
|
|
|
use Modelarium\GeneratorNameTrait; |
|
13
|
|
|
|
|
14
|
|
|
use function Safe\file_get_contents; |
|
15
|
|
|
|
|
16
|
|
|
class FrontendGenerator implements GeneratorInterface |
|
17
|
|
|
{ |
|
18
|
|
|
use GeneratorNameTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var FrameworkComposer |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $composer = null; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var Model |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $model = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var GeneratedCollection |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $collection; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $stubDir = __DIR__ . '/stubs'; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct(FrameworkComposer $composer, Model $model) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->composer = $composer; |
|
44
|
|
|
$this->model = $model; |
|
45
|
|
|
$this->setName($model->getName()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function generate(): GeneratedCollection |
|
49
|
|
|
{ |
|
50
|
|
|
$this->collection = new GeneratedCollection(); |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var FrameworkVue $vue |
|
54
|
|
|
*/ |
|
55
|
|
|
$vue = $this->composer->getByName('Vue'); |
|
56
|
|
|
// $blade = FrameworkComposer::getByName('Blade'); |
|
57
|
|
|
|
|
58
|
|
|
if ($vue !== null) { |
|
59
|
|
|
$this->makeVue($vue, 'Base', 'viewable'); |
|
60
|
|
|
$this->makeVue($vue, 'Card', 'viewable'); |
|
61
|
|
|
$this->makeVue($vue, 'List', 'viewable'); |
|
62
|
|
|
$this->makeVue($vue, 'Show', 'viewable'); |
|
63
|
|
|
$this->makeVue($vue, 'Form', 'editable'); |
|
64
|
|
|
$this->makeVueRouter(); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $this->collection; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function makeVue(FrameworkVue $vue, string $component, string $mode): void |
|
71
|
|
|
{ |
|
72
|
|
|
$path = $this->model->getName() . '/' . |
|
73
|
|
|
$this->model->getName() . $component . '.vue'; |
|
74
|
|
|
$stub = file_get_contents($this->stubDir . "/Vue{$component}.stub.vue"); |
|
75
|
|
|
if ($mode == 'editable') { |
|
76
|
|
|
$vue->setEditableTemplate($stub); |
|
77
|
|
|
$this->collection->push( |
|
78
|
|
|
new GeneratedItem( |
|
79
|
|
|
GeneratedItem::TYPE_FRONTEND, |
|
80
|
|
|
$this->model->editable($this->composer), |
|
81
|
|
|
$path |
|
82
|
|
|
) |
|
83
|
|
|
); |
|
84
|
|
|
} else { |
|
85
|
|
|
$vue->setViewableTemplate($stub); |
|
86
|
|
|
$this->collection->push( |
|
87
|
|
|
new GeneratedItem( |
|
88
|
|
|
GeneratedItem::TYPE_FRONTEND, |
|
89
|
|
|
$this->model->viewable($this->composer, []), |
|
90
|
|
|
$path |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
protected function makeVueRoutes(string $component, string $mode): void |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
$path = $this->model->getName() . '/routes.js'; |
|
99
|
|
|
$stub = file_get_contents($this->stubDir . "/routes.stub.js"); |
|
100
|
|
|
|
|
101
|
|
|
$this->collection->push( |
|
102
|
|
|
new GeneratedItem( |
|
103
|
|
|
GeneratedItem::TYPE_FRONTEND, |
|
104
|
|
|
$this->template($stub), |
|
105
|
|
|
$path |
|
106
|
|
|
) |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.