@@ -6,45 +6,45 @@ discard block |
||
| 6 | 6 | use Symfony\Component\HttpFoundation\Request; |
| 7 | 7 | use Symfony\Component\HttpKernel\HttpKernelInterface; |
| 8 | 8 | use Ajax\service\JString; |
| 9 | -class JsUtils extends \Ajax\JsUtils{ |
|
| 9 | +class JsUtils extends \Ajax\JsUtils { |
|
| 10 | 10 | |
| 11 | - public function getUrl($url){ |
|
| 11 | + public function getUrl($url) { |
|
| 12 | 12 | //$request = Request::createFromGlobals(); |
| 13 | 13 | $router=$this->getInjected(); |
| 14 | - if(isset($router)){ |
|
| 14 | + if (isset($router)) { |
|
| 15 | 15 | try { |
| 16 | 16 | $url=$router->generate($url); |
| 17 | - }catch (\Exception $e){ |
|
| 17 | + }catch (\Exception $e) { |
|
| 18 | 18 | return $router->getContext()->getBaseUrl(); |
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | return $url; |
| 22 | 22 | } |
| 23 | - public function addViewElement($identifier,$content,&$view){ |
|
| 24 | - if(\is_array($view)){ |
|
| 25 | - if(\array_key_exists("q", $view)===false){ |
|
| 23 | + public function addViewElement($identifier, $content, &$view) { |
|
| 24 | + if (\is_array($view)) { |
|
| 25 | + if (\array_key_exists("q", $view)===false) { |
|
| 26 | 26 | $view["q"]=array(); |
| 27 | 27 | } |
| 28 | 28 | $view["q"][$identifier]=$content; |
| 29 | - }elseif($view instanceof \Twig_Environment){ |
|
| 29 | + }elseif ($view instanceof \Twig_Environment) { |
|
| 30 | 30 | $vars=$view->getGlobals(); |
| 31 | - if(\array_key_exists("q", $vars)===false){ |
|
| 31 | + if (\array_key_exists("q", $vars)===false) { |
|
| 32 | 32 | $vars["q"]=array(); |
| 33 | 33 | } |
| 34 | 34 | $vars["q"][$identifier]=$content; |
| 35 | - $view->addGlobal("q",$vars["q"]); |
|
| 35 | + $view->addGlobal("q", $vars["q"]); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public function createScriptVariable(&$view,$view_var, $output){ |
|
| 39 | + public function createScriptVariable(&$view, $view_var, $output) { |
|
| 40 | 40 | $this->addVariable($view_var, $output, $view); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - protected function addVariable($key,$value,&$view){ |
|
| 44 | - if(\is_array($view)){ |
|
| 43 | + protected function addVariable($key, $value, &$view) { |
|
| 44 | + if (\is_array($view)) { |
|
| 45 | 45 | $view[$key]=$value; |
| 46 | - }elseif($view instanceof \Twig_Environment){ |
|
| 47 | - $view->addGlobal($key,$value); |
|
| 46 | + }elseif ($view instanceof \Twig_Environment) { |
|
| 47 | + $view->addGlobal($key, $value); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
@@ -55,17 +55,17 @@ discard block |
||
| 55 | 55 | * @param array $params |
| 56 | 56 | * @see \Ajax\JsUtils::forward() |
| 57 | 57 | */ |
| 58 | - public function forward($initialControllerInstance,$controllerName,$actionName,$params=array()){ |
|
| 58 | + public function forward($initialControllerInstance, $controllerName, $actionName, $params=array()) { |
|
| 59 | 59 | $path=$params; |
| 60 | - $request = $initialControllerInstance->get('request_stack')->getCurrentRequest(); |
|
| 61 | - $path['_forwarded'] = $request->attributes; |
|
| 62 | - $path['_controller'] = $controllerName.":".$actionName; |
|
| 63 | - $subRequest = $request->duplicate([], null, $path); |
|
| 64 | - $response= $initialControllerInstance->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); |
|
| 60 | + $request=$initialControllerInstance->get('request_stack')->getCurrentRequest(); |
|
| 61 | + $path['_forwarded']=$request->attributes; |
|
| 62 | + $path['_controller']=$controllerName.":".$actionName; |
|
| 63 | + $subRequest=$request->duplicate([], null, $path); |
|
| 64 | + $response=$initialControllerInstance->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); |
|
| 65 | 65 | return $response->getContent(); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - public function renderContent($initialControllerInstance,$viewName, $params=NULL) { |
|
| 68 | + public function renderContent($initialControllerInstance, $viewName, $params=NULL) { |
|
| 69 | 69 | if ($initialControllerInstance->has('templating')) { |
| 70 | 70 | return $initialControllerInstance->get('templating')->render($viewName, $params); |
| 71 | 71 | } |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | return $initialControllerInstance->get('twig')->render($viewName, $params); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function fromDispatcher($dispatcher){ |
|
| 81 | - $request = $dispatcher->get('request_stack')->getCurrentRequest(); |
|
| 80 | + public function fromDispatcher($dispatcher) { |
|
| 81 | + $request=$dispatcher->get('request_stack')->getCurrentRequest(); |
|
| 82 | 82 | $uri=$request->getPathInfo(); |
| 83 | - if(JString::startswith($uri, "/")){ |
|
| 83 | + if (JString::startswith($uri, "/")) { |
|
| 84 | 84 | $uri=\substr($uri, 1); |
| 85 | 85 | } |
| 86 | 86 | return \explode("/", $uri); |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | if(isset($router)){ |
| 15 | 15 | try { |
| 16 | 16 | $url=$router->generate($url); |
| 17 | - }catch (\Exception $e){ |
|
| 17 | + } catch (\Exception $e){ |
|
| 18 | 18 | return $router->getContext()->getBaseUrl(); |
| 19 | 19 | } |
| 20 | 20 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $view["q"]=array(); |
| 27 | 27 | } |
| 28 | 28 | $view["q"][$identifier]=$content; |
| 29 | - }elseif($view instanceof \Twig_Environment){ |
|
| 29 | + } elseif($view instanceof \Twig_Environment){ |
|
| 30 | 30 | $vars=$view->getGlobals(); |
| 31 | 31 | if(\array_key_exists("q", $vars)===false){ |
| 32 | 32 | $vars["q"]=array(); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | protected function addVariable($key,$value,&$view){ |
| 44 | 44 | if(\is_array($view)){ |
| 45 | 45 | $view[$key]=$value; |
| 46 | - }elseif($view instanceof \Twig_Environment){ |
|
| 46 | + } elseif($view instanceof \Twig_Environment){ |
|
| 47 | 47 | $view->addGlobal($key,$value); |
| 48 | 48 | } |
| 49 | 49 | } |