Passed
Push — main ( 92de25...9fb01f )
by Guillaume
02:18
created

VueJS::getUseAxios()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
namespace PHPMV;
3
4
use PHPMV\js\JavascriptUtils;
5
use PHPMV\utils\JsUtils;
6
7
/**
8
 * PHPMV$VueJS
9
 * This class is part of php-vuejs
10
 *
11
 * @author jc
12
 * @version 1.0.0
13
 *
14
 */
15
class VueJS extends AbstractVueJS {
16
17
	protected $useAxios;
18
19
	protected $configuration;
20
21
	public function __construct(string $app = "#app", bool $vuetify = false, bool $useAxios = false) {
22
		parent::__construct();
23
		$this->configuration['el'] = '"' . $app . '"';
24
		if ($vuetify) {
25
			$this->configuration['vuetify'] = "new Vuetify()";
26
		}
27
		;
28
		$this->useAxios = $useAxios;
29
	}
30
31
	public function __toString(): string {
32
		$script = "";
33
		if ($this->useAxios) {
34
			$script .= "Vue.prototype.\$http = axios;\n";
35
		}
36
		$script .= "const app=new Vue(";
37
		$script .= JavascriptUtils::arrayToJsObject($this->configuration + $this->data + $this->methods + $this->watchers + $this->computeds + $this->hooks);
38
		$script = JsUtils::cleanJSONFunctions($script);
39
		$script .= ")";
40
		$script = JavascriptUtils::wrapScript($script);
41
		return $script;
42
	}
43
44
	public function getUseAxios(): bool {
45
		return $this->useAxios;
46
	}
47
48
	public function setUseAxios(bool $useAxios): void {
49
		$this->useAxios = $useAxios;
50
	}
51
52
	public function getConfiguration(): array {
53
		return $this->configuration;
54
	}
55
56
	public function setConfiguration(array $configuration): void {
57
		$this->configuration = $configuration;
58
	}
59
}
60
$vue=new VueJS("v-app",true,false);
61
$vue->onBeforeMount("alert('The page is created')");
62
$vue->onMounted("alert('The page is created')");
63
$vue->onBeforeCreate("alert('The page is created')");
64
$vue->onCreated("alert('The page is created')");
65
$vue->onBeforeUpdate("alert('The page is created')");
66
$vue->onUpdated("alert('The page is created')");
67
$vue->onUpdatedNextTick("alert('The page is created')");
68
$vue->onBeforeDestroy("alert('The page is created')");
69
$vue->onDestroyed("alert('The page is created')");