1
|
|
|
<?php |
2
|
|
|
namespace PHPMV; |
3
|
|
|
|
4
|
|
|
use PHPMV\utils\JsUtils; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Created by PhpStorm. |
8
|
|
|
* User: qgorak |
9
|
|
|
* Date: 19/11/2020 |
10
|
|
|
* Time: 14:20 |
11
|
|
|
*/ |
12
|
|
|
class AbstractVueJS { |
13
|
|
|
protected array $data; |
14
|
|
|
protected array $methods; |
15
|
|
|
protected array $computeds; |
16
|
|
|
protected array $watchers; |
17
|
|
|
protected array $directives; |
18
|
|
|
protected array $filters; |
19
|
|
|
protected array $hooks; |
20
|
|
|
|
21
|
|
|
public function __construct() { |
22
|
|
|
$this->data=[]; |
23
|
16 |
|
$this->methods=[]; |
24
|
16 |
|
$this->computeds=[]; |
25
|
16 |
|
$this->watchers=[]; |
26
|
16 |
|
$this->directives=[]; |
27
|
16 |
|
$this->filters=[]; |
28
|
16 |
|
$this->hooks=[]; |
29
|
16 |
|
} |
30
|
16 |
|
|
31
|
16 |
|
public function addHook(string $name,string $body):void { |
32
|
|
|
$this->hooks[$name] = JsUtils::generateFunction($body); |
33
|
2 |
|
} |
34
|
2 |
|
|
35
|
2 |
|
public function onBeforeCreate(string $body):void { |
36
|
|
|
$this->addHook("beforeCreate", $body); |
37
|
1 |
|
} |
38
|
1 |
|
|
39
|
1 |
|
public function onCreated(string $body):void { |
40
|
|
|
$this->addHook("created", $body); |
41
|
1 |
|
} |
42
|
1 |
|
|
43
|
1 |
|
public function onBeforeMount(string $body):void { |
44
|
|
|
$this->addHook("beforeMount", $body); |
45
|
1 |
|
} |
46
|
1 |
|
|
47
|
1 |
|
public function onMounted(string $body):void { |
48
|
|
|
$this->addHook("mounted", $body); |
49
|
2 |
|
} |
50
|
2 |
|
|
51
|
2 |
|
public function onBeforeUpdate(string $body):void { |
52
|
|
|
$this->addHook("beforeUpdate", $body); |
53
|
1 |
|
} |
54
|
1 |
|
|
55
|
1 |
|
public function onUpdated(string $body):void { |
56
|
|
|
$this->addHook("updated", $body); |
57
|
1 |
|
} |
58
|
1 |
|
|
59
|
1 |
|
public function onUpdatedNextTick(string $body):void { |
60
|
|
|
$this->addHook("updated", "this.\$nextTick(function () {".$body."})"); |
61
|
1 |
|
} |
62
|
1 |
|
|
63
|
1 |
|
public function onBeforeDestroy(string $body):void { |
64
|
|
|
$this->addHook("beforeDestroy", $body); |
65
|
1 |
|
} |
66
|
1 |
|
|
67
|
1 |
|
public function onDestroyed(string $body):void { |
68
|
|
|
$this->addHook("destroyed", $body); |
69
|
1 |
|
} |
70
|
1 |
|
|
71
|
1 |
|
public function addData(string $name,$value):void { |
72
|
|
|
$this->data["data"][$name]=$value; |
73
|
3 |
|
} |
74
|
3 |
|
|
75
|
3 |
|
public function addDataRaw(string $name,string $value):void { |
76
|
|
|
$this->data["data"][$name]=JsUtils::removeQuotes($value); |
77
|
2 |
|
} |
78
|
2 |
|
|
79
|
2 |
|
public function addMethod(string $name,string $body, array $params = []):void { |
80
|
|
|
$this->methods["methods"][$name]=JsUtils::generateFunction($body,$params); |
81
|
4 |
|
} |
82
|
4 |
|
|
83
|
4 |
|
public function addComputed(string $name,string $get,string $set=null):void { |
84
|
|
|
$name=JsUtils::removeQuotes($name); |
85
|
3 |
|
$vc=(is_null($set)) ? JsUtils::generateFunction($get) : JsUtils::removeQuotes("{ get: ".JsUtils::generateFunction($get,[],false).", set: ".JsUtils::generateFunction($set,["v"],false)." }"); |
86
|
3 |
|
$this->computeds["computeds"][$name]=$vc; |
87
|
3 |
|
} |
88
|
3 |
|
|
89
|
3 |
|
public function addWatcher(string $var,string $body,array $params=[]):void { |
90
|
|
|
$this->watchers["watch"][$var]=JsUtils::generateFunction($body,$params); |
91
|
2 |
|
} |
92
|
2 |
|
|
93
|
2 |
|
public function addFilter(string $name,string $body, array $params = []):void { |
94
|
|
|
$name=JsUtils::removeQuotes($name); |
95
|
1 |
|
$this->filters["filters"][$name]=JsUtils::generateFunction($body,$params); |
96
|
1 |
|
} |
97
|
1 |
|
|
98
|
1 |
|
public function addDirective(string $name,array $hookFunction):void { |
99
|
|
|
$name = JsUtils::removeQuotes($name); |
100
|
1 |
|
foreach ($hookFunction as $key=>$value){ |
101
|
1 |
|
$key = JsUtils::removeQuotes($key); |
102
|
1 |
|
$this->directives["directives"][$name][$key] = JsUtils::generateFunction($value,['el', 'binding', 'vnode', 'oldVnode']); |
103
|
1 |
|
} |
104
|
1 |
|
} |
105
|
|
|
|
106
|
1 |
|
public function getData():array { |
107
|
|
|
return $this->data; |
108
|
1 |
|
} |
109
|
1 |
|
|
110
|
1 |
|
public function setData(array $data):void { |
111
|
|
|
$this->data=$data; |
112
|
1 |
|
} |
113
|
1 |
|
|
114
|
|
|
public function getMethods():array { |
115
|
1 |
|
return $this->methods; |
116
|
1 |
|
} |
117
|
1 |
|
|
118
|
|
|
public function setMethods(array $methods):void { |
119
|
1 |
|
$this->methods=$methods; |
120
|
1 |
|
} |
121
|
1 |
|
|
122
|
|
|
public function getComputeds():array { |
123
|
4 |
|
return $this->computeds; |
124
|
4 |
|
} |
125
|
|
|
|
126
|
|
|
public function setComputeds(array $computeds):void { |
127
|
1 |
|
$this->computeds = $computeds; |
128
|
1 |
|
} |
129
|
1 |
|
|
130
|
|
|
public function getWatchers():array { |
131
|
3 |
|
return $this->watchers; |
132
|
3 |
|
} |
133
|
|
|
|
134
|
|
|
public function setWatchers(array $watchers):void { |
135
|
1 |
|
$this->watchers = $watchers; |
136
|
1 |
|
} |
137
|
1 |
|
|
138
|
|
|
public function getDirectives():array { |
139
|
3 |
|
return $this->directives; |
140
|
3 |
|
} |
141
|
|
|
|
142
|
|
|
public function setDirectives(array $directives):void { |
143
|
1 |
|
$this->directives = $directives; |
144
|
1 |
|
} |
145
|
1 |
|
|
146
|
|
|
public function getFilters():array { |
147
|
2 |
|
return $this->filters; |
148
|
2 |
|
} |
149
|
|
|
|
150
|
|
|
public function setFilters(array $filters):void { |
151
|
1 |
|
$this->filters = $filters; |
152
|
1 |
|
} |
153
|
1 |
|
|
154
|
|
|
public function getHooks():array { |
155
|
2 |
|
return $this->hooks; |
156
|
2 |
|
} |
157
|
|
|
|
158
|
|
|
public function setHooks(array $hooks):void { |
159
|
1 |
|
$this->hooks = $hooks; |
160
|
|
|
} |
161
|
|
|
} |