1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Minor tidying of DivinerPublisher classes

Summary: Self-explanatory. Also made a few methods `final`.

Test Plan: Eyeball it.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11598
This commit is contained in:
Joshua Spence 2015-02-02 07:30:56 +11:00
parent 2b75b33552
commit 0fc2464e03
3 changed files with 21 additions and 27 deletions

View file

@ -8,9 +8,7 @@ final class DivinerLivePublisher extends DivinerPublisher {
if (!$this->book) {
$book_name = $this->getConfig('name');
$book = id(new DivinerLiveBook())->loadOneWhere(
'name = %s',
$book_name);
$book = id(new DivinerLiveBook())->loadOneWhere('name = %s', $book_name);
if (!$book) {
$book = id(new DivinerLiveBook())
->setName($book_name)
@ -19,9 +17,9 @@ final class DivinerLivePublisher extends DivinerPublisher {
}
$book->setConfigurationData($this->getConfigurationData())->save();
$this->book = $book;
}
return $this->book;
}
@ -75,7 +73,6 @@ final class DivinerLivePublisher extends DivinerPublisher {
protected function deleteDocumentsByHash(array $hashes) {
$atom_table = new DivinerLiveAtom();
$symbol_table = new DivinerLiveSymbol();
$conn_w = $symbol_table->establishConnection('w');
$strings = array();
@ -149,7 +146,6 @@ final class DivinerLivePublisher extends DivinerPublisher {
public function findAtomByRef(DivinerAtomRef $ref) {
// TODO: Actually implement this.
return null;
}

View file

@ -10,51 +10,51 @@ abstract class DivinerPublisher {
private $symbolReverseMap;
private $dropCaches;
public function setDropCaches($drop_caches) {
public final function setDropCaches($drop_caches) {
$this->dropCaches = $drop_caches;
return $this;
}
public function setRenderer(DivinerRenderer $renderer) {
public final function setRenderer(DivinerRenderer $renderer) {
$renderer->setPublisher($this);
$this->renderer = $renderer;
return $this;
}
public function getRenderer() {
public final function getRenderer() {
return $this->renderer;
}
public function setConfig(array $config) {
public final function setConfig(array $config) {
$this->config = $config;
return $this;
}
public function getConfig($key, $default = null) {
public final function getConfig($key, $default = null) {
return idx($this->config, $key, $default);
}
public function getConfigurationData() {
public final function getConfigurationData() {
return $this->config;
}
public function setAtomCache(DivinerAtomCache $cache) {
public final function setAtomCache(DivinerAtomCache $cache) {
$this->atomCache = $cache;
$graph_map = $this->atomCache->getGraphMap();
$this->atomGraphHashToNodeHashMap = array_flip($graph_map);
return $this;
}
protected function getAtomFromGraphHash($graph_hash) {
protected final function getAtomFromGraphHash($graph_hash) {
if (empty($this->atomGraphHashToNodeHashMap[$graph_hash])) {
throw new Exception("No such atom '{$graph_hash}'!");
throw new Exception(pht("No such atom '%s'!", $graph_hash));
}
return $this->getAtomFromNodeHash(
$this->atomGraphHashToNodeHashMap[$graph_hash]);
}
protected function getAtomFromNodeHash($node_hash) {
protected final function getAtomFromNodeHash($node_hash) {
if (empty($this->atomMap[$node_hash])) {
$dict = $this->atomCache->getAtom($node_hash);
$this->atomMap[$node_hash] = DivinerAtom::newFromDictionary($dict);
@ -62,7 +62,7 @@ abstract class DivinerPublisher {
return $this->atomMap[$node_hash];
}
protected function getSimilarAtoms(DivinerAtom $atom) {
protected final function getSimilarAtoms(DivinerAtom $atom) {
if ($this->symbolReverseMap === null) {
$rmap = array();
$smap = $this->atomCache->getSymbolMap();
@ -75,7 +75,7 @@ abstract class DivinerPublisher {
$shash = $atom->getRef()->toHash();
if (empty($this->symbolReverseMap[$shash])) {
throw new Exception('Atom has no symbol map entry!');
throw new Exception(pht('Atom has no symbol map entry!'));
}
$hashes = $this->symbolReverseMap[$shash];
@ -91,10 +91,10 @@ abstract class DivinerPublisher {
/**
* If a book contains multiple definitions of some atom, like some function
* "f()", we assign them an arbitrary (but fairly stable) order and publish
* them as "function/f/1/", "function/f/2/", etc., or similar.
* `f()`, we assign them an arbitrary (but fairly stable) order and publish
* them as `function/f/1/`, `function/f/2/`, etc., or similar.
*/
protected function getAtomSimilarIndex(DivinerAtom $atom) {
protected final function getAtomSimilarIndex(DivinerAtom $atom) {
$atoms = $this->getSimilarAtoms($atom);
if (count($atoms) == 1) {
return 0;
@ -108,16 +108,15 @@ abstract class DivinerPublisher {
$index++;
}
throw new Exception('Expected to find atom while disambiguating!');
throw new Exception(pht('Expected to find atom while disambiguating!'));
}
abstract protected function loadAllPublishedHashes();
abstract protected function deleteDocumentsByHash(array $hashes);
abstract protected function createDocumentsByHash(array $hashes);
abstract public function findAtomByRef(DivinerAtomRef $ref);
final public function publishAtoms(array $hashes) {
public final function publishAtoms(array $hashes) {
$existing = $this->loadAllPublishedHashes();
if ($this->dropCaches) {
@ -141,7 +140,7 @@ abstract class DivinerPublisher {
$this->createDocumentsByHash($created);
}
protected function shouldGenerateDocumentForAtom(DivinerAtom $atom) {
protected final function shouldGenerateDocumentForAtom(DivinerAtom $atom) {
switch ($atom->getType()) {
case DivinerAtom::TYPE_METHOD:
case DivinerAtom::TYPE_FILE:

View file

@ -59,7 +59,6 @@ final class DivinerStaticPublisher extends DivinerPublisher {
protected function createDocumentsByHash(array $hashes) {
$indexes = array();
$cache = $this->getPublishCache();
foreach ($hashes as $hash) {
@ -89,7 +88,6 @@ final class DivinerStaticPublisher extends DivinerPublisher {
}
$this->publishIndex();
$cache->writePathMap();
$cache->writeIndex();
}
@ -97,6 +95,7 @@ final class DivinerStaticPublisher extends DivinerPublisher {
private function publishIndex() {
$index = $this->getPublishCache()->getIndex();
$refs = array();
foreach ($index as $hash => $dictionary) {
$refs[$hash] = DivinerAtomRef::newFromDictionary($dictionary);
}