1 | <?php |
||
8 | class Sample |
||
9 | { |
||
10 | /** |
||
11 | * Returns wether we run on CLI or browser |
||
12 | * @return bool |
||
13 | */ |
||
14 | public function isCli() |
||
18 | |||
19 | /** |
||
20 | * Return the filename currently being executed |
||
21 | * @return string |
||
22 | */ |
||
23 | public function getScriptFilename() |
||
27 | |||
28 | /** |
||
29 | * Wether we are executing the index page |
||
30 | * @return bool |
||
31 | */ |
||
32 | public function isIndex() |
||
36 | |||
37 | /** |
||
38 | * Return the page title |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getPageTitle() |
||
45 | |||
46 | /** |
||
47 | * Return the page heading |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getPageHeading() |
||
54 | |||
55 | /** |
||
56 | * Returns an array of all known samples |
||
57 | * @return string[] [$name => $path] |
||
58 | */ |
||
59 | public function getSamples() |
||
73 | |||
74 | /** |
||
75 | * Write documents |
||
76 | * |
||
77 | * @param Spreadsheet $spreadsheet |
||
78 | * @param string $filename |
||
79 | * @param array $writers |
||
80 | */ |
||
81 | public function write(Spreadsheet $spreadsheet, $filename, array $writers = ['Excel2007' => 'xlsx', 'Excel5' => 'xls']) |
||
101 | |||
102 | /** |
||
103 | * Returns the temporary directory and make sure it exists |
||
104 | * @return string |
||
105 | */ |
||
106 | private function getTemporaryFolder() |
||
115 | |||
116 | /** |
||
117 | * Returns the filename that should be used for sample output |
||
118 | * @param string $filename |
||
119 | * @param string $extension |
||
120 | * @return string |
||
121 | */ |
||
122 | public function getFilename($filename, $extension = 'xlsx') |
||
126 | |||
127 | /** |
||
128 | * Return a random temporary file name |
||
129 | * @param string $extension |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getTemporaryFilename($extension = 'xlsx') |
||
139 | |||
140 | public function log($message) |
||
144 | |||
145 | /** |
||
146 | * Log ending notes |
||
147 | */ |
||
148 | public function logEndingNotes() |
||
153 | |||
154 | /** |
||
155 | * Log a line about the write operation |
||
156 | * @param \PhpSpreadsheet\Writer\IWriter $writer |
||
157 | * @param string $path |
||
158 | * @param float $callStartTime |
||
159 | */ |
||
160 | public function logWrite(\PhpSpreadsheet\Writer\IWriter $writer, $path, $callStartTime) |
||
170 | |||
171 | /** |
||
172 | * Log a line about the read operation |
||
173 | * @param string $format |
||
174 | * @param string $path |
||
175 | * @param float $callStartTime |
||
176 | */ |
||
177 | public function logRead($format, $path, $callStartTime) |
||
185 | } |
||
186 |
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: