1 | <?php |
||
8 | abstract class Report { |
||
9 | /** |
||
10 | * @var Config |
||
11 | */ |
||
12 | protected $config; |
||
13 | |||
14 | /** |
||
15 | * @var Queries |
||
16 | */ |
||
17 | protected $queries; |
||
18 | |||
19 | 2 | public function __construct(Queries $queries, Config $config) { |
|
23 | |||
24 | /** |
||
25 | * Get the default template for the report. |
||
26 | * |
||
27 | * This could be: |
||
28 | * - a filename, which is then assumed to be in templates-directory of |
||
29 | * dicto or in the current working directory, if not found in dicto |
||
30 | * templates |
||
31 | * - an absolute path |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | abstract protected function default_template(); |
||
36 | |||
37 | /** |
||
38 | * Get the name of the template. |
||
39 | * |
||
40 | * Uses config["template"] or falls back to default template. |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | 3 | protected function template() { |
|
47 | |||
48 | /** |
||
49 | * Get the absolute path for a template. |
||
50 | * |
||
51 | * Does only realpath(..) if an absolute path is given. Searches dicto-templates |
||
52 | * directory, config-directory and current working directory otherwise. |
||
53 | * |
||
54 | * @throws \InvalidArgumentException if none of the strategies leads to an |
||
55 | * existing file. |
||
56 | * @param string $name |
||
57 | * @return string |
||
58 | */ |
||
59 | 4 | protected function template_path($name) { |
|
79 | |||
80 | /** |
||
81 | * Load a template from a path. |
||
82 | * |
||
83 | * Expects the file to contain a function with the same name as the file |
||
84 | * (minus postfix) prefixed with template_, that writes to stdout. |
||
85 | * |
||
86 | * @param string $template_path |
||
87 | * @return \Closure array -> null |
||
88 | */ |
||
89 | 3 | protected function load_template($template_path) { |
|
98 | |||
99 | /** |
||
100 | * Derive the name of the template function from a filename. |
||
101 | * |
||
102 | * @param string $path |
||
103 | * @return string |
||
104 | */ |
||
105 | 4 | protected function template_function_name($path) { |
|
112 | |||
113 | /** |
||
114 | * Generate the report. |
||
115 | * |
||
116 | * Should return a structured array containing the information in the report. |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | abstract public function generate(); |
||
121 | |||
122 | /** |
||
123 | * Write the report to some handle using a template. |
||
124 | * |
||
125 | * @param resource $handle |
||
126 | * @return null |
||
127 | */ |
||
128 | 3 | public function write($handle) { |
|
136 | |||
137 | /** |
||
138 | * Get value from the custom config or default if it does not exist. |
||
139 | * |
||
140 | * @param string $key |
||
141 | * @param mixed $default |
||
142 | * @return mixed |
||
143 | */ |
||
144 | 3 | protected function custom_config_value($key, $default) { |
|
150 | } |
||
151 |