|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
5
|
|
|
* To change this template file, choose Tools | Templates |
|
6
|
|
|
* and open the template in the editor. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Serverfireteam\Panel; |
|
10
|
|
|
|
|
11
|
|
|
use \Serverfireteam\Panel\libs\PanelElements; |
|
12
|
|
|
use Illuminate\Routing\Controller; |
|
13
|
|
|
use Symfony\Component\Finder\Finder; |
|
14
|
|
|
|
|
15
|
|
|
class MainController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
public function entityUrl($entity, $methods) |
|
20
|
|
|
{ |
|
21
|
|
|
$appHelper = new libs\AppHelper(); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
if (\Links::isMain($entity)) { |
|
24
|
|
|
$controller_path = 'Serverfireteam\Panel\\'.$entity.'Controller'; |
|
25
|
|
|
} else { |
|
26
|
|
|
$panel_path = \Config::get('panel.controllers'); |
|
27
|
|
|
if (isset($panel_path)) { |
|
28
|
|
|
$controller_path = '\\'.$panel_path.'\\'.$entity.'Controller'; |
|
29
|
|
|
} else { |
|
30
|
|
|
$controller_path = ''; |
|
31
|
|
|
$finder = new Finder(); |
|
32
|
|
|
$files = $finder->files()->name($entity."Controller.php")->in( |
|
33
|
|
|
\App::basePath().'/app' |
|
34
|
|
|
); |
|
35
|
|
|
foreach ($files as $item) { |
|
36
|
|
|
$fileContent = $item->getContents(); |
|
37
|
|
|
$controller_path = $this->getNameSpace( |
|
38
|
|
|
$fileContent |
|
39
|
|
|
)."\\".$entity."Controller"; |
|
40
|
|
|
} |
|
41
|
|
|
if ($controller_path === '') { |
|
42
|
|
|
throw new \Exception("Controller not found ( $entity.\"Controller.php\" ) "); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
try { |
|
48
|
|
|
$controller = \App::make($controller_path); |
|
49
|
|
|
} catch (\Exception $ex) { |
|
50
|
|
|
throw new \Exception("Controller not found ( $controller_path ) "); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (!method_exists($controller, $methods)) { |
|
54
|
|
|
throw new \Exception( |
|
55
|
|
|
'Controller does not implement the CrudController methods!' |
|
56
|
|
|
); |
|
57
|
|
|
} else { |
|
58
|
|
|
return $controller->callAction( |
|
59
|
|
|
$methods, |
|
60
|
|
|
array('entity' => $entity) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private function getNameSpace($fileContent) |
|
67
|
|
|
{ |
|
68
|
|
|
if (preg_match('#^namespace\s+(.+?);$#sm', $fileContent, $m)) { |
|
69
|
|
|
return $m[1]; |
|
70
|
|
|
} |
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.