|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace PHPMV\php\ubiquity; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use PHPMV\VueManager; |
|
8
|
|
|
|
|
9
|
|
|
class UVueManager extends VueManager { |
|
10
|
|
|
public static function start(array &$config):UVueManager{ |
|
11
|
|
|
$instance=self::getInstance(); |
|
12
|
|
|
$instance->config=$config['vuejs']??['delimiters'=>['${','}']]; |
|
|
|
|
|
|
13
|
|
|
} |
|
14
|
|
|
/** |
|
15
|
|
|
* Performs Javascript compilation and displays a view |
|
16
|
|
|
* |
|
17
|
|
|
* @param string $viewName |
|
18
|
|
|
* @param mixed $parameters |
|
19
|
|
|
* Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br> |
|
20
|
|
|
* If an associative array is passed, the view retrieves variables from the table's key names |
|
21
|
|
|
* @param boolean $asString |
|
22
|
|
|
* If true, the view is not displayed but returned as a string (usable in a variable) |
|
23
|
|
|
* @return string|null |
|
24
|
|
|
* @throws \Exception |
|
25
|
|
|
*/ |
|
26
|
|
|
public function renderView($viewName, $parameters = [], $asString = false): ?string { |
|
27
|
|
|
if (isset($this->container)) { |
|
28
|
|
|
$view = $this->container->getView(); |
|
|
|
|
|
|
29
|
|
|
$parameters['script_foot']=$this->getInstance()->__toString(); |
|
30
|
|
|
if (isset($parameters)) |
|
31
|
|
|
$view->setVars($parameters); |
|
32
|
|
|
return $view->render($viewName, $asString); |
|
33
|
|
|
} |
|
34
|
|
|
throw new \Exception(get_class() . " instance is not properly instancied : you omitted the second parameter \$controller!"); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Performs javascript compilation and displays the default view |
|
39
|
|
|
* |
|
40
|
|
|
* @param mixed $parameters |
|
41
|
|
|
* Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br> |
|
42
|
|
|
* If an associative array is passed, the view retrieves variables from the table's key names |
|
43
|
|
|
* @param boolean $asString |
|
44
|
|
|
* If true, the view is not displayed but returned as a string (usable in a variable) |
|
45
|
|
|
* @return string|null |
|
46
|
|
|
* @throws \Exception |
|
47
|
|
|
*/ |
|
48
|
|
|
public function renderDefaultView($parameters = [], $asString = false):?string { |
|
49
|
|
|
return $this->renderView($this->container->getDefaultViewName(), $parameters, $asString); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
} |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: