|
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'); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|