1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\php\laravel; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Request; |
6
|
|
|
use Illuminate\Support\Facades\App; |
7
|
|
|
use Illuminate\Support\Facades\Route; |
8
|
|
|
class JsUtils extends \Ajax\JsUtils{ |
9
|
|
|
public function getUrl($url){ |
10
|
|
|
return \url($url); |
11
|
|
|
} |
12
|
|
View Code Duplication |
public function addViewElement($identifier,$content,$view){ |
|
|
|
|
13
|
|
|
$controls=$view->__get("q"); |
14
|
|
|
if (isset($controls) === false) { |
15
|
|
|
$controls=array (); |
16
|
|
|
} |
17
|
|
|
$controls[$identifier]=$content; |
18
|
|
|
$view->__set("q", $controls); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function createScriptVariable($view,$view_var, $output){ |
22
|
|
|
$view->__set($view_var,$output); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function forward($initialController,$controller,$action){ |
26
|
|
|
//\request()->attributes->all() |
|
|
|
|
27
|
|
|
$url=\action($controller.'@'.$action, [],false); |
28
|
|
|
$request = Request::create($url, 'GET'); |
29
|
|
|
// handle the response |
30
|
|
|
return Route::dispatch($request)->getContent(); |
31
|
|
|
//return App::make($controller)->{$action}(\request()->attributes->all()); |
|
|
|
|
32
|
|
|
//return "Accordion content";// |
33
|
|
|
//return \redirect()->action($controller.'@'.$action,\request()->attributes->all())->getContent(); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function renderContent($view, $controller, $action, $params=NULL) { |
37
|
|
|
$template=$view->getRender($controller, $action, $params, function ($view) { |
38
|
|
|
$view->setRenderLevel(View::LEVEL_ACTION_VIEW); |
39
|
|
|
}); |
40
|
|
|
return $template; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function fromDispatcher($dispatcher){ |
44
|
|
|
return $dispatcher->segments(); |
45
|
|
|
} |
46
|
|
|
} |
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.