Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/field/PhabricatorSearchField.php
<?php | <?php | ||||
/** | /** | ||||
* @task config Configuring Fields | * @task config Configuring Fields | ||||
* @task error Handling Errors | * @task error Handling Errors | ||||
* @task io Reading and Writing Field Values | * @task io Reading and Writing Field Values | ||||
* @task conduit Integration with Conduit | |||||
* @task util Utility Methods | * @task util Utility Methods | ||||
*/ | */ | ||||
abstract class PhabricatorSearchField extends Phobject { | abstract class PhabricatorSearchField extends Phobject { | ||||
private $key; | private $key; | ||||
private $conduitKey; | |||||
private $viewer; | private $viewer; | ||||
private $value; | private $value; | ||||
private $label; | private $label; | ||||
private $aliases = array(); | private $aliases = array(); | ||||
private $errors = array(); | private $errors = array(); | ||||
/* -( Configuring Fields )------------------------------------------------- */ | /* -( Configuring Fields )------------------------------------------------- */ | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | /* -( Configuring Fields )------------------------------------------------- */ | ||||
* @return list<string> List of aliases for this field. | * @return list<string> List of aliases for this field. | ||||
* @task config | * @task config | ||||
*/ | */ | ||||
public function getAliases() { | public function getAliases() { | ||||
return $this->aliases; | return $this->aliases; | ||||
} | } | ||||
/** | |||||
* Provide an alternate field key for Conduit. | |||||
* | |||||
* This can allow you to choose a more usable key for API endpoints. | |||||
* If no key is provided, the main key is used. | |||||
* | |||||
* @param string Alternate key for Conduit. | |||||
* @return this | |||||
* @task config | |||||
*/ | |||||
public function setConduitKey($conduit_key) { | |||||
$this->conduitKey = $conduit_key; | |||||
return $this; | |||||
} | |||||
/** | |||||
* Get the field key for use in Conduit. | |||||
* | |||||
* @return string Conduit key for this field. | |||||
* @task config | |||||
*/ | |||||
public function getConduitKey() { | |||||
if ($this->conduitKey !== null) { | |||||
return $this->conduitKey; | |||||
} | |||||
return $this->getKey(); | |||||
} | |||||
/* -( Handling Errors )---------------------------------------------------- */ | /* -( Handling Errors )---------------------------------------------------- */ | ||||
protected function addError($short, $long) { | protected function addError($short, $long) { | ||||
$this->errors[] = array($short, $long); | $this->errors[] = array($short, $long); | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | /* -( Reading and Writing Field Values )----------------------------------- */ | ||||
protected function getDefaultValue() { | protected function getDefaultValue() { | ||||
return null; | return null; | ||||
} | } | ||||
public function getValueForQuery($value) { | public function getValueForQuery($value) { | ||||
return $value; | return $value; | ||||
} | } | ||||
public function getValueExistsInConduitRequest(array $constraints) { | |||||
return array_key_exists($this->getKey(), $constraints); | |||||
} | |||||
public function readValueFromConduitRequest(array $constraints) { | |||||
return idx($constraints, $this->getKey()); | |||||
} | |||||
/* -( Rendering Controls )------------------------------------------------- */ | /* -( Rendering Controls )------------------------------------------------- */ | ||||
protected function newControl() { | protected function newControl() { | ||||
throw new PhutilMethodNotImplementedException(); | throw new PhutilMethodNotImplementedException(); | ||||
} | } | ||||
Show All 9 Lines | /* -( Rendering Controls )------------------------------------------------- */ | ||||
} | } | ||||
public function appendToForm(AphrontFormView $form) { | public function appendToForm(AphrontFormView $form) { | ||||
$form->appendControl($this->renderControl()); | $form->appendControl($this->renderControl()); | ||||
return $this; | return $this; | ||||
} | } | ||||
/* -( Integration with Conduit )------------------------------------------- */ | |||||
/** | |||||
* @task conduit | |||||
*/ | |||||
final public function getConduitParameterType() { | |||||
$type = $this->newConduitParameterType(); | |||||
if ($type) { | |||||
$type->setViewer($this->getViewer()); | |||||
} | |||||
return $type; | |||||
} | |||||
protected function newConduitParameterType() { | |||||
return null; | |||||
} | |||||
public function getValueExistsInConduitRequest(array $constraints) { | |||||
return $this->getConduitParameterType()->getExists( | |||||
$constraints, | |||||
$this->getConduitKey()); | |||||
} | |||||
public function readValueFromConduitRequest(array $constraints) { | |||||
return $this->getConduitParameterType()->getValue( | |||||
$constraints, | |||||
$this->getConduitKey()); | |||||
} | |||||
/* -( Utility Methods )----------------------------------------------------- */ | /* -( Utility Methods )----------------------------------------------------- */ | ||||
/** | /** | ||||
* Read a list of items from the request, in either array format or string | * Read a list of items from the request, in either array format or string | ||||
* format: | * format: | ||||
* | * | ||||
* list[]=item1&list[]=item2 | * list[]=item1&list[]=item2 | ||||
Show All 19 Lines | protected function getListFromRequest( | ||||
if (!$list) { | if (!$list) { | ||||
return array(); | return array(); | ||||
} | } | ||||
return $list; | return $list; | ||||
} | } | ||||
public function getKeyForConduit() { | |||||
// TODO: This shouldn't really be different, but internal handling of | |||||
// custom field keys is a bit of a mess for now. | |||||
return $this->getKey(); | |||||
} | |||||
} | } |