Completed
Push — master ( 6ada0e...35727f )
by Jean-Christophe
04:07
created

JsUtils   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 37
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 5 2
A addViewElement() 0 7 2
A createScriptVariable() 0 3 1
A forward() 0 8 1
A renderContent() 0 3 1
A fromDispatcher() 0 4 1
1
<?php
2
3
namespace Ajax\php\yii;
4
5
use yii\helpers\Url;
6
7
class JsUtils extends \Ajax\JsUtils{
8
	public function getUrl($url){
9
		if($url==="")
10
			$url="/";
11
		return Url::toRoute($url);
12
	}
13
14
	public function addViewElement($identifier,$content,$view){
15
		$params=$view->params;
16
		if (\array_key_exists("q", $params)==false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
17
			$view->params["q"]=array();
18
		}
19
		$view->params["q"][$identifier]=$content;
20
	}
21
22
	public function createScriptVariable($view,$view_var, $output){
23
		$view->params[$view_var]=$output;
24
	}
25
26
	public function forward($initialControllerInstance,$controllerName,$actionName,$params=NULL){
27
		\ob_start();
28
		$ctrInfo=\yii::$app->createController($controllerName."/".$actionName);
29
		$ctrInfo[0]->{$ctrInfo[1]}($params);
30
		$result=\ob_get_contents();
31
		\ob_end_clean();
32
		return $result;
33
	}
34
35
	public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
36
		return \yii::$app->view->render($viewName,$params);
37
	}
38
39
	public function fromDispatcher($dispatcher){
40
		$uri=new \Ajax\php\yii\URI();
41
		return $uri->segment_array();
42
	}
43
}