Test Failed
Push — main ( c284eb...6e070f )
by Jean-Christophe
05:10
created

UVueManager::renderView()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 3
eloc 7
c 2
b 1
f 1
nc 3
nop 3
dl 0
loc 10
rs 10
1
<?php
2
3
4
namespace PHPMV\fw\ubiquity;
5
6
7
use PHPMV\fw\VueManagerInterface;
8
use PHPMV\utils\PhpUtils;
9
use PHPMV\VueJSComponent;
10
use PHPMV\VueManager;
11
12
/**
13
 * php-vueJS Manager class for Ubiquity framework.
14
 *
15
 * PHPMV\jw$UVueManager
16
 * This class is part of php-vuejs
17
 *
18
 * @author jcheron
19
 * @version 1.0.0
20
 * @package PHPMV\fw\ubiquity
21
 *
22
 */
23
class UVueManager extends VueManager implements VueManagerInterface {
24
25
	public static function start(array &$config): void {
26
		self::getInstance()->setConfig($config['vuejs'] ?? ['delimiters' => ['${', '}']]);
27
	}
28
29
	public function renderView(string $viewName, $parameters = [], bool $asString = false): ?string {
30
		if (isset($this->container)) {
31
			$view = $this->container->getView();
32
			$parameters['script_foot'] = $this->getInstance()->__toString();
33
			if (isset($parameters)) {
34
				$view->setVars($parameters);
35
			}
36
			return $view->render($viewName, $asString);
37
		}
38
		throw new \Exception(get_class() . " instance is not properly instancied : you omitted the second parameter \$controller!");
39
	}
40
41
	public function renderDefaultView($parameters = [], bool $asString = false): ?string {
42
		return $this->renderView($this->container->getDefaultViewName(), $parameters, $asString);
43
	}
44
45
	public function addTemplateFileComponent(string $filename, VueJSComponent $component, $parameters = null): void {
46
		$filename = \rtrim($this->getTemplateComponentDirectory(), '/') . '/' . $filename;
47
		$view = $this->container->getView();
48
		if (isset($parameters)) {
49
			$view->setVars($parameters);
50
		}
51
		$content=\str_replace(["\n","\t"],"",$view->render($filename, true));
52
		$content=\str_replace('"','\"',$content);
53
		$component->addTemplate($content);
54
	}
55
56
	public function parseFile(string $fileName): void {
57
		PhpUtils::parseFile(\ROOT.'..'.\DS.'public'.\DS.'assets'.\DS.'js'.\DS.$fileName,'js');
1 ignored issue
show
Bug introduced by
The constant DS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
	}
59
}
60