@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 76 lines 2.1 kB view raw
1<?php 2 3abstract class DivinerWorkflow extends PhabricatorManagementWorkflow { 4 5 private $config; 6 private $bookConfigPath; 7 8 public function getBookConfigPath() { 9 return $this->bookConfigPath; 10 } 11 12 protected function getConfig($key, $default = null) { 13 return idx($this->config, $key, $default); 14 } 15 16 protected function getAllConfig() { 17 return $this->config; 18 } 19 20 protected function readBookConfiguration($book_path) { 21 if ($book_path === null) { 22 throw new PhutilArgumentUsageException( 23 pht( 24 'Specify a Diviner book configuration file with %s.', 25 '--book')); 26 } 27 28 $book_data = Filesystem::readFile($book_path); 29 $book = phutil_json_decode($book_data); 30 31 PhutilTypeSpec::checkMap( 32 $book, 33 array( 34 'name' => 'string', 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>>', 43 )); 44 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'])) { 49 $book['root'] = '.'; 50 } 51 $book['root'] = Filesystem::resolvePath($book['root'], $full_path); 52 53 if (!preg_match('/^[a-z][a-z-]*\z/', $book['name'])) { 54 $name = $book['name']; 55 throw new PhutilArgumentUsageException( 56 pht( 57 "Book configuration '%s' has name '%s', but book names must ". 58 "include only lowercase letters and hyphens.", 59 $book_path, 60 $name)); 61 } 62 63 foreach (idx($book, 'groups', array()) as $group) { 64 PhutilTypeSpec::checkMap( 65 $group, 66 array( 67 'name' => 'string', 68 'include' => 'optional regex|list<regex>', 69 )); 70 } 71 72 $this->bookConfigPath = $book_path; 73 $this->config = $book; 74 } 75 76}