[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/conduit/ -> DiffusionQueryConduitAPIMethod.php (source)

   1  <?php
   2  
   3  abstract class DiffusionQueryConduitAPIMethod
   4    extends DiffusionConduitAPIMethod {
   5  
   6    public function shouldAllowPublic() {
   7      return true;
   8    }
   9  
  10    public function getMethodStatus() {
  11      return self::METHOD_STATUS_UNSTABLE;
  12    }
  13  
  14    public function getMethodStatusDescription() {
  15      return pht(
  16        'See T2784 - migrating diffusion working copy calls to conduit methods. '.
  17        'Until that task is completed (and possibly after) these methods are '.
  18        'unstable.');
  19    }
  20  
  21    private $diffusionRequest;
  22    private $repository;
  23  
  24    protected function setDiffusionRequest(DiffusionRequest $request) {
  25      $this->diffusionRequest = $request;
  26      return $this;
  27    }
  28  
  29    protected function getDiffusionRequest() {
  30      return $this->diffusionRequest;
  31    }
  32  
  33    protected function getRepository(ConduitAPIRequest $request) {
  34      return $this->getDiffusionRequest()->getRepository();
  35    }
  36  
  37    final public function defineErrorTypes() {
  38      return $this->defineCustomErrorTypes() +
  39        array(
  40          'ERR-UNKNOWN-REPOSITORY' =>
  41            pht('There is no repository with that callsign.'),
  42          'ERR-UNKNOWN-VCS-TYPE' =>
  43            pht('Unknown repository VCS type.'),
  44          'ERR-UNSUPPORTED-VCS' =>
  45            pht('VCS is not supported for this method.'),
  46        );
  47    }
  48  
  49    /**
  50     * Subclasses should override this to specify custom error types.
  51     */
  52    protected function defineCustomErrorTypes() {
  53      return array();
  54    }
  55  
  56    final public function defineParamTypes() {
  57      return $this->defineCustomParamTypes() +
  58        array(
  59          'callsign' => 'required string',
  60          'branch' => 'optional string',
  61        );
  62    }
  63  
  64    /**
  65     * Subclasses should override this to specify custom param types.
  66     */
  67    protected function defineCustomParamTypes() {
  68      return array();
  69    }
  70  
  71    /**
  72     * Subclasses should override these methods with the proper result for the
  73     * pertinent version control system, e.g. getGitResult for Git.
  74     *
  75     * If the result is not supported for that VCS, do not implement it. e.g.
  76     * Subversion (SVN) does not support branches.
  77     */
  78    protected function getGitResult(ConduitAPIRequest $request) {
  79      throw new ConduitException('ERR-UNSUPPORTED-VCS');
  80    }
  81    protected function getSVNResult(ConduitAPIRequest $request) {
  82      throw new ConduitException('ERR-UNSUPPORTED-VCS');
  83    }
  84    protected function getMercurialResult(ConduitAPIRequest $request) {
  85      throw new ConduitException('ERR-UNSUPPORTED-VCS');
  86    }
  87  
  88    /**
  89     * This method is final because most queries will need to construct a
  90     * @{class:DiffusionRequest} and use it. Consolidating this codepath and
  91     * enforcing @{method:getDiffusionRequest} works when we need it is good.
  92     *
  93     * @{method:getResult} should be overridden by subclasses as necessary, e.g.
  94     * there is a common operation across all version control systems that
  95     * should occur after @{method:getResult}, like formatting a timestamp.
  96     */
  97    final protected function execute(ConduitAPIRequest $request) {
  98      $drequest = DiffusionRequest::newFromDictionary(
  99        array(
 100          'user' => $request->getUser(),
 101          'callsign' => $request->getValue('callsign'),
 102          'branch' => $request->getValue('branch'),
 103          'path' => $request->getValue('path'),
 104          'commit' => $request->getValue('commit'),
 105          'initFromConduit' => false,
 106        ));
 107  
 108      $this->setDiffusionRequest($drequest);
 109  
 110      return $this->getResult($request);
 111    }
 112  
 113    protected function getResult(ConduitAPIRequest $request) {
 114      $repository = $this->getRepository($request);
 115      $result = null;
 116      switch ($repository->getVersionControlSystem()) {
 117        case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
 118          $result = $this->getGitResult($request);
 119          break;
 120        case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
 121          $result = $this->getMercurialResult($request);
 122          break;
 123        case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
 124          $result = $this->getSVNResult($request);
 125          break;
 126        default:
 127          throw new ConduitException('ERR-UNKNOWN-VCS-TYPE');
 128          break;
 129      }
 130      return $result;
 131    }
 132  
 133  }


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