From d4b78af1027176729f76017c42c66a8aa038f495 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Sun, 1 Feb 2015 22:01:04 +1100 Subject: [PATCH] Allow `DivinerPublisher` to be specified as a flag Summary: Allow the `DivinerPublisher` subclass to be specified via `./bin/divner generate --publisher ...`. In particular, this allows use of the (mostly broken) `DivinerStaticPublisher`. Test Plan: Ran `./bin/diviner generate --publisher DivinerStaticPublisher` Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11588 --- .../diviner/publisher/DivinerPublisher.php | 1 + .../workflow/DivinerGenerateWorkflow.php | 37 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/applications/diviner/publisher/DivinerPublisher.php b/src/applications/diviner/publisher/DivinerPublisher.php index 298d0b42e7..0c2c0b1ad1 100644 --- a/src/applications/diviner/publisher/DivinerPublisher.php +++ b/src/applications/diviner/publisher/DivinerPublisher.php @@ -42,6 +42,7 @@ abstract class DivinerPublisher { $this->atomCache = $cache; $graph_map = $this->atomCache->getGraphMap(); $this->atomGraphHashToNodeHashMap = array_flip($graph_map); + return $this; } protected function getAtomFromGraphHash($graph_hash) { diff --git a/src/applications/diviner/workflow/DivinerGenerateWorkflow.php b/src/applications/diviner/workflow/DivinerGenerateWorkflow.php index 9e1370d73b..2b0e4ed3ae 100644 --- a/src/applications/diviner/workflow/DivinerGenerateWorkflow.php +++ b/src/applications/diviner/workflow/DivinerGenerateWorkflow.php @@ -19,6 +19,12 @@ final class DivinerGenerateWorkflow extends DivinerWorkflow { 'param' => 'path', 'help' => pht('Path to a Diviner book configuration.'), ), + array( + 'name' => 'publisher', + 'param' => 'class', + 'help' => pht('Specify a subclass of %s.', 'DivinerPublisher'), + 'default' => 'DivinerLivePublisher', + ), )); } @@ -164,7 +170,22 @@ final class DivinerGenerateWorkflow extends DivinerWorkflow { $this->buildAtomCache(); $this->buildGraphCache(); - $this->publishDocumentation($args->getArg('clean')); + $publisher_class = $args->getArg('publisher'); + $symbols = id(new PhutilSymbolLoader()) + ->setName($publisher_class) + ->setConcreteOnly(true) + ->setAncestorClass('DivinerPublisher') + ->selectAndLoadSymbols(); + if (!$symbols) { + throw new Exception( + pht( + "Publisher class '%s' must be a concrete subclass of %s.", + $publisher_class, + 'DivinerPublisher')); + } + $publisher = newv($publisher_class, array()); + + $this->publishDocumentation($args->getArg('clean'), $publisher); } /* -( Atom Cache )--------------------------------------------------------- */ @@ -497,18 +518,18 @@ final class DivinerGenerateWorkflow extends DivinerWorkflow { return md5(serialize($inputs)).'G'; } - private function publishDocumentation($clean) { + private function publishDocumentation($clean, DivinerPublisher $publisher) { $atom_cache = $this->getAtomCache(); $graph_map = $atom_cache->getGraphMap(); $this->log(pht('PUBLISHING DOCUMENTATION')); - $publisher = new DivinerLivePublisher(); - $publisher->setDropCaches($clean); - $publisher->setConfig($this->getAllConfig()); - $publisher->setAtomCache($atom_cache); - $publisher->setRenderer(new DivinerDefaultRenderer()); - $publisher->publishAtoms(array_values($graph_map)); + $publisher + ->setDropCaches($clean) + ->setConfig($this->getAllConfig()) + ->setAtomCache($atom_cache) + ->setRenderer(new DivinerDefaultRenderer()) + ->publishAtoms(array_values($graph_map)); $this->log(pht('Done.')); }