Path: blob/master/src/applications/paste/conduit/PasteCreateConduitAPIMethod.php
12241 views
<?php12final class PasteCreateConduitAPIMethod extends PasteConduitAPIMethod {34public function getAPIMethodName() {5return 'paste.create';6}78public function getMethodDescription() {9return pht('Create a new paste.');10}1112public function getMethodStatus() {13return self::METHOD_STATUS_FROZEN;14}1516public function getMethodStatusDescription() {17return pht(18'This method is frozen and will eventually be deprecated. New code '.19'should use "paste.edit" instead.');20}2122protected function defineParamTypes() {23return array(24'content' => 'required string',25'title' => 'optional string',26'language' => 'optional string',27);28}2930protected function defineReturnType() {31return 'nonempty dict';32}3334protected function defineErrorTypes() {35return array(36'ERR-NO-PASTE' => pht('Paste may not be empty.'),37);38}3940protected function execute(ConduitAPIRequest $request) {41$content = $request->getValue('content');42$title = $request->getValue('title');43$language = $request->getValue('language');4445if ($content === null || !strlen($content)) {46throw new ConduitException('ERR-NO-PASTE');47}4849$title = nonempty($title, pht('Masterwork From Distant Lands'));50$language = nonempty($language, '');5152$viewer = $request->getUser();5354$paste = PhabricatorPaste::initializeNewPaste($viewer);5556$xactions = array();5758$xactions[] = id(new PhabricatorPasteTransaction())59->setTransactionType(PhabricatorPasteContentTransaction::TRANSACTIONTYPE)60->setNewValue($content);6162$xactions[] = id(new PhabricatorPasteTransaction())63->setTransactionType(PhabricatorPasteTitleTransaction::TRANSACTIONTYPE)64->setNewValue($title);6566if (strlen($language)) {67$xactions[] = id(new PhabricatorPasteTransaction())68->setTransactionType(69PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)70->setNewValue($language);71}7273$editor = id(new PhabricatorPasteEditor())74->setActor($viewer)75->setContinueOnNoEffect(true)76->setContentSource($request->newContentSource());7778$xactions = $editor->applyTransactions($paste, $xactions);7980$paste->attachRawContent($content);81return $this->buildPasteInfoDictionary($paste);82}8384}858687