1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPMV; |
4
|
|
|
|
5
|
|
|
use PHPMV\js\JavascriptUtils; |
6
|
|
|
|
7
|
|
|
class VueManager { |
8
|
|
|
|
9
|
|
|
private static ?VueManager $instance = null; |
10
|
|
|
protected array $imports; |
11
|
|
|
protected array $vues; |
12
|
|
|
protected bool $useAxios; |
13
|
|
|
|
14
|
2 |
|
protected function __construct() { |
15
|
2 |
|
$this->imports = []; |
16
|
2 |
|
$this->vues = []; |
17
|
2 |
|
$this->useAxios = false; |
18
|
2 |
|
} |
19
|
|
|
|
20
|
2 |
|
public static function getInstance(): ?VueManager { |
21
|
2 |
|
if (!isset(self::$instance)) { |
22
|
2 |
|
self::$instance = new VueManager(); |
23
|
|
|
} |
24
|
2 |
|
return self::$instance; |
25
|
|
|
} |
26
|
|
|
|
27
|
2 |
|
public static function deleteInstance(): void { |
28
|
2 |
|
VueManager::$instance = null; |
29
|
2 |
|
} |
30
|
|
|
|
31
|
1 |
|
protected function addImport($import): void { |
32
|
1 |
|
$this->imports[] = $import; |
33
|
1 |
|
} |
34
|
|
|
|
35
|
1 |
|
public function importComponentObject(VueJSComponent $component): void { //component, mixin, or extend |
36
|
1 |
|
$this->addImport(JavascriptUtils::declareVariable('const', $component->getVarName(), $component->generateObject(), false)); |
|
|
|
|
37
|
1 |
|
} |
38
|
|
|
|
39
|
1 |
|
protected function addGlobal(string $type, string $body, string $name = null): void { |
40
|
1 |
|
if ($name) { |
41
|
1 |
|
$this->addImport("Vue." . $type . "('" . $name . "'," . $body . ");"); |
42
|
|
|
} else { |
43
|
1 |
|
$this->addImport("Vue." . $type . "(" . $body . ");"); |
44
|
|
|
} |
45
|
1 |
|
} |
46
|
|
|
|
47
|
1 |
|
public function addGlobalDirective(string $name, array $hookFunction) { |
48
|
1 |
|
foreach ($hookFunction as $key => $value) { |
49
|
1 |
|
$hookFunction[$key] = JavascriptUtils::generateFunction($value, ['el', 'binding', 'vnode', 'oldVnode']); |
|
|
|
|
50
|
|
|
} |
51
|
1 |
|
$this->addGlobal('directive', JavascriptUtils::arrayToJsObject($hookFunction), $name); |
52
|
1 |
|
} |
53
|
|
|
|
54
|
1 |
|
public function addGlobalFilter(string $name, string $body, array $params = []): void { |
55
|
1 |
|
$this->addGlobal('filter', JavascriptUtils::generateFunction($body, $params, false), $name); |
56
|
1 |
|
} |
57
|
|
|
|
58
|
1 |
|
public function addGlobalExtend(VueJSComponent $extend): void { |
59
|
1 |
|
$this->addGlobal('extend', $extend->generateObject()); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
1 |
|
public function addGlobalMixin(VueJSComponent $mixin): void { |
63
|
1 |
|
$this->addGlobal('mixin', $mixin->generateObject()); |
64
|
1 |
|
} |
65
|
|
|
|
66
|
1 |
|
public function addGlobalObservable(string $varName, array $object): void { |
67
|
1 |
|
$this->addImport(JavascriptUtils::declareVariable('const', $varName, "Vue.observable(" . JavascriptUtils::arrayToJsObject($object) . ")", false)); |
68
|
1 |
|
} |
69
|
|
|
|
70
|
1 |
|
public function addGlobalComponent(VueJSComponent $component): void { |
71
|
1 |
|
$this->addImport($component->generateGlobalScript()); |
72
|
1 |
|
} |
73
|
|
|
|
74
|
1 |
|
public function addVue(VueJS $vue): void { |
75
|
1 |
|
$this->vues[] = $vue; |
76
|
1 |
|
} |
77
|
|
|
|
78
|
1 |
|
public function __toString(): string { |
79
|
1 |
|
$script = ""; |
80
|
1 |
|
if ($this->useAxios) $script = "Vue.prototype.\$http = axios;" . PHP_EOL; |
81
|
1 |
|
$script .= implode(PHP_EOL, $this->imports); |
82
|
1 |
|
$script .= PHP_EOL . implode(PHP_EOL, $this->vues); |
83
|
1 |
|
$script = JavascriptUtils::cleanJSONFunctions($script); |
|
|
|
|
84
|
1 |
|
return JavascriptUtils::wrapScript($script); |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
public function setAxios(bool $useAxios): void { |
88
|
1 |
|
$this->useAxios = $useAxios; |
89
|
|
|
} |
90
|
|
|
} |
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.