Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / diviner / workflow / DivinerWorkflow.php
blob69fcc67f48746955b0d46042ceda72fb6e446771
1 <?php
3 abstract class DivinerWorkflow extends PhabricatorManagementWorkflow {
5 private $config;
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() {
17 return $this->config;
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'));
28 $book_data = Filesystem::readFile($book_path);
29 $book = phutil_json_decode($book_data);
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 ));
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'] = '.';
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(
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));
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 ));
72 $this->bookConfigPath = $book_path;
73 $this->config = $book;