mirror of
https://github.com/nextcloud/server.git
synced 2026-04-20 22:00:39 -04:00
Use IURLGenerator function to get value of \OC::$WEBROOT global
Signed-off-by: Jonas Meurer <jonas@freesources.org>
This commit is contained in:
parent
5f5bacde8f
commit
7c76e85dde
4 changed files with 27 additions and 2 deletions
|
|
@ -33,6 +33,7 @@ use OCP\AppFramework\OCSController;
|
|||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Route\IRouter;
|
||||
use OCP\Search\ISearchQuery;
|
||||
|
|
@ -49,15 +50,20 @@ class UnifiedSearchController extends OCSController {
|
|||
/** @var IRouter */
|
||||
private $router;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct(IRequest $request,
|
||||
IUserSession $userSession,
|
||||
SearchComposer $composer,
|
||||
IRouter $router) {
|
||||
IRouter $router,
|
||||
IURLGenerator $urlGenerator) {
|
||||
parent::__construct('core', $request);
|
||||
|
||||
$this->composer = $composer;
|
||||
$this->userSession = $userSession;
|
||||
$this->router = $router;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -127,7 +133,7 @@ class UnifiedSearchController extends OCSController {
|
|||
|
||||
// Optionally strip webroot from URL. Required for route matching on setups
|
||||
// with Nextcloud in a webserver subfolder (webroot).
|
||||
$webroot = \OC::$WEBROOT;
|
||||
$webroot = $this->urlGenerator->getWebroot();
|
||||
if ($webroot !== '' && substr($urlPath, 0, strlen($webroot)) === $webroot) {
|
||||
$urlPath = substr($urlPath, strlen($webroot));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,4 +276,11 @@ class URLGenerator implements IURLGenerator {
|
|||
}
|
||||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string webroot part of the base url
|
||||
*/
|
||||
public function getWebroot(): string {
|
||||
return \OC::$WEBROOT;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,4 +102,10 @@ interface IURLGenerator {
|
|||
* @since 13.0.0
|
||||
*/
|
||||
public function getBaseUrl(): string;
|
||||
|
||||
/**
|
||||
* @return string webroot part of the base url
|
||||
* @since 23.0.0
|
||||
*/
|
||||
public function getWebroot(): string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,6 +179,12 @@ class UrlGeneratorTest extends \Test\TestCase {
|
|||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetWebroot() {
|
||||
\OC::$WEBROOT = '/nextcloud';
|
||||
$actual = $this->urlGenerator->getWebroot();
|
||||
$this->assertEquals(\OC::$WEBROOT, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideOCSRoutes
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue