|
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
|
|
|
namespace Serverfireteam\Panel; |
|
9
|
|
|
|
|
10
|
|
|
use \Serverfireteam\Panel\libs\PanelElements; |
|
11
|
|
|
use Illuminate\Routing\Controller; |
|
12
|
|
|
use Illuminate\Support\Facades\Route; |
|
13
|
|
|
use Illuminate\Support\Facades\Request; |
|
14
|
|
|
|
|
15
|
|
|
class MainController extends Controller { |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
public function entityUrl($entity, $methods){ |
|
19
|
|
|
$uri = Request::path(); |
|
20
|
|
|
// Get route collection |
|
21
|
|
|
$routes = collect(Route::getRoutes()->getRoutes())->reduce(function ($carry = [], $route) { |
|
22
|
|
|
starts_with($route->uri(), 'panel/{entity}') ?: $carry[] = $route; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
return $carry; |
|
25
|
|
|
}); |
|
26
|
|
|
try { |
|
27
|
|
|
// If we find a match, take the user there. |
|
28
|
|
|
foreach ($routes as $route){ |
|
29
|
|
|
if ($uri == $route->uri()){ |
|
30
|
|
|
$controller_path = $route->getAction()['controller']; |
|
31
|
|
|
$controller_action = explode('@',$controller_path); |
|
32
|
|
|
$controller = \App::make($controller_action[0]); |
|
33
|
|
|
return $controller->callAction($controller_action[1], array()); |
|
34
|
|
|
break; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
catch (Exception $e){ |
|
|
|
|
|
|
39
|
|
|
// Otherwise, we didn't find a match so take the user to the admin page. |
|
40
|
|
|
return redirect('/panel'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$appHelper = new libs\AppHelper(); |
|
44
|
|
|
|
|
45
|
|
|
if ( \Links::isMain($entity)){ |
|
46
|
|
|
$controller_path = 'Serverfireteam\Panel\\'.$entity.'Controller'; |
|
47
|
|
|
} else { |
|
48
|
|
|
$panel_path = \Config::get('panel.controllers'); |
|
49
|
|
|
if ( isset($panel_path) ){ |
|
50
|
|
|
$controller_path = '\\'.$panel_path.'\\'.$entity.'Controller'; |
|
51
|
|
|
} else { |
|
52
|
|
|
$controller_path = $appHelper->getNameSpace().'Http\Controllers\\'.$entity.'Controller'; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
try{ |
|
57
|
|
|
$controller = \App::make($controller_path); |
|
58
|
|
|
}catch(\Exception $ex){ |
|
59
|
|
|
throw new \Exception("Controller not found ( $controller_path ) "); |
|
60
|
|
|
} |
|
61
|
|
|
if (!method_exists($controller, $methods)){ |
|
62
|
|
|
throw new \Exception('Controller does not implement the CrudController methods!'); |
|
63
|
|
|
} else { |
|
64
|
|
|
return $controller->callAction($methods, array('entity' => $entity)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.