當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DifferentialDiff::initializeNewDiff方法代碼示例

本文整理匯總了PHP中DifferentialDiff::initializeNewDiff方法的典型用法代碼示例。如果您正苦於以下問題:PHP DifferentialDiff::initializeNewDiff方法的具體用法?PHP DifferentialDiff::initializeNewDiff怎麽用?PHP DifferentialDiff::initializeNewDiff使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DifferentialDiff的用法示例。


在下文中一共展示了DifferentialDiff::initializeNewDiff方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handleRequest

 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     // If we're on the "Update Diff" workflow, load the revision we're going
     // to update.
     $revision = null;
     $revision_id = $request->getURIData('revisionID');
     if ($revision_id) {
         $revision = id(new DifferentialRevisionQuery())->setViewer($viewer)->withIDs(array($revision_id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$revision) {
             return new Aphront404Response();
         }
     }
     $diff = null;
     // This object is just for policy stuff
     $diff_object = DifferentialDiff::initializeNewDiff($viewer);
     $repository_phid = null;
     $errors = array();
     $e_diff = null;
     $e_file = null;
     $validation_exception = null;
     if ($request->isFormPost()) {
         $repository_tokenizer = $request->getArr(id(new DifferentialRepositoryField())->getFieldKey());
         if ($repository_tokenizer) {
             $repository_phid = reset($repository_tokenizer);
         }
         if ($request->getFileExists('diff-file')) {
             $diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
         } else {
             $diff = $request->getStr('diff');
         }
         if (!strlen($diff)) {
             $errors[] = pht('You can not create an empty diff. Paste a diff or upload a ' . 'file containing a diff.');
             $e_diff = pht('Required');
             $e_file = pht('Required');
         }
         if (!$errors) {
             try {
                 $call = new ConduitCall('differential.createrawdiff', array('diff' => $diff, 'repositoryPHID' => $repository_phid, 'viewPolicy' => $request->getStr('viewPolicy')));
                 $call->setUser($viewer);
                 $result = $call->execute();
                 $diff_id = $result['id'];
                 $uri = $this->getApplicationURI("diff/{$diff_id}/");
                 $uri = new PhutilURI($uri);
                 if ($revision) {
                     $uri->setQueryParam('revisionID', $revision->getID());
                 }
                 return id(new AphrontRedirectResponse())->setURI($uri);
             } catch (PhabricatorApplicationTransactionValidationException $ex) {
                 $validation_exception = $ex;
             }
         }
     }
     $form = new AphrontFormView();
     $arcanist_href = PhabricatorEnv::getDoclink('Arcanist User Guide');
     $arcanist_link = phutil_tag('a', array('href' => $arcanist_href, 'target' => '_blank'), pht('Learn More'));
     $cancel_uri = $this->getApplicationURI();
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($diff_object)->execute();
     $info_view = null;
     if (!$request->isFormPost()) {
         $info_view = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->setErrors(array(array(pht('The best way to create a diff is to use the Arcanist ' . 'command-line tool.'), ' ', $arcanist_link), pht('You can also paste a diff below, or upload a file ' . 'containing a diff (for example, from %s, %s or %s).', phutil_tag('tt', array(), 'svn diff'), phutil_tag('tt', array(), 'git diff'), phutil_tag('tt', array(), 'hg diff --git'))));
     }
     if ($revision) {
         $title = pht('Update Diff');
         $header = pht('Update Diff');
         $button = pht('Continue');
     } else {
         $title = pht('Create Diff');
         $header = pht('Create New Diff');
         $button = pht('Create Diff');
     }
     $form->setEncType('multipart/form-data')->setUser($viewer);
     if ($revision) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Updating Revision'))->setValue($viewer->renderHandle($revision->getPHID())));
     }
     if ($repository_phid) {
         $repository_value = array($repository_phid);
     } else {
         $repository_value = array();
     }
     $form->appendChild(id(new AphrontFormTextAreaControl())->setLabel(pht('Raw Diff'))->setName('diff')->setValue($diff)->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setError($e_diff))->appendChild(id(new AphrontFormFileControl())->setLabel(pht('Raw Diff From File'))->setName('diff-file')->setError($e_file))->appendControl(id(new AphrontFormTokenizerControl())->setName(id(new DifferentialRepositoryField())->getFieldKey())->setLabel(pht('Repository'))->setDatasource(new DiffusionRepositoryDatasource())->setValue($repository_value)->setLimit(1))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setName('viewPolicy')->setPolicyObject($diff_object)->setPolicies($policies)->setCapability(PhabricatorPolicyCapability::CAN_VIEW))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($button));
     $form_box = id(new PHUIObjectBoxView())->setHeaderText($header)->setValidationException($validation_exception)->setForm($form)->setFormErrors($errors);
     if ($info_view) {
         $form_box->setInfoView($info_view);
     }
     $crumbs = $this->buildApplicationCrumbs();
     if ($revision) {
         $crumbs->addTextCrumb($revision->getMonogram(), '/' . $revision->getMonogram());
     }
     $crumbs->addTextCrumb($title);
     return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $title));
 }
開發者ID:pugong,項目名稱:phabricator,代碼行數:92,代碼來源:DifferentialDiffCreateController.php


注:本文中的DifferentialDiff::initializeNewDiff方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。