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