[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/paste/conduit/ -> PasteCreateConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class PasteCreateConduitAPIMethod extends PasteConduitAPIMethod {
   4  
   5    public function getAPIMethodName() {
   6      return 'paste.create';
   7    }
   8  
   9    public function getMethodDescription() {
  10      return 'Create a new paste.';
  11    }
  12  
  13    public function defineParamTypes() {
  14      return array(
  15        'content'   => 'required string',
  16        'title'     => 'optional string',
  17        'language'  => 'optional string',
  18      );
  19    }
  20  
  21    public function defineReturnType() {
  22      return 'nonempty dict';
  23    }
  24  
  25    public function defineErrorTypes() {
  26      return array(
  27        'ERR-NO-PASTE' => 'Paste may not be empty.',
  28      );
  29    }
  30  
  31    protected function execute(ConduitAPIRequest $request) {
  32      $content  = $request->getValue('content');
  33      $title    = $request->getValue('title');
  34      $language = $request->getValue('language');
  35  
  36      if (!strlen($content)) {
  37        throw new ConduitException('ERR-NO-PASTE');
  38      }
  39  
  40      $title = nonempty($title, 'Masterwork From Distant Lands');
  41      $language = nonempty($language, '');
  42  
  43      $viewer = $request->getUser();
  44  
  45      $paste = PhabricatorPaste::initializeNewPaste($viewer);
  46  
  47      $file = PhabricatorPasteEditor::initializeFileForPaste(
  48        $viewer,
  49        $title,
  50        $content);
  51  
  52      $xactions = array();
  53  
  54      $xactions[] = id(new PhabricatorPasteTransaction())
  55        ->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)
  56        ->setNewValue($file->getPHID());
  57  
  58      $xactions[] = id(new PhabricatorPasteTransaction())
  59        ->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE)
  60        ->setNewValue($title);
  61  
  62      $xactions[] = id(new PhabricatorPasteTransaction())
  63        ->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE)
  64        ->setNewValue($language);
  65  
  66      $editor = id(new PhabricatorPasteEditor())
  67        ->setActor($viewer)
  68        ->setContentSourceFromConduitRequest($request);
  69  
  70      $xactions = $editor->applyTransactions($paste, $xactions);
  71  
  72      $paste->attachRawContent($content);
  73      return $this->buildPasteInfoDictionary($paste);
  74    }
  75  
  76  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1