/** * Sets the requested URL. * * In case the URL does not exist, sets the default URL to the default module. * @access public */ public function setUrl($urlPath = null, array $args = null) { if (is_null($urlPath)) { $urlPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); } if ($this->router->isSearchEngineFriendly()) { if ($this->router->match($urlPath)) { $routeFound = $this->router->getMatchedRoute(); $this->moduleName = $routeFound['module']; $this->controllerName = ucfirst($routeFound['controller']) . 'Controller'; $this->actionName = $routeFound['action']; $this->urlParams = $this->router->getMatchedRouteParams(); return; } return $this->dispatchRouteDefault(); } if ($urlPath == '/') { $this->moduleName = $this->config->get('default_module'); $this->controllerName = 'IndexController'; $this->actionName = 'index'; return; } $arrayUrl = explode('/', $urlPath); if (count($arrayUrl) <= 3) { return $this->dispatchRouteDefault(); } $this->moduleName = $arrayUrl[1]; $this->controllerName = ucfirst($arrayUrl[2]) . 'Controller'; $this->actionName = $arrayUrl[3]; unset($arrayUrl[0], $arrayUrl[1], $arrayUrl[2], $arrayUrl[3]); if (is_null($args)) { $args = []; foreach ($arrayUrl as $key => $value) { if ($key == 0 || $key % 2 == 0) { $args[$value] = !isset($arrayUrl[$key + 1]) || empty($arrayUrl[$key + 1]) ? '' : $arrayUrl[$key + 1]; } } } $this->urlParams = $args; }
private function getConfig() { $config = new \Piano\Config(); $config->setApplicationFolder('application')->setDefaultModule('testDefaultModuleName')->setLayoutPerModule(['base' => ['application'], 'admin' => ['admin']]); return $config; }