public function testRemoval() { $request = new Request(); $request->pathInfo = 'foo/bar'; $request->hostInfo = 'example.fr'; $comp = new Composition($request); $this->assertEquals('this-should/be-left', $comp->removeFrom('en/this-should/be-left')); }
private function urlReplaceModule($url, $navItemId, \luya\web\Composition $composition) { $route = $this->removeBaseUrl($url); $route = $composition->removeFrom($route); $module = $this->findModuleInRoute($route); if (!$module) { return $url; } $item = $this->menu->find()->where(['id' => $navItemId])->with('hidden')->lang($composition['langShortCode'])->one(); if (!$item) { throw new BadRequestHttpException("Unable to find nav_item_id '{$navItemId}' to generate the module link for url '{$url}'."); } // if the item type is (2) module and the current context module is not equals we don't have to remove to replace the module name // as this is an url rule not related to the current module. if ($item->type == 2) { if ($module !== $item->moduleName) { return $url; } } $replaceRoute = preg_replace("/{$module}/", rtrim($item->link, '/'), ltrim($route, '/'), 1); return $replaceRoute; }