diff options
author | Joas Schilling <coding@schilljs.com> | 2020-08-05 09:49:18 +0200 |
---|---|---|
committer | npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com> | 2020-08-05 12:52:16 +0000 |
commit | ea8f68bea6957ae459ff1ba6849b25354b3f0093 (patch) | |
tree | b6523d1ad1c01e55622fd31bfcfb27daabec0593 /lib | |
parent | d98f7c1bd83fc03fd297ebeac6279ffe17316950 (diff) | |
download | nextcloud-server-ea8f68bea6957ae459ff1ba6849b25354b3f0093.tar.gz nextcloud-server-ea8f68bea6957ae459ff1ba6849b25354b3f0093.zip |
Hand in the route and the parameters of the request
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Route/Router.php | 17 | ||||
-rw-r--r-- | lib/private/Search/SearchComposer.php | 9 | ||||
-rw-r--r-- | lib/private/Search/SearchQuery.php | 28 | ||||
-rw-r--r-- | lib/public/Search/IProvider.php | 5 | ||||
-rw-r--r-- | lib/public/Search/ISearchQuery.php | 12 |
5 files changed, 62 insertions, 9 deletions
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index de7c720f271..6de581ffa96 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -239,9 +239,9 @@ class Router implements IRouter { * * @param string $url The url to find * @throws \Exception - * @return void + * @return array */ - public function match($url) { + public function findMatchingRoute(string $url): array { if (substr($url, 0, 6) === '/apps/') { // empty string / 'apps' / $app / rest of the route list(, , $app,) = explode('/', $url, 4); @@ -287,6 +287,19 @@ class Router implements IRouter { } } + return $parameters; + } + + /** + * Find and execute the route matching $url + * + * @param string $url The url to find + * @throws \Exception + * @return void + */ + public function match($url) { + $parameters = $this->findMatchingRoute($url); + \OC::$server->getEventLogger()->start('run_route', 'Run route'); if (isset($parameters['caller'])) { $caller = $parameters['caller']; diff --git a/lib/private/Search/SearchComposer.php b/lib/private/Search/SearchComposer.php index f86626909c4..fdac9c5612a 100644 --- a/lib/private/Search/SearchComposer.php +++ b/lib/private/Search/SearchComposer.php @@ -109,19 +109,20 @@ class SearchComposer { * Get a list of all provider IDs & Names for the consecutive calls to `search` * Sort the list by the order property * - * @param string $from the url the user is currently at + * @param string $route the route the user is currently at + * @param array $routeParameters the parameters of the route the user is currently at * * @return array */ - public function getProviders(string $from): array { + public function getProviders(string $route, array $routeParameters): array { $this->loadLazyProviders(); $providers = array_values( - array_map(function (IProvider $provider) use ($from) { + array_map(function (IProvider $provider) use ($route, $routeParameters) { return [ 'id' => $provider->getId(), 'name' => $provider->getName(), - 'order' => $provider->getOrder($from) + 'order' => $provider->getOrder($route, $routeParameters), ]; }, $this->providers) ); diff --git a/lib/private/Search/SearchQuery.php b/lib/private/Search/SearchQuery.php index 186b4ccf18f..7ba63de90ec 100644 --- a/lib/private/Search/SearchQuery.php +++ b/lib/private/Search/SearchQuery.php @@ -42,20 +42,32 @@ class SearchQuery implements ISearchQuery { /** @var int|string|null */ private $cursor; + /** @var string */ + private $route; + + /** @var array */ + private $routeParameters; + /** * @param string $term * @param int $sortOrder * @param int $limit * @param int|string|null $cursor + * @param string $route + * @param array $routeParameters */ public function __construct(string $term, int $sortOrder = ISearchQuery::SORT_DATE_DESC, int $limit = self::LIMIT_DEFAULT, - $cursor = null) { + $cursor = null, + string $route = '', + array $routeParameters = []) { $this->term = $term; $this->sortOrder = $sortOrder; $this->limit = $limit; $this->cursor = $cursor; + $this->route = $route; + $this->routeParameters = $routeParameters; } /** @@ -85,4 +97,18 @@ class SearchQuery implements ISearchQuery { public function getCursor() { return $this->cursor; } + + /** + * @inheritDoc + */ + public function getRoute(): string { + return $this->route; + } + + /** + * @inheritDoc + */ + public function getRouteParameters(): array { + return $this->routeParameters; + } } diff --git a/lib/public/Search/IProvider.php b/lib/public/Search/IProvider.php index 5a6cfb3fd03..a91efa55fe1 100644 --- a/lib/public/Search/IProvider.php +++ b/lib/public/Search/IProvider.php @@ -68,13 +68,14 @@ interface IProvider { * Get the search provider order * The lower the int, the higher it will be sorted (0 will be before 10) * - * @param string $from the url the user is currently at. (e.g. /apps/files/?dir=/&fileid=982) + * @param string $route the route the user is currently at, e.g. files.view.index + * @param array $routeParameters the parameters of the route the user is currently at, e.g. [fileId = 982, dir = "/"] * * @return int * * @since 20.0.0 */ - public function getOrder(string $from): int; + public function getOrder(string $route, array $routeParameters): int; /** * Find matching search entries in an app diff --git a/lib/public/Search/ISearchQuery.php b/lib/public/Search/ISearchQuery.php index 00d538050d4..f89251dd134 100644 --- a/lib/public/Search/ISearchQuery.php +++ b/lib/public/Search/ISearchQuery.php @@ -76,4 +76,16 @@ interface ISearchQuery { * @since 20.0.0 */ public function getCursor(); + + /** + * @return string + * @since 20.0.0 + */ + public function getRoute(): string; + + /** + * @return array + * @since 20.0.0 + */ + public function getRouteParameters(): array; } |