mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-24 07:42:40 +01:00
ef214e94ce
Summary: This is used in every other view. Test Plan: Browsed around. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4248
55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
abstract class AphrontView extends Phobject {
|
|
|
|
protected $user;
|
|
protected $children = array();
|
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
$this->user = $user;
|
|
return $this;
|
|
}
|
|
|
|
protected function getUser() {
|
|
return $this->user;
|
|
}
|
|
|
|
protected function canAppendChild() {
|
|
return true;
|
|
}
|
|
|
|
final public function appendChild($child) {
|
|
if (!$this->canAppendChild()) {
|
|
$class = get_class($this);
|
|
throw new Exception(
|
|
"View '{$class}' does not support children.");
|
|
}
|
|
$this->children[] = $child;
|
|
return $this;
|
|
}
|
|
|
|
final protected function renderChildren() {
|
|
$out = array();
|
|
foreach ($this->children as $child) {
|
|
$out[] = $this->renderSingleView($child);
|
|
}
|
|
return implode('', $out);
|
|
}
|
|
|
|
final protected function renderSingleView($child) {
|
|
if ($child instanceof AphrontView) {
|
|
return $child->render();
|
|
} else if (is_array($child)) {
|
|
$out = array();
|
|
foreach ($child as $element) {
|
|
$out[] = $this->renderSingleView($element);
|
|
}
|
|
return implode('', $out);
|
|
} else {
|
|
return $child;
|
|
}
|
|
}
|
|
|
|
abstract public function render();
|
|
|
|
}
|