mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-30 18:52:42 +01:00
601aaa5a86
Summary: Ref T10537. For Nuance, I want to introduce new sources (like "GitHub" or "GitHub via Nuance" or something) but this needs to modularize eventually. Split ContentSource apart so applications can add new content sources. Test Plan: This change has huge surface area, so I'll hold it until post-release. I think it's fairly safe (and if it does break anything, the breaks should be fatals, not anything subtle or difficult to fix), there's just no reason not to hold it for a few hours. - Viewed new module page. - Grepped for all removed functions/constants. - Viewed some transactions. - Hovered over timestamps to get content source details. - Added a comment via Conduit. - Added a comment via web. - Ran `bin/storage upgrade --namespace XXXXX --no-quickstart -f` to re-run all historic migrations. - Generated some objects with `bin/lipsum`. - Ran a bulk job on some tasks. - Ran unit tests. {F1190182} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10537 Differential Revision: https://secure.phabricator.com/D15521
92 lines
2.2 KiB
PHP
92 lines
2.2 KiB
PHP
<?php
|
|
|
|
abstract class PhabricatorContentSource extends Phobject {
|
|
|
|
private $source;
|
|
private $params = array();
|
|
|
|
abstract public function getSourceName();
|
|
abstract public function getSourceDescription();
|
|
|
|
final public function getSourceTypeConstant() {
|
|
return $this->getPhobjectClassConstant('SOURCECONST', 32);
|
|
}
|
|
|
|
final public static function getAllContentSources() {
|
|
return id(new PhutilClassMapQuery())
|
|
->setAncestorClass(__CLASS__)
|
|
->setUniqueMethod('getSourceTypeConstant')
|
|
->execute();
|
|
}
|
|
|
|
/**
|
|
* Construct a new content source object.
|
|
*
|
|
* @param const The source type constant to build a source for.
|
|
* @param array Source parameters.
|
|
* @param bool True to suppress errors and force construction of a source
|
|
* even if the source type is not valid.
|
|
* @return PhabricatorContentSource New source object.
|
|
*/
|
|
final public static function newForSource(
|
|
$source,
|
|
array $params = array(),
|
|
$force = false) {
|
|
|
|
$map = self::getAllContentSources();
|
|
if (isset($map[$source])) {
|
|
$obj = clone $map[$source];
|
|
} else {
|
|
if ($force) {
|
|
$obj = new PhabricatorUnknownContentSource();
|
|
} else {
|
|
throw new Exception(
|
|
pht(
|
|
'Content source type "%s" is not known to Phabricator!',
|
|
$source));
|
|
}
|
|
}
|
|
|
|
$obj->source = $source;
|
|
$obj->params = $params;
|
|
|
|
return $obj;
|
|
}
|
|
|
|
public static function newFromSerialized($serialized) {
|
|
$dict = json_decode($serialized, true);
|
|
if (!is_array($dict)) {
|
|
$dict = array();
|
|
}
|
|
|
|
$source = idx($dict, 'source');
|
|
$params = idx($dict, 'params');
|
|
if (!is_array($params)) {
|
|
$params = array();
|
|
}
|
|
|
|
return self::newForSource($source, $params, true);
|
|
}
|
|
|
|
public static function newFromRequest(AphrontRequest $request) {
|
|
return self::newForSource(
|
|
PhabricatorWebContentSource::SOURCECONST);
|
|
}
|
|
|
|
final public function serialize() {
|
|
return phutil_json_encode(
|
|
array(
|
|
'source' => $this->getSource(),
|
|
'params' => $this->params,
|
|
));
|
|
}
|
|
|
|
final public function getSource() {
|
|
return $this->source;
|
|
}
|
|
|
|
final public function getContentSourceParameter($key, $default = null) {
|
|
return idx($this->params, $key, $default);
|
|
}
|
|
|
|
}
|