Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / paste / view / PasteEmbedView.php
blobe5121b496b6bf5c361a24ed725675f4e5c8cef81
1 <?php
3 final class PasteEmbedView extends AphrontView {
5 private $paste;
6 private $handle;
7 private $highlights = array();
8 private $lines = 24;
10 public function setPaste(PhabricatorPaste $paste) {
11 $this->paste = $paste;
12 return $this;
15 public function setHandle(PhabricatorObjectHandle $handle) {
16 $this->handle = $handle;
17 return $this;
20 public function setHighlights(array $highlights) {
21 $this->highlights = $highlights;
22 return $this;
25 public function setLines($lines) {
26 $this->lines = $lines;
27 return $this;
30 public function render() {
31 if (!$this->paste) {
32 throw new PhutilInvalidStateException('setPaste');
35 $lines = phutil_split_lines($this->paste->getContent());
36 require_celerity_resource('paste-css');
38 $link = phutil_tag(
39 'a',
40 array(
41 'href' => '/P'.$this->paste->getID(),
43 $this->handle->getFullName());
45 $head = phutil_tag(
46 'div',
47 array(
48 'class' => 'paste-embed-head',
50 $link);
52 $body_attributes = array('class' => 'paste-embed-body');
53 if ($this->lines != null) {
54 $body_attributes['style'] = 'max-height: '.$this->lines * (1.15).'em;';
57 $body = phutil_tag(
58 'div',
59 $body_attributes,
60 id(new PhabricatorSourceCodeView())
61 ->setLines($lines)
62 ->setHighlights($this->highlights)
63 ->disableHighlightOnClick());
65 return phutil_tag(
66 'div',
67 array('class' => 'paste-embed'),
68 array($head, $body));