1 | <?php |
||
17 | class Sample |
||
18 | { |
||
19 | /** |
||
20 | * Returns whether we run on CLI or browser. |
||
21 | * |
||
22 | * @return bool |
||
23 | */ |
||
24 | 1 | public function isCli() |
|
28 | |||
29 | /** |
||
30 | * Return the filename currently being executed. |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | public function getScriptFilename() |
||
38 | |||
39 | /** |
||
40 | * Whether we are executing the index page. |
||
41 | * |
||
42 | * @return bool |
||
43 | */ |
||
44 | public function isIndex() |
||
48 | |||
49 | /** |
||
50 | * Return the page title. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getPageTitle() |
||
58 | |||
59 | /** |
||
60 | * Return the page heading. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | public function getPageHeading() |
||
68 | |||
69 | /** |
||
70 | * Returns an array of all known samples. |
||
71 | * |
||
72 | * @return string[] [$name => $path] |
||
73 | */ |
||
74 | public function getSamples() |
||
104 | |||
105 | /** |
||
106 | * Write documents. |
||
107 | * |
||
108 | * @param Spreadsheet $spreadsheet |
||
109 | * @param string $filename |
||
110 | * @param string[] $writers |
||
111 | */ |
||
112 | 1 | public function write(Spreadsheet $spreadsheet, $filename, array $writers = ['Xlsx', 'Xls']) |
|
128 | |||
129 | /** |
||
130 | * Returns the temporary directory and make sure it exists. |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | 1 | private function getTemporaryFolder() |
|
143 | |||
144 | /** |
||
145 | * Returns the filename that should be used for sample output. |
||
146 | * |
||
147 | * @param string $filename |
||
148 | * @param string $extension |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 1 | public function getFilename($filename, $extension = 'xlsx') |
|
156 | |||
157 | /** |
||
158 | * Return a random temporary file name. |
||
159 | * |
||
160 | * @param string $extension |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getTemporaryFilename($extension = 'xlsx') |
||
171 | |||
172 | 1 | public function log($message) |
|
177 | |||
178 | /** |
||
179 | * Log ending notes. |
||
180 | */ |
||
181 | 1 | public function logEndingNotes() |
|
186 | |||
187 | /** |
||
188 | * Log a line about the write operation. |
||
189 | * |
||
190 | * @param IWriter $writer |
||
191 | * @param string $path |
||
192 | * @param float $callStartTime |
||
193 | * |
||
194 | * @throws \ReflectionException |
||
195 | */ |
||
196 | 1 | public function logWrite(IWriter $writer, $path, $callStartTime) |
|
206 | |||
207 | /** |
||
208 | * Log a line about the read operation. |
||
209 | * |
||
210 | * @param string $format |
||
211 | * @param string $path |
||
212 | * @param float $callStartTime |
||
213 | */ |
||
214 | public function logRead($format, $path, $callStartTime) |
||
222 | } |
||
223 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: