Completed
Push — master ( bc53b5...fc9cad )
by Jean-Christophe
03:58
created

_JsUtils::getUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Ajax\php\cakephp;
4
5
6
use Ajax\service\JString;
7
use Cake\Routing\Router;
8
class _JsUtils extends \Ajax\JsUtils{
9
	public function getUrl($url){
10
		return Router::url($url);
11
	}
12
	public function addViewElement($identifier,$content,&$view){
13
		$viewVars=$view->viewVars;
14
		if (isset($viewVars["q"]) === false) {
15
			$controls=array ();
16
		}else{
17
			$controls=$viewVars["q"];
18
		}
19
		$controls[$identifier]=$content;
20
		$view->set("q", $controls);
21
	}
22
23
	public function createScriptVariable(&$view,$view_var, $output){
24
		$view->set($view_var,$output);
25
	}
26
27
	/**
28
	 * @param Symfony\Component\DependencyInjection\ContainerInterface $initialControllerInstance
29
	 * @param string $controllerName
30
	 * @param string $actionName
31
	 * @param array $params
32
	 * @see \Ajax\JsUtils::forward()
33
	 */
34 View Code Duplication
	public function forward($initialControllerInstance,$controllerName,$actionName,$params=array()){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
		$path=$params;
36
		$request = $initialControllerInstance->get('request_stack')->getCurrentRequest();
37
		$path['_forwarded'] = $request->attributes;
38
		$path['_controller'] = $controllerName.":".$actionName;
39
		$subRequest = $request->duplicate([], null, $path);
40
		$response= $initialControllerInstance->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
41
		return $response->getContent();
42
	}
43
44 View Code Duplication
	public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
        if ($initialControllerInstance->has('templating')) {
46
            return $initialControllerInstance->get('templating')->render($viewName, $params);
47
        }
48
49
        if (!$initialControllerInstance->has('twig')) {
50
            throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.');
51
        }
52
53
        return $initialControllerInstance->get('twig')->render($viewName, $params);
54
	}
55
56
	public function fromDispatcher($dispatcher){
57
		return \explode("/", Router::getRequest(true)->url);
58
	}
59
}