Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Export | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| create | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
| getExportTimestamp | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * JSON, and PDF export |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @author Matteo Scaramuccia <matteo@scaramuccia.com> |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @copyright 2005-2026 phpMyFAQ Team |
| 15 | * @link https://www.phpmyfaq.de |
| 16 | * @since 2005-11-02 |
| 17 | */ |
| 18 | |
| 19 | declare(strict_types=1); |
| 20 | |
| 21 | namespace phpMyFAQ; |
| 22 | |
| 23 | use phpMyFAQ\Core\Exception; |
| 24 | use phpMyFAQ\Export\Json; |
| 25 | use phpMyFAQ\Export\Pdf; |
| 26 | use Symfony\Component\HttpFoundation\Request; |
| 27 | |
| 28 | /** |
| 29 | * Class Export |
| 30 | * |
| 31 | * @package phpMyFAQ |
| 32 | */ |
| 33 | class Export |
| 34 | { |
| 35 | protected Faq $faq; |
| 36 | |
| 37 | protected Category $category; |
| 38 | |
| 39 | protected Configuration $config; |
| 40 | |
| 41 | /** |
| 42 | * Factory. |
| 43 | * @throws Exception |
| 44 | */ |
| 45 | public static function create( |
| 46 | Faq $faq, |
| 47 | Category $category, |
| 48 | Configuration $configuration, |
| 49 | string $mode = 'pdf', |
| 50 | ): Pdf|Json { |
| 51 | return match ($mode) { |
| 52 | 'json' => new Json($faq, $category, $configuration), |
| 53 | 'pdf' => new Pdf($faq, $category, $configuration), |
| 54 | default => throw new Exception(message: 'Export not implemented!'), |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the timestamp of the export. |
| 60 | */ |
| 61 | public static function getExportTimestamp(): string |
| 62 | { |
| 63 | $requestTime = Request::createFromGlobals()->server->get(key: 'REQUEST_TIME'); |
| 64 | |
| 65 | return date(format: 'Y-m-d-H-i-s', timestamp: is_numeric($requestTime) ? (int) $requestTime : time()); |
| 66 | } |
| 67 | } |