1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\php\laravel; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class JsUtils extends \Ajax\JsUtils{ |
7
|
|
|
public function getUrl($url){ |
8
|
|
|
return $url; |
9
|
|
|
} |
10
|
|
View Code Duplication |
public function addViewElement($identifier,$content,$view){ |
|
|
|
|
11
|
|
|
$controls=$view->__get("q"); |
12
|
|
|
if (isset($controls) === false) { |
13
|
|
|
$controls=array (); |
14
|
|
|
} |
15
|
|
|
$controls[$identifier]=$content; |
16
|
|
|
$view->__set("q", $controls); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function createScriptVariable($view,$view_var, $output){ |
20
|
|
|
$view->__set($view_var,$output); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
View Code Duplication |
public function forward($initialController,$controller,$action){ |
|
|
|
|
24
|
|
|
$dispatcher = $initialController->dispatcher; |
25
|
|
|
$dispatcher->setControllerName($controller); |
26
|
|
|
$dispatcher->setActionName($action); |
27
|
|
|
$dispatcher->dispatch(); |
28
|
|
|
$template=$initialController->view->getRender($dispatcher->getControllerName(), $dispatcher->getActionName(),$dispatcher->getParams(), function ($view) { |
29
|
|
|
$view->setRenderLevel(View::LEVEL_ACTION_VIEW); |
30
|
|
|
}); |
31
|
|
|
return $template; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function renderContent($view, $controller, $action, $params=NULL) { |
35
|
|
|
$template=$view->getRender($controller, $action, $params, function ($view) { |
36
|
|
|
$view->setRenderLevel(View::LEVEL_ACTION_VIEW); |
37
|
|
|
}); |
38
|
|
|
return $template; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function fromDispatcher($dispatcher){ |
|
|
|
|
42
|
|
|
$params=$dispatcher->getParams(); |
43
|
|
|
$action=$dispatcher->getActionName(); |
44
|
|
|
$items=array($dispatcher->getControllerName()); |
45
|
|
|
if(\sizeof($params)>0 || \strtolower($action)!="index" ){ |
46
|
|
|
$items[]=$action; |
47
|
|
|
foreach ($params as $p){ |
48
|
|
|
if(\is_object($p)===false) |
49
|
|
|
$items[]=$p; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
return $items; |
53
|
|
|
} |
54
|
|
|
} |
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.