[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class ReleephFieldSpecification 4 extends PhabricatorCustomField 5 implements PhabricatorMarkupInterface { 6 7 // TODO: This is temporary, until ReleephFieldSpecification is more conformant 8 // to PhabricatorCustomField. 9 private $requestValue; 10 11 public function readValueFromRequest(AphrontRequest $request) { 12 $this->requestValue = $request->getStr($this->getRequiredStorageKey()); 13 return $this; 14 } 15 16 public function shouldAppearInPropertyView() { 17 return true; 18 } 19 20 public function renderPropertyViewLabel() { 21 return $this->getName(); 22 } 23 24 public function renderPropertyViewValue(array $handles) { 25 $key = $this->getRequiredStorageKey(); 26 $value = $this->getReleephRequest()->getDetail($key); 27 if ($value === '') { 28 return null; 29 } 30 return $value; 31 } 32 33 abstract public function getName(); 34 35 /* -( Storage )------------------------------------------------------------ */ 36 37 public function getStorageKey() { 38 return null; 39 } 40 41 public function getRequiredStorageKey() { 42 $key = $this->getStorageKey(); 43 if ($key === null) { 44 throw new PhabricatorCustomFieldImplementationIncompleteException($this); 45 } 46 if (strpos($key, '.') !== false) { 47 /** 48 * Storage keys are reused for form controls, and periods in form control 49 * names break HTML forms. 50 */ 51 throw new Exception( 52 "You can't use '.' in storage keys!"); 53 } 54 return $key; 55 } 56 57 public function shouldAppearInEditView() { 58 return $this->isEditable(); 59 } 60 61 final public function isEditable() { 62 return $this->getStorageKey() !== null; 63 } 64 65 final public function getValue() { 66 if ($this->requestValue !== null) { 67 return $this->requestValue; 68 } 69 70 $key = $this->getRequiredStorageKey(); 71 return $this->getReleephRequest()->getDetail($key); 72 } 73 74 final public function setValue($value) { 75 $key = $this->getRequiredStorageKey(); 76 return $this->getReleephRequest()->setDetail($key, $value); 77 } 78 79 /** 80 * @throws ReleephFieldParseException, to show an error. 81 */ 82 public function validate($value) { 83 return; 84 } 85 86 /** 87 * Turn values as they are stored in a ReleephRequest into a text that can be 88 * rendered as a transactions old/new values. 89 */ 90 public function normalizeForTransactionView( 91 PhabricatorApplicationTransaction $xaction, 92 $value) { 93 94 return $value; 95 } 96 97 98 /* -( Conduit )------------------------------------------------------------ */ 99 100 public function getKeyForConduit() { 101 return $this->getRequiredStorageKey(); 102 } 103 104 public function getValueForConduit() { 105 return $this->getValue(); 106 } 107 108 public function setValueFromConduitAPIRequest(ConduitAPIRequest $request) { 109 $value = idx( 110 $request->getValue('fields', array()), 111 $this->getRequiredStorageKey()); 112 $this->validate($value); 113 $this->setValue($value); 114 } 115 116 117 /* -( Arcanist )----------------------------------------------------------- */ 118 119 public function renderHelpForArcanist() { 120 return ''; 121 } 122 123 124 /* -( Context )------------------------------------------------------------ */ 125 126 private $releephProject; 127 private $releephBranch; 128 private $releephRequest; 129 private $user; 130 131 final public function setReleephProject(ReleephProject $rp) { 132 $this->releephProject = $rp; 133 return $this; 134 } 135 136 final public function setReleephBranch(ReleephBranch $rb) { 137 $this->releephRequest = $rb; 138 return $this; 139 } 140 141 final public function setReleephRequest(ReleephRequest $rr) { 142 $this->releephRequest = $rr; 143 return $this; 144 } 145 146 final public function setUser(PhabricatorUser $user) { 147 $this->user = $user; 148 return $this; 149 } 150 151 final public function getReleephProject() { 152 if (!$this->releephProject) { 153 return $this->getReleephBranch()->getProduct(); 154 } 155 return $this->releephProject; 156 } 157 158 final public function getReleephBranch() { 159 if (!$this->releephBranch) { 160 return $this->getReleephRequest()->getBranch(); 161 } 162 return $this->releephBranch; 163 } 164 165 final public function getReleephRequest() { 166 if (!$this->releephRequest) { 167 return $this->getObject(); 168 } 169 return $this->releephRequest; 170 } 171 172 final public function getUser() { 173 if (!$this->user) { 174 return $this->getViewer(); 175 } 176 return $this->user; 177 } 178 179 /* -( Commit Messages )---------------------------------------------------- */ 180 181 public function shouldAppearOnCommitMessage() { 182 return false; 183 } 184 185 public function renderLabelForCommitMessage() { 186 throw new PhabricatorCustomFieldImplementationIncompleteException($this); 187 } 188 189 public function renderValueForCommitMessage() { 190 throw new PhabricatorCustomFieldImplementationIncompleteException($this); 191 } 192 193 public function shouldAppearOnRevertMessage() { 194 return false; 195 } 196 197 public function renderLabelForRevertMessage() { 198 return $this->renderLabelForCommitMessage(); 199 } 200 201 public function renderValueForRevertMessage() { 202 return $this->renderValueForCommitMessage(); 203 } 204 205 206 /* -( Markup Interface )--------------------------------------------------- */ 207 208 const MARKUP_FIELD_GENERIC = 'releeph:generic-markup-field'; 209 210 private $engine; 211 212 /** 213 * @{class:ReleephFieldSpecification} implements much of 214 * @{interface:PhabricatorMarkupInterface} for you. If you return true from 215 * `shouldMarkup()`, and implement `getMarkupText()` then your text will be 216 * rendered through the Phabricator markup pipeline. 217 * 218 * Output is retrievable with `getMarkupEngineOutput()`. 219 */ 220 public function shouldMarkup() { 221 return false; 222 } 223 224 public function getMarkupText($field) { 225 throw new PhabricatorCustomFieldImplementationIncompleteException($this); 226 } 227 228 final public function getMarkupEngineOutput() { 229 return $this->engine->getOutput($this, self::MARKUP_FIELD_GENERIC); 230 } 231 232 final public function setMarkupEngine(PhabricatorMarkupEngine $engine) { 233 $this->engine = $engine; 234 $engine->addObject($this, self::MARKUP_FIELD_GENERIC); 235 return $this; 236 } 237 238 final public function getMarkupFieldKey($field) { 239 return sprintf( 240 '%s:%s:%s:%s', 241 $this->getReleephRequest()->getPHID(), 242 $this->getStorageKey(), 243 $field, 244 PhabricatorHash::digest($this->getMarkupText($field))); 245 } 246 247 final public function newMarkupEngine($field) { 248 return PhabricatorMarkupEngine::newDifferentialMarkupEngine(); 249 } 250 251 final public function didMarkupText( 252 $field, 253 $output, 254 PhutilMarkupEngine $engine) { 255 256 return $output; 257 } 258 259 final public function shouldUseMarkupCache($field) { 260 return true; 261 } 262 263 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |