2011-01-16 13:51:39 -08:00
|
|
|
<?php
|
|
|
|
|
2013-03-09 13:52:21 -08:00
|
|
|
abstract class AphrontView extends Phobject
|
|
|
|
implements PhutilSafeHTMLProducerInterface {
|
2011-01-16 13:51:39 -08:00
|
|
|
|
2012-12-20 14:27:12 -08:00
|
|
|
protected $user;
|
2011-01-16 13:51:39 -08:00
|
|
|
protected $children = array();
|
|
|
|
|
2012-12-20 14:27:12 -08:00
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getUser() {
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:01:18 -08:00
|
|
|
protected function canAppendChild() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
final public function appendChild($child) {
|
2012-11-20 18:01:18 -08:00
|
|
|
if (!$this->canAppendChild()) {
|
|
|
|
$class = get_class($this);
|
|
|
|
throw new Exception(
|
2013-03-01 15:37:32 -08:00
|
|
|
pht("View '%s' does not support children.", $class));
|
2012-11-20 18:01:18 -08:00
|
|
|
}
|
2011-01-16 13:51:39 -08:00
|
|
|
$this->children[] = $child;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function renderChildren() {
|
2013-03-09 13:52:41 -08:00
|
|
|
return $this->children;
|
2013-01-28 18:09:00 -08:00
|
|
|
}
|
|
|
|
|
2013-03-09 13:52:41 -08:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2011-03-12 16:17:34 -08:00
|
|
|
final protected function renderSingleView($child) {
|
2013-03-09 13:52:41 -08:00
|
|
|
phutil_deprecated(
|
|
|
|
'AphrontView->renderSingleView()',
|
|
|
|
"This method no longer does anything; it can be removed and replaced ".
|
|
|
|
"with its arguments.");
|
|
|
|
return $child;
|
2011-01-16 13:51:39 -08:00
|
|
|
}
|
|
|
|
|
2013-01-28 18:09:33 -08: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 13:51:39 -08:00
|
|
|
abstract public function render();
|
|
|
|
|
2013-03-09 13:52:21 -08:00
|
|
|
public function producePhutilSafeHTML() {
|
|
|
|
return $this->render();
|
|
|
|
}
|
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
}
|