[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class RemarkupProcessConduitAPIMethod extends ConduitAPIMethod { 4 5 public function getAPIMethodName() { 6 return 'remarkup.process'; 7 } 8 9 public function getMethodStatus() { 10 return self::METHOD_STATUS_UNSTABLE; 11 } 12 13 public function getMethodDescription() { 14 return 'Process text through remarkup in phabricator context.'; 15 } 16 17 public function defineReturnType() { 18 return 'nonempty dict'; 19 } 20 21 public function defineErrorTypes() { 22 return array( 23 'ERR-NO-CONTENT' => 'Content may not be empty.', 24 'ERR-INVALID-ENGINE' => 'Invalid markup engine.', 25 ); 26 } 27 28 public function defineParamTypes() { 29 $available_contexts = array_keys($this->getEngineContexts()); 30 $available_const = $this->formatStringConstants($available_contexts); 31 32 return array( 33 'context' => 'required '.$available_const, 34 'contents' => 'required list<string>', 35 ); 36 } 37 38 protected function execute(ConduitAPIRequest $request) { 39 $contents = $request->getValue('contents'); 40 $context = $request->getValue('context'); 41 42 $engine_class = idx($this->getEngineContexts(), $context); 43 if (!$engine_class) { 44 throw new ConduitException('ERR-INVALID_ENGINE'); 45 } 46 47 $engine = PhabricatorMarkupEngine::$engine_class(); 48 $engine->setConfig('viewer', $request->getUser()); 49 50 $results = array(); 51 foreach ($contents as $content) { 52 $text = $engine->markupText($content); 53 if ($text) { 54 $content = hsprintf('%s', $text)->getHTMLContent(); 55 } else { 56 $content = ''; 57 } 58 $results[] = array( 59 'content' => $content, 60 ); 61 } 62 return $results; 63 } 64 65 private function getEngineContexts() { 66 return array( 67 'phriction' => 'newPhrictionMarkupEngine', 68 'maniphest' => 'newManiphestMarkupEngine', 69 'differential' => 'newDifferentialMarkupEngine', 70 'phame' => 'newPhameMarkupEngine', 71 'feed' => 'newFeedMarkupEngine', 72 'diffusion' => 'newDiffusionMarkupEngine', 73 ); 74 } 75 76 }
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 |