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