[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionController.php (source)

   1  <?php
   2  
   3  abstract class DiffusionController extends PhabricatorController {
   4  
   5    protected $diffusionRequest;
   6  
   7    public function setDiffusionRequest(DiffusionRequest $request) {
   8      $this->diffusionRequest = $request;
   9      return $this;
  10    }
  11  
  12    protected function getDiffusionRequest() {
  13      if (!$this->diffusionRequest) {
  14        throw new Exception('No Diffusion request object!');
  15      }
  16      return $this->diffusionRequest;
  17    }
  18  
  19    public function willBeginExecution() {
  20      $request = $this->getRequest();
  21  
  22      // Check if this is a VCS request, e.g. from "git clone", "hg clone", or
  23      // "svn checkout". If it is, we jump off into repository serving code to
  24      // process the request.
  25      if (DiffusionServeController::isVCSRequest($request)) {
  26        $serve_controller = id(new DiffusionServeController())
  27          ->setCurrentApplication($this->getCurrentApplication());
  28        return $this->delegateToController($serve_controller);
  29      }
  30  
  31      return parent::willBeginExecution();
  32    }
  33  
  34    public function willProcessRequest(array $data) {
  35      if (isset($data['callsign'])) {
  36        $drequest = DiffusionRequest::newFromAphrontRequestDictionary(
  37          $data,
  38          $this->getRequest());
  39        $this->setDiffusionRequest($drequest);
  40      }
  41    }
  42  
  43    public function buildCrumbs(array $spec = array()) {
  44      $crumbs = $this->buildApplicationCrumbs();
  45      $crumb_list = $this->buildCrumbList($spec);
  46      foreach ($crumb_list as $crumb) {
  47        $crumbs->addCrumb($crumb);
  48      }
  49      return $crumbs;
  50    }
  51  
  52    private function buildCrumbList(array $spec = array()) {
  53  
  54      $spec = $spec + array(
  55        'commit'  => null,
  56        'tags'    => null,
  57        'branches'    => null,
  58        'view'    => null,
  59      );
  60  
  61      $crumb_list = array();
  62  
  63      // On the home page, we don't have a DiffusionRequest.
  64      if ($this->diffusionRequest) {
  65        $drequest = $this->getDiffusionRequest();
  66        $repository = $drequest->getRepository();
  67      } else {
  68        $drequest = null;
  69        $repository = null;
  70      }
  71  
  72      if (!$repository) {
  73        return $crumb_list;
  74      }
  75  
  76      $callsign = $repository->getCallsign();
  77      $repository_name = $repository->getName();
  78  
  79      if (!$spec['commit'] && !$spec['tags'] && !$spec['branches']) {
  80        $branch_name = $drequest->getBranch();
  81        if ($branch_name) {
  82          $repository_name .= ' ('.$branch_name.')';
  83        }
  84      }
  85  
  86      $crumb = id(new PhabricatorCrumbView())
  87        ->setName($repository_name);
  88      if (!$spec['view'] && !$spec['commit'] &&
  89          !$spec['tags'] && !$spec['branches']) {
  90        $crumb_list[] = $crumb;
  91        return $crumb_list;
  92      }
  93      $crumb->setHref(
  94        $drequest->generateURI(
  95          array(
  96            'action' => 'branch',
  97            'path' => '/',
  98          )));
  99      $crumb_list[] = $crumb;
 100  
 101      $stable_commit = $drequest->getStableCommit();
 102  
 103      if ($spec['tags']) {
 104        $crumb = new PhabricatorCrumbView();
 105        if ($spec['commit']) {
 106          $crumb->setName(
 107            pht('Tags for %s', 'r'.$callsign.$stable_commit));
 108          $crumb->setHref($drequest->generateURI(
 109            array(
 110              'action' => 'commit',
 111              'commit' => $drequest->getStableCommit(),
 112            )));
 113        } else {
 114          $crumb->setName(pht('Tags'));
 115        }
 116        $crumb_list[] = $crumb;
 117        return $crumb_list;
 118      }
 119  
 120      if ($spec['branches']) {
 121        $crumb = id(new PhabricatorCrumbView())
 122          ->setName(pht('Branches'));
 123        $crumb_list[] = $crumb;
 124        return $crumb_list;
 125      }
 126  
 127      if ($spec['commit']) {
 128        $crumb = id(new PhabricatorCrumbView())
 129          ->setName("r{$callsign}{$stable_commit}")
 130          ->setHref("r{$callsign}{$stable_commit}");
 131        $crumb_list[] = $crumb;
 132        return $crumb_list;
 133      }
 134  
 135      $crumb = new PhabricatorCrumbView();
 136      $view = $spec['view'];
 137  
 138      switch ($view) {
 139        case 'history':
 140          $view_name = pht('History');
 141          break;
 142        case 'browse':
 143          $view_name = pht('Browse');
 144          break;
 145        case 'lint':
 146          $view_name = pht('Lint');
 147          break;
 148        case 'change':
 149          $view_name = pht('Change');
 150          break;
 151      }
 152  
 153      $crumb = id(new PhabricatorCrumbView())
 154        ->setName($view_name);
 155  
 156      $crumb_list[] = $crumb;
 157      return $crumb_list;
 158    }
 159  
 160    protected function callConduitWithDiffusionRequest(
 161      $method,
 162      array $params = array()) {
 163  
 164      $user = $this->getRequest()->getUser();
 165      $drequest = $this->getDiffusionRequest();
 166  
 167      return DiffusionQuery::callConduitWithDiffusionRequest(
 168        $user,
 169        $drequest,
 170        $method,
 171        $params);
 172    }
 173  
 174    protected function getRepositoryControllerURI(
 175      PhabricatorRepository $repository,
 176      $path) {
 177      return $this->getApplicationURI($repository->getCallsign().'/'.$path);
 178    }
 179  
 180    protected function renderPathLinks(DiffusionRequest $drequest, $action) {
 181      $path = $drequest->getPath();
 182      $path_parts = array_filter(explode('/', trim($path, '/')));
 183  
 184      $divider = phutil_tag(
 185        'span',
 186        array(
 187          'class' => 'phui-header-divider',
 188        ),
 189        '/');
 190  
 191      $links = array();
 192      if ($path_parts) {
 193        $links[] = phutil_tag(
 194          'a',
 195          array(
 196            'href' => $drequest->generateURI(
 197              array(
 198                'action' => $action,
 199                'path' => '',
 200              )),
 201          ),
 202          'r'.$drequest->getRepository()->getCallsign());
 203        $links[] = $divider;
 204        $accum = '';
 205        $last_key = last_key($path_parts);
 206        foreach ($path_parts as $key => $part) {
 207          $accum .= '/'.$part;
 208          if ($key === $last_key) {
 209            $links[] = $part;
 210          } else {
 211            $links[] = phutil_tag(
 212              'a',
 213              array(
 214                'href' => $drequest->generateURI(
 215                  array(
 216                    'action' => $action,
 217                    'path' => $accum.'/',
 218                  )),
 219              ),
 220              $part);
 221            $links[] = $divider;
 222          }
 223        }
 224      } else {
 225        $links[] = 'r'.$drequest->getRepository()->getCallsign();
 226        $links[] = $divider;
 227      }
 228  
 229      return $links;
 230    }
 231  
 232    protected function renderStatusMessage($title, $body) {
 233      return id(new AphrontErrorView())
 234        ->setSeverity(AphrontErrorView::SEVERITY_WARNING)
 235        ->setTitle($title)
 236        ->appendChild($body);
 237    }
 238  
 239  }


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