2011-01-16 22:51:39 +01:00
|
|
|
<?php
|
|
|
|
|
2012-12-19 01:11:07 +01:00
|
|
|
abstract class AphrontView extends Phobject {
|
2011-01-16 22:51:39 +01:00
|
|
|
|
2012-12-20 23:27:12 +01:00
|
|
|
protected $user;
|
2011-01-16 22:51:39 +01:00
|
|
|
protected $children = array();
|
|
|
|
|
2012-12-20 23:27:12 +01:00
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getUser() {
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2012-11-21 03:01:18 +01:00
|
|
|
protected function canAppendChild() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
final public function appendChild($child) {
|
2012-11-21 03:01:18 +01:00
|
|
|
if (!$this->canAppendChild()) {
|
|
|
|
$class = get_class($this);
|
|
|
|
throw new Exception(
|
|
|
|
"View '{$class}' does not support children.");
|
|
|
|
}
|
2011-01-16 22:51:39 +01:00
|
|
|
$this->children[] = $child;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function renderChildren() {
|
2013-01-29 03:09:00 +01:00
|
|
|
$out = array();
|
|
|
|
foreach ($this->children as $child) {
|
2013-02-11 23:43:25 +01:00
|
|
|
$out[] = $this->renderSingleView($child);
|
2013-01-29 03:09:00 +01:00
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
final protected function renderSingleView($child) {
|
2011-01-16 22:51:39 +01:00
|
|
|
if ($child instanceof AphrontView) {
|
|
|
|
return $child->render();
|
|
|
|
} else if (is_array($child)) {
|
|
|
|
$out = array();
|
|
|
|
foreach ($child as $element) {
|
2011-03-13 01:17:34 +01:00
|
|
|
$out[] = $this->renderSingleView($element);
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|
2013-02-13 23:50:15 +01:00
|
|
|
return phutil_implode_html('', $out);
|
2011-01-16 22:51:39 +01:00
|
|
|
} else {
|
|
|
|
return $child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 03:09:33 +01:00
|
|
|
final protected function isEmptyContent($content) {
|
|
|
|
if (is_array($content)) {
|
|
|
|
foreach ($content as $element) {
|
|
|
|
if (!$this->isEmptyContent($element)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return !strlen((string)$content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
abstract public function render();
|
|
|
|
|
|
|
|
}
|