Differential D12460 Diff 29957 src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php
Show All 24 Lines | public function loadResults() { | ||||
$offset = $this->getOffset(); | $offset = $this->getOffset(); | ||||
$limit = $this->getLimit(); | $limit = $this->getLimit(); | ||||
// If the input query is a function like `members(platy`, and we can | // If the input query is a function like `members(platy`, and we can | ||||
// parse the function, we strip the function off and hand the stripped | // parse the function, we strip the function off and hand the stripped | ||||
// query to child sources. This makes it easier to implement function | // query to child sources. This makes it easier to implement function | ||||
// sources in terms of real object sources. | // sources in terms of real object sources. | ||||
$raw_query = $this->getRawQuery(); | $raw_query = $this->getRawQuery(); | ||||
$is_function = false; | |||||
if (self::isFunctionToken($raw_query)) { | if (self::isFunctionToken($raw_query)) { | ||||
$function = $this->parseFunction($raw_query, $allow_partial = true); | $is_function = true; | ||||
if ($function) { | |||||
$raw_query = head($function['argv']); | |||||
} | |||||
} | } | ||||
$stack = $this->getFunctionStack(); | |||||
$results = array(); | $results = array(); | ||||
foreach ($this->getUsableDatasources() as $source) { | foreach ($this->getUsableDatasources() as $source) { | ||||
$source_stack = $stack; | |||||
$source_query = $raw_query; | |||||
if ($is_function) { | |||||
// If this source can't handle the function, skip it. | |||||
$function = $source->parseFunction($raw_query, $allow_partial = true); | |||||
if (!$function) { | |||||
continue; | |||||
} | |||||
// If this source handles the function directly, strip the function. | |||||
// Otherwise, this is something like a composite source which has | |||||
// some internal source which can evaluate the function, but will | |||||
// perform stripping later. | |||||
if ($source->shouldStripFunction($function['name'])) { | |||||
$source_query = head($function['argv']); | |||||
$source_stack[] = $function['name']; | |||||
} | |||||
} | |||||
$source | $source | ||||
->setRawQuery($raw_query) | ->setFunctionStack($source_stack) | ||||
->setRawQuery($source_query) | |||||
->setQuery($this->getQuery()) | ->setQuery($this->getQuery()) | ||||
->setViewer($this->getViewer()); | ->setViewer($this->getViewer()); | ||||
if ($limit) { | if ($limit) { | ||||
$source->setLimit($offset + $limit); | $source->setLimit($offset + $limit); | ||||
} | } | ||||
$source_results = $source->loadResults(); | $source_results = $source->loadResults(); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | foreach ($this->getUsableDatasources() as $source) { | ||||
if ($source->canEvaluateFunction($function)) { | if ($source->canEvaluateFunction($function)) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return parent::canEvaluateFunction($function); | return parent::canEvaluateFunction($function); | ||||
} | } | ||||
protected function evaluateFunction($function, array $argv) { | protected function evaluateFunction($function, array $argv) { | ||||
foreach ($this->getUsableDatasources() as $source) { | foreach ($this->getUsableDatasources() as $source) { | ||||
if ($source->canEvaluateFunction($function)) { | if ($source->canEvaluateFunction($function)) { | ||||
return $source->evaluateFunction($function, $argv); | return $source->evaluateFunction($function, $argv); | ||||
} | } | ||||
} | } | ||||
return parent::evaluateFunction($function, $argv); | return parent::evaluateFunction($function, $argv); | ||||
Show All 14 Lines |