| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Ajax\php\symfony; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\HttpFoundation\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\HttpKernel\HttpKernelInterface; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 8 |  |  | use Ajax\service\JString; | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  | class JsUtils extends \Ajax\JsUtils{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	public function getUrl($url){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		//$request = Request::createFromGlobals(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 		$router=$this->getInjected(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 		if(isset($router)===true){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 			try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 			$url=$router->generate($url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 			}catch (\Exception $e){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 				return $router->getContext()->getBaseUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		return $url; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 21 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	public function addViewElement($identifier,$content,&$view){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		if(\array_key_exists("q", $view)===false){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 			$view["q"]=array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		$view["q"][$identifier]=$content; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	public function createScriptVariable(&$view,$view_var, $output){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		$view[$view_var]=$output; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 	 * @param Symfony\Component\DependencyInjection\ContainerInterface $initialControllerInstance | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 	 * @param string $controllerName | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 	 * @param string $actionName | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 	 * @param array $params | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 	 * @see \Ajax\JsUtils::forward() | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	public function forward($initialControllerInstance,$controllerName,$actionName,$params=array()){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		$path=$params; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$request = $initialControllerInstance->get('request_stack')->getCurrentRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		$path['_forwarded'] = $request->attributes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$path['_controller'] = $controllerName.":".$actionName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		$subRequest = $request->duplicate([], null, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		$response= $initialControllerInstance->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		return $response->getContent(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	public function renderContent($initialControllerInstance,$viewName, $params=NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         if ($initialControllerInstance->has('templating')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             return $initialControllerInstance->get('templating')->render($viewName, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         if (!$initialControllerInstance->has('twig')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         return $initialControllerInstance->get('twig')->render($viewName, $params); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	public function fromDispatcher($dispatcher){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$request = $dispatcher->get('request_stack')->getCurrentRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$uri=$request->getPathInfo(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		if(JString::startswith($uri, "/")){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			$uri=\substr($uri, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		return \explode("/", $uri); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 70 |  |  | } | 
            
                        
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.