Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / controller / DiffusionCloneController.php
blob8bc4faa1a2f30fc0b18c878f00f7f30e4f15b98f
1 <?php
3 final class DiffusionCloneController extends DiffusionController {
5 public function shouldAllowPublic() {
6 return true;
9 public function handleRequest(AphrontRequest $request) {
10 $viewer = $request->getViewer();
11 $response = $this->loadDiffusionContext();
12 if ($response) {
13 return $response;
16 $drequest = $this->getDiffusionRequest();
17 $repository = $drequest->getRepository();
19 $view = id(new PHUIPropertyListView())
20 ->setUser($viewer);
22 $display_never = PhabricatorRepositoryURI::DISPLAY_NEVER;
23 $warning = null;
25 $uris = $repository->getURIs();
26 foreach ($uris as $uri) {
27 if ($uri->getIsDisabled()) {
28 continue;
31 if ($uri->getEffectiveDisplayType() == $display_never) {
32 continue;
35 if ($repository->isSVN()) {
36 $label = phutil_tag_div('diffusion-clone-label', pht('Checkout'));
37 } else {
38 $label = phutil_tag_div('diffusion-clone-label', pht('Clone'));
41 $view->addProperty(
42 $label,
43 $this->renderCloneURI($repository, $uri));
46 if (!$view->hasAnyProperties()) {
47 $view = id(new PHUIInfoView())
48 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
49 ->appendChild(pht('Repository has no URIs set.'));
52 $info = null;
54 // Try to load alternatives. This may fail for repositories which have not
55 // cloned yet. If it does, just ignore it and continue.
56 try {
57 $alternatives = $drequest->getRefAlternatives();
58 } catch (ConduitClientException $ex) {
59 $alternatives = array();
62 if ($alternatives) {
63 $message = array(
64 pht(
65 'The ref "%s" is ambiguous in this repository.',
66 $drequest->getBranch()),
67 ' ',
68 phutil_tag(
69 'a',
70 array(
71 'href' => $drequest->generateURI(
72 array(
73 'action' => 'refs',
74 )),
76 pht('View Alternatives')),
79 $messages = array($message);
81 $warning = id(new PHUIInfoView())
82 ->setSeverity(PHUIInfoView::SEVERITY_WARNING)
83 ->setErrors(array($message));
86 $cancel_uri = $drequest->generateURI(
87 array(
88 'action' => 'branch',
89 'path' => '/',
90 ));
92 return $this->newDialog()
93 ->setTitle(pht('Clone Repository'))
94 ->setWidth(AphrontDialogView::WIDTH_FORM)
95 ->addCancelButton($cancel_uri, pht('Close'))
96 ->appendChild(array($view, $warning));
99 private function renderCloneURI(
100 PhabricatorRepository $repository,
101 PhabricatorRepositoryURI $uri) {
103 if ($repository->isSVN()) {
104 $display = csprintf(
105 'svn checkout %R %R',
106 (string)$uri->getDisplayURI(),
107 $repository->getCloneName());
108 } else {
109 $display = csprintf('%R', (string)$uri->getDisplayURI());
112 $display = (string)$display;
113 $viewer = $this->getViewer();
115 return id(new DiffusionCloneURIView())
116 ->setViewer($viewer)
117 ->setRepository($repository)
118 ->setRepositoryURI($uri)
119 ->setDisplayURI($display);