public function testSetBasePathAltersInitialPath() { $helper = new BasePathHelper(); $helper->setBasePath('/foo'); $this->assertEquals('/foo/', $helper()); $this->assertEquals('/foo/asset.css', $helper('asset.css')); }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { $uri = $request->getUri(); $uriPath = $uri->getPath(); $baseUrl = $this->baseUrlFinder->findBaseUrl($request->getServerParams(), $uriPath); $basePath = $this->detectBasePath($request->getServerParams(), $baseUrl); $request = $request->withAttribute(self::BASE_URL, $baseUrl); $request = $request->withAttribute(self::BASE_PATH, $basePath); if (!empty($baseUrl) && strpos($uriPath, $baseUrl) === 0) { $path = substr($uriPath, strlen($baseUrl)); $path = '/' . ltrim($path, '/'); $request = $request->withUri($uri->withPath($path)); } if ($this->urlHelper) { $this->urlHelper->setBasePath($baseUrl); } if ($this->basePathHelper) { $this->basePathHelper->setBasePath($basePath); } return $next($request, $response); }