public function __construct() { $this->app = \PFCS\FMK\App::getInstance(); $this->view = \PFCS\FMK\View::getInstance(); $this->config = \PFCS\FMK\Config::getInstance(); $this->input = \PFCS\FMK\InputData::getInstance(); // $this->session = $this->app->getSession(); we need Http Context maybe :P // View::logged((bool)$this->session->userId); // View::role($this->session->user['role']); }
public function parseCustomRoute(InputData $input, string $uri) { $customRoutes = $this->config->routes; if ($customRoutes && is_array($customRoutes)) { foreach ($customRoutes as $customRoute => $controllerAction) { $routeParts = explode('/{', $customRoute); $matchedCustomRoute = array_shift($routeParts); $hasParams = preg_match_all('/{(.+?)}/i', $customRoute, $result); $routeParamNames = $result[1]; if (stripos($uri, $matchedCustomRoute) === 0 && ($uri == $matchedCustomRoute || stripos($uri, $matchedCustomRoute . '/') === 0)) { if ($hasParams) { $paramsUri = substr($uri, strlen($matchedCustomRoute) + 1); $paramValues = explode('/', $paramsUri); $params = array(); foreach ($routeParamNames as $paramName) { $params[$paramName] = array_shift($paramValues); } } if ($hasParams) { $matchedCustomRoute = substr($matchedCustomRoute, strlen($customRoute) + 1); } else { $matchedCustomRoute = substr($uri, strlen($customRoute) + 1); } $matchedCustomRouteArray = explode('/', $matchedCustomRoute); if ($controllerAction[1]) { $this->controller = $controllerAction[1]; } else { $this->controller = array_shift($matchedCustomRouteArray); if (!$this->controller) { $this->controller = $this->getDefaultController(); } } if ($controllerAction[2]) { $this->method = $controllerAction[2]; } else { $this->method = array_shift($matchedCustomRouteArray); if (!$this->method) { $this->method = $this->getDefaultMethod(); } } if ($hasParams) { $input->setGet(array_merge($params, $matchedCustomRouteArray)); } else { $input->setGet($matchedCustomRouteArray); } $input->setPost($this->router->getPost()); $this->namespace = $controllerAction[0] ? $controllerAction[0] : $this->config->app['defaultControllerNamespace']; $this->loadControllerAction(); return true; } } } }