5use Ubiquity\controllers\Startup;
6use Ubiquity\utils\http\URequest;
7use Ubiquity\security\csp\ContentSecurityManager;
8use Ubiquity\utils\http\UResponse;
20 if (($this->params[
'csp'] ??
false) ===
'nonce' && ContentSecurityManager::isStarted()) {
21 $nonce = ContentSecurityManager::getNonce(
'jsUtils');
22 $str .=
' nonce="' . $nonce .
'" ';
24 $str .= ($src ==
'') ?
'>' :
' src="' . $src .
'">';
28 public function inline($script, $cdata =
true) {
29 if (($this->params[
'csp'] ??
false) ===
'hash' && ContentSecurityManager::isStarted()) {
30 $script = ($cdata) ?
"\n// <![CDATA[\n{$script}\n// ]]>\n" :
"\n{$script}\n";
31 ContentSecurityManager::getHash(
'jsUtils', $script);
37 return URequest::getUrl($url);
41 $controls = $view->getVar(
"q");
42 if (isset($controls) ===
false) {
45 $controls[$identifier] = $content;
46 $view->setVar(
"q", $controls);
50 $view->setVar($view_var, $output);
53 public function forward($initialController, $controller, $action,
$params = array()) {
54 return $initialController->forward($controller, $action,
$params,
true,
true,
true);
58 return $initialControllerInstance->loadView($viewName,
$params,
true);
62 return Startup::$urlParts;
75 public function renderView($viewName, $parameters = [], $asString =
false) {
76 if (isset($this->injected)) {
77 $view = $this->injected->getView();
79 return $this->injected->loadView($viewName, $parameters, $asString);
81 throw new \Exception(get_class() .
" instance is not properly instancied : you omitted the second parameter \$controller!");
94 return $this->
renderView($this->injected->getDefaultViewName(), $parameters, $asString);
107 if (isset($this->injected)) {
108 $view = $this->injected->getView();
109 if (isset($parameters))
110 $view->setVars($parameters);
111 $js = $view->render($jsFile .
'.js',
true);
112 return $this->
exec($js, $immediatly);
114 throw new \Exception(get_class() .
" instance is not properly instancied : you omitted the second parameter \$controller!");
128 $jquery =
new JsUtils($options, $controller);
130 $jquery->setAjaxLoader(
"<div class=\"ui active centered inline text loader\">Loading</div>");
145 $jquery =
new JsUtils($options, $controller);
147 $jquery->setAjaxLoader(
"<div class=\"d-flex justify-content-center\"><div class=\"spinner-border\" role=\"status\"><span class=\"sr-only\">Loading...</span></div></div>");
161 $this->
exec(
Rule::
ajax($this, $ruleName, $checkUrl,
$params,
'result=data.result;', $method), true);
170 if (URequest::isPost()) {
173 $value = $_POST[
'_value'];
174 $result[
'result'] = $callback($value);
175 echo \json_encode($result);
compile(&$view=NULL, $view_var='script_foot', $script_tags=TRUE)
gather together all script needing to be output
exec($js, $immediatly=false)
Executes the code $js.
ajax($method, $url, $responseElement='', $parameters=[])
Performs an ajax request.
_close_script($extra="\n")
Outputs an closing </script>
renderView($viewName, $parameters=[], $asString=false)
Performs jQuery compilation and displays a view.
fromDispatcher($dispatcher)
Collects url parts from the request dispatcher : controllerName, actionName, parameters Used internal...
getUrl($url)
Generates an URL Used internally by phpMv.
checkValidationRule($callback)
Checks a validation rule declared with @ajaxValidationRule.
renderContent($initialControllerInstance, $viewName, $params=NULL)
render the content of an existing view : $viewName and set the response to the modal content Used int...
forward($initialController, $controller, $action, $params=array())
Forwards to.
createScriptVariable(&$view, $view_var, $output)
Creates the script variable script_foot Used internally by phpMv.
static diBootstrap($controller, $options=['defer'=> true, 'gc'=> true])
Returns an instance of JsUtils initialized with Bootstrap (for di injection)
renderDefaultView($parameters=[], $asString=false)
Performs jQuery compilation and displays the default view.
_open_script($src='')
Outputs an opening <script>
execJSFromFile($jsFile, $parameters=[], $immediatly=true)
Loads and eventually executes a jsFile with php parameters, using the default template engine.
static diSemantic($controller, $options=['defer'=> true, 'gc'=> true])
Returns an instance of JsUtils initialized with Semantic (for di injection)
addViewElement($identifier, $content, &$view)
Adds the array of controls q in the $view element Used internally by phpMv.
ajaxValidationRule(string $ruleName, string $checkUrl, string $params='{_value:value}', string $method='post')
Adds a new semantic validation ajax rule.