1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPMV; |
4
|
|
|
|
5
|
|
|
use PHPMV\js\JavascriptUtils; |
6
|
|
|
use PHPMV\utils\JsUtils; |
7
|
|
|
|
8
|
|
|
class VueJSComponent extends AbstractVueJS { |
9
|
|
|
protected string $name; |
10
|
|
|
protected array $props; |
11
|
|
|
protected array $template; |
12
|
2 |
|
protected array $extends; |
13
|
2 |
|
protected ?string $varName; |
14
|
2 |
|
|
15
|
2 |
|
public function __construct(string $name,string $varName = null) { |
16
|
2 |
|
parent::__construct(); |
17
|
2 |
|
$this->name = $name; |
18
|
|
|
$this->props = []; |
19
|
1 |
|
$this->extends = []; |
20
|
1 |
|
$this->template = []; |
21
|
1 |
|
if(!$varName){ |
22
|
1 |
|
$varName = JsUtils::kebabToPascal($name); |
23
|
|
|
} |
24
|
|
|
$this->varName = $varName; |
25
|
1 |
|
} |
26
|
1 |
|
|
27
|
1 |
|
public function extends(VueJSComponent $component):void { |
28
|
1 |
|
$this->extends['extends'] = $component->getVarName(); |
29
|
1 |
|
} |
30
|
|
|
|
31
|
|
|
public function generateObject():string { |
32
|
|
|
$script = JavascriptUtils::arrayToJsObject($this->props + $this->components + $this->filters + $this->extends + $this->mixins + $this->data + $this->computeds + $this->watchers + $this->hooks + $this->methods + $this->template); |
33
|
|
|
$script = JsUtils::cleanJSONFunctions($script); |
34
|
|
|
return $script; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function addProps(string ...$props):void { |
38
|
|
|
$this->props["props"] = $props; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function addTemplate(string $template):void { |
42
|
|
|
$this->template["template"] = $template; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function importTemplate(string $template):void { |
46
|
|
|
$this->template["template"] = "'".\str_replace(["\n","\r","\t"]," ",(\file_get_contents($template.'.html',true))."'"); |
47
|
1 |
|
} |
48
|
1 |
|
|
49
|
1 |
|
public function onActivated(string $body):void { |
50
|
|
|
$this->addHook("activated", $body); |
51
|
1 |
|
} |
52
|
1 |
|
|
53
|
1 |
|
public function onDeactivated(string $body):void { |
54
|
|
|
$this->addHook("deactivated", $body); |
55
|
1 |
|
} |
56
|
1 |
|
|
57
|
|
|
public function getName():string { |
58
|
1 |
|
return $this->name; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getVarName():string { |
62
|
|
|
return $this->varName; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |