2013-05-20 19:18:26 +02:00
|
|
|
<?php
|
|
|
|
|
2013-05-31 19:52:25 +02:00
|
|
|
final class DivinerLiveSymbol extends DivinerDAO
|
2013-06-06 17:36:51 +02:00
|
|
|
implements PhabricatorPolicyInterface, PhabricatorMarkupInterface {
|
2013-05-20 19:18:26 +02:00
|
|
|
|
|
|
|
protected $phid;
|
|
|
|
protected $bookPHID;
|
|
|
|
protected $context;
|
|
|
|
protected $type;
|
|
|
|
protected $name;
|
|
|
|
protected $atomIndex;
|
|
|
|
protected $graphHash;
|
|
|
|
protected $identityHash;
|
2013-08-28 18:54:39 +02:00
|
|
|
protected $nodeHash;
|
2013-05-20 19:18:26 +02:00
|
|
|
|
2013-06-04 20:15:34 +02:00
|
|
|
protected $title;
|
|
|
|
protected $groupName;
|
|
|
|
protected $summary;
|
|
|
|
protected $isDocumentable = 0;
|
|
|
|
|
2013-08-28 18:54:39 +02:00
|
|
|
private $book = self::ATTACHABLE;
|
|
|
|
private $atom = self::ATTACHABLE;
|
|
|
|
private $extends = self::ATTACHABLE;
|
2013-05-31 19:52:25 +02:00
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
self::CONFIG_TIMESTAMPS => false,
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(
|
2013-07-30 15:49:13 +02:00
|
|
|
DivinerPHIDTypeAtom::TYPECONST);
|
2013-05-20 19:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-05-31 19:52:25 +02:00
|
|
|
public function getBook() {
|
2013-08-28 18:54:39 +02:00
|
|
|
return $this->assertAttached($this->book);
|
2013-05-31 19:52:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachBook(DivinerLiveBook $book) {
|
|
|
|
$this->book = $book;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-01 00:14:39 +02:00
|
|
|
public function getAtom() {
|
2013-08-28 18:54:39 +02:00
|
|
|
return $this->assertAttached($this->atom);
|
2013-06-01 00:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachAtom(DivinerLiveAtom $atom) {
|
|
|
|
$this->atom = DivinerAtom::newFromDictionary($atom->getAtomData());
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI() {
|
|
|
|
$parts = array(
|
|
|
|
'book',
|
|
|
|
$this->getBook()->getName(),
|
|
|
|
$this->getType(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->getContext()) {
|
|
|
|
$parts[] = $this->getContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
$parts[] = $this->getName();
|
|
|
|
|
|
|
|
if ($this->getAtomIndex()) {
|
|
|
|
$parts[] = $this->getAtomIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
return '/'.implode('/', $parts).'/';
|
|
|
|
}
|
|
|
|
|
2013-06-04 20:15:34 +02:00
|
|
|
public function getSortKey() {
|
|
|
|
return $this->getTitle();
|
|
|
|
}
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
public function save() {
|
|
|
|
|
|
|
|
// NOTE: The identity hash is just a sanity check because the unique tuple
|
|
|
|
// on this table is way way too long to fit into a normal UNIQUE KEY. We
|
|
|
|
// don't use it directly, but its existence prevents duplicate records.
|
|
|
|
|
|
|
|
if (!$this->identityHash) {
|
|
|
|
$this->identityHash = PhabricatorHash::digestForIndex(
|
|
|
|
serialize(
|
|
|
|
array(
|
|
|
|
'bookPHID' => $this->getBookPHID(),
|
|
|
|
'context' => $this->getContext(),
|
|
|
|
'type' => $this->getType(),
|
|
|
|
'name' => $this->getName(),
|
|
|
|
'index' => $this->getAtomIndex(),
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
2013-06-04 20:15:34 +02:00
|
|
|
public function getTitle() {
|
|
|
|
$title = parent::getTitle();
|
|
|
|
if (!strlen($title)) {
|
|
|
|
$title = $this->getName();
|
|
|
|
}
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
2013-08-28 18:54:39 +02:00
|
|
|
public function attachExtends(array $extends) {
|
|
|
|
assert_instances_of($extends, 'DivinerLiveSymbol');
|
|
|
|
$this->extends = $extends;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getExtends() {
|
|
|
|
return $this->assertAttached($this->extends);
|
|
|
|
}
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
|
2013-05-31 19:52:25 +02:00
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return $this->getBook()->getCapabilities();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
return $this->getBook()->getPolicy($capability);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return $this->getBook()->hasAutomaticCapability($capability, $viewer);
|
|
|
|
}
|
|
|
|
|
2013-06-06 17:36:51 +02:00
|
|
|
|
|
|
|
/* -( Markup Interface )--------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getMarkupFieldKey($field) {
|
|
|
|
return $this->getPHID().':'.$field.':'.$this->getGraphHash();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function newMarkupEngine($field) {
|
|
|
|
$engine = PhabricatorMarkupEngine::newMarkupEngine(array());
|
|
|
|
|
|
|
|
$engine->setConfig('preserve-linebreaks', false);
|
|
|
|
// $engine->setConfig('diviner.renderer', new DivinerDefaultRenderer());
|
|
|
|
$engine->setConfig('header.generate-toc', true);
|
|
|
|
|
|
|
|
return $engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getMarkupText($field) {
|
|
|
|
return $this->getAtom()->getDocblockText();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function didMarkupText(
|
|
|
|
$field,
|
|
|
|
$output,
|
|
|
|
PhutilMarkupEngine $engine) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function shouldUseMarkupCache($field) {
|
2013-07-28 22:07:30 +02:00
|
|
|
return false;
|
2013-06-06 17:36:51 +02:00
|
|
|
}
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
}
|