3 abstract class DivinerWorkflow
extends PhabricatorManagementWorkflow
{
6 private $bookConfigPath;
8 public function getBookConfigPath() {
9 return $this->bookConfigPath
;
12 protected function getConfig($key, $default = null) {
13 return idx($this->config
, $key, $default);
16 protected function getAllConfig() {
20 protected function readBookConfiguration($book_path) {
21 if ($book_path === null) {
22 throw new PhutilArgumentUsageException(
24 'Specify a Diviner book configuration file with %s.',
28 $book_data = Filesystem
::readFile($book_path);
29 $book = phutil_json_decode($book_data);
31 PhutilTypeSpec
::checkMap(
35 'title' => 'optional string',
36 'short' => 'optional string',
37 'preface' => 'optional string',
38 'root' => 'optional string',
39 'uri.source' => 'optional string',
40 'rules' => 'optional map<regex, string>',
41 'exclude' => 'optional regex|list<regex>',
42 'groups' => 'optional map<string, map<string, wild>>',
45 // If the book specifies a "root", resolve it; otherwise, use the directory
46 // the book configuration file lives in.
47 $full_path = dirname(Filesystem
::resolvePath($book_path));
48 if (empty($book['root'])) {
51 $book['root'] = Filesystem
::resolvePath($book['root'], $full_path);
53 if (!preg_match('/^[a-z][a-z-]*\z/', $book['name'])) {
54 $name = $book['name'];
55 throw new PhutilArgumentUsageException(
57 "Book configuration '%s' has name '%s', but book names must ".
58 "include only lowercase letters and hyphens.",
63 foreach (idx($book, 'groups', array()) as $group) {
64 PhutilTypeSpec
::checkMap(
68 'include' => 'optional regex|list<regex>',
72 $this->bookConfigPath
= $book_path;
73 $this->config
= $book;