Path: blob/master/src/applications/diviner/workflow/DivinerWorkflow.php
12256 views
<?php12abstract class DivinerWorkflow extends PhabricatorManagementWorkflow {34private $config;5private $bookConfigPath;67public function getBookConfigPath() {8return $this->bookConfigPath;9}1011protected function getConfig($key, $default = null) {12return idx($this->config, $key, $default);13}1415protected function getAllConfig() {16return $this->config;17}1819protected function readBookConfiguration($book_path) {20if ($book_path === null) {21throw new PhutilArgumentUsageException(22pht(23'Specify a Diviner book configuration file with %s.',24'--book'));25}2627$book_data = Filesystem::readFile($book_path);28$book = phutil_json_decode($book_data);2930PhutilTypeSpec::checkMap(31$book,32array(33'name' => 'string',34'title' => 'optional string',35'short' => 'optional string',36'preface' => 'optional string',37'root' => 'optional string',38'uri.source' => 'optional string',39'rules' => 'optional map<regex, string>',40'exclude' => 'optional regex|list<regex>',41'groups' => 'optional map<string, map<string, wild>>',42));4344// If the book specifies a "root", resolve it; otherwise, use the directory45// the book configuration file lives in.46$full_path = dirname(Filesystem::resolvePath($book_path));47if (empty($book['root'])) {48$book['root'] = '.';49}50$book['root'] = Filesystem::resolvePath($book['root'], $full_path);5152if (!preg_match('/^[a-z][a-z-]*\z/', $book['name'])) {53$name = $book['name'];54throw new PhutilArgumentUsageException(55pht(56"Book configuration '%s' has name '%s', but book names must ".57"include only lowercase letters and hyphens.",58$book_path,59$name));60}6162foreach (idx($book, 'groups', array()) as $group) {63PhutilTypeSpec::checkMap(64$group,65array(66'name' => 'string',67'include' => 'optional regex|list<regex>',68));69}7071$this->bookConfigPath = $book_path;72$this->config = $book;73}7475}767778