2011-01-16 22:51:39 +01:00
|
|
|
<?php
|
|
|
|
|
2013-03-09 22:52:21 +01:00
|
|
|
abstract class AphrontView extends Phobject
|
|
|
|
implements PhutilSafeHTMLProducerInterface {
|
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(
|
2013-03-02 00:37:32 +01:00
|
|
|
pht("View '%s' does not support children.", $class));
|
2012-11-21 03:01:18 +01:00
|
|
|
}
|
2011-01-16 22:51:39 +01:00
|
|
|
$this->children[] = $child;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function renderChildren() {
|
2013-03-09 22:52:41 +01:00
|
|
|
return $this->children;
|
2013-01-29 03:09:00 +01:00
|
|
|
}
|
|
|
|
|
2013-03-09 22:52:41 +01:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2011-03-13 01:17:34 +01:00
|
|
|
final protected function renderSingleView($child) {
|
2013-03-09 22:52:41 +01: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 22:51:39 +01:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2013-03-09 22:52:21 +01:00
|
|
|
public function producePhutilSafeHTML() {
|
|
|
|
return $this->render();
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|