mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
Allow third-party code to extend upstream datasources via EngineExtension
Summary: Depends on D19089. Fixes T13079. This is likely not the final form of this, but creates a defensible extension point. Test Plan: See T13079 for discussion. Maniphest Tasks: T13079 Differential Revision: https://secure.phabricator.com/D19090
This commit is contained in:
parent
d6edc3f4cc
commit
fe294d4034
3 changed files with 33 additions and 1 deletions
|
@ -34,4 +34,22 @@ final class PhabricatorDatasourceEngine extends Phobject {
|
|||
return null;
|
||||
}
|
||||
|
||||
public function newDatasourcesForCompositeDatasource(
|
||||
PhabricatorTypeaheadCompositeDatasource $datasource) {
|
||||
$viewer = $this->getViewer();
|
||||
$extensions = PhabricatorDatasourceEngineExtension::getAllExtensions();
|
||||
|
||||
$sources = array();
|
||||
foreach ($extensions as $extension) {
|
||||
$extension_sources = id(clone $extension)
|
||||
->setViewer($viewer)
|
||||
->newDatasourcesForCompositeDatasource($datasource);
|
||||
foreach ($extension_sources as $extension_source) {
|
||||
$sources[] = $extension_source;
|
||||
}
|
||||
}
|
||||
|
||||
return $sources;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,11 @@ abstract class PhabricatorDatasourceEngineExtension extends Phobject {
|
|||
return null;
|
||||
}
|
||||
|
||||
public function newDatasourcesForCompositeDatasource(
|
||||
PhabricatorTypeaheadCompositeDatasource $datasource) {
|
||||
return array();
|
||||
}
|
||||
|
||||
final public static function getAllExtensions() {
|
||||
return id(new PhutilClassMapQuery())
|
||||
->setAncestorClass(__CLASS__)
|
||||
|
|
|
@ -223,8 +223,17 @@ abstract class PhabricatorTypeaheadCompositeDatasource
|
|||
|
||||
private function getUsableDatasources() {
|
||||
if ($this->usable === null) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$sources = $this->getComponentDatasources();
|
||||
|
||||
$extension_sources = id(new PhabricatorDatasourceEngine())
|
||||
->setViewer($viewer)
|
||||
->newDatasourcesForCompositeDatasource($this);
|
||||
foreach ($extension_sources as $extension_source) {
|
||||
$sources[] = $extension_source;
|
||||
}
|
||||
|
||||
$usable = array();
|
||||
foreach ($sources as $source) {
|
||||
$application_class = $source->getDatasourceApplicationClass();
|
||||
|
@ -239,7 +248,7 @@ abstract class PhabricatorTypeaheadCompositeDatasource
|
|||
}
|
||||
}
|
||||
|
||||
$source->setViewer($this->getViewer());
|
||||
$source->setViewer($viewer);
|
||||
$usable[] = $source;
|
||||
}
|
||||
$this->usable = $usable;
|
||||
|
|
Loading…
Reference in a new issue