| Conditions | 5 |
| Paths | 5 |
| Total Lines | 33 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function getResponse($packageRoot, Request $request) |
||
| 25 | { |
||
| 26 | $packageRoot = rtrim($packageRoot, '/'); |
||
| 27 | $path = $packageRoot . '/Route/' . $request->route() . '/' . $request->method() . '.php'; |
||
| 28 | if (file_exists($path)) { |
||
| 29 | require $path; |
||
| 30 | $controllerClass = $request->package() . '\\Route_' . str_replace('/', '_', $request->route()) . '\\' . $request->method(); |
||
| 31 | |||
| 32 | preg_match('/^[\\a-zA-Z0-9_-]*$/iD', $controllerClass, $match); |
||
| 33 | if (isset($match[0])) { |
||
| 34 | $controllerClass = $match[0]; |
||
| 35 | /** |
||
| 36 | * @var BaseController $controller |
||
| 37 | */ |
||
| 38 | $controller = new $controllerClass($packageRoot, $request); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Call handler. |
||
| 42 | */ |
||
| 43 | $handler = $_POST['handler'] ?? $_GET['handler'] ?? 'index'; |
||
| 44 | preg_match('/^[a-zA-Z0-9_-]*$/iD', $handler, $match); |
||
| 45 | if (isset($match[0])) { |
||
| 46 | $handler = $match[0]; |
||
| 47 | if (method_exists($controllerClass, $handler)) { |
||
| 48 | $controller->$handler(); |
||
| 49 | return $controller->getResponse(); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | return null; |
||
| 56 | } |
||
| 57 | } |