Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| DocumentParser | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| parseDocument | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Utils\Parser\Document |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Utils\Parser\Document; |
| 16 | |
| 17 | use PhpOffice\PhpWord\IOFactory; |
| 18 | use PhpOffice\PhpWord\Writer\HTML; |
| 19 | |
| 20 | /** |
| 21 | * Document parser class. |
| 22 | * |
| 23 | * @package phpOMS\Utils\Parser\Document |
| 24 | * @license OMS License 2.0 |
| 25 | * @link https://jingga.app |
| 26 | * @since 1.0.0 |
| 27 | */ |
| 28 | class DocumentParser |
| 29 | { |
| 30 | /** |
| 31 | * Document to string |
| 32 | * |
| 33 | * @param string $path Path |
| 34 | * |
| 35 | * @return string |
| 36 | * |
| 37 | * @since 1.0.0 |
| 38 | */ |
| 39 | public static function parseDocument(string $path, string $output = 'html') : string |
| 40 | { |
| 41 | if ($output === 'html') { |
| 42 | $doc = IOFactory::load($path); |
| 43 | |
| 44 | $writer = new HTML($doc); |
| 45 | |
| 46 | return $writer->getContent(); |
| 47 | } elseif ($output === 'pdf') { |
| 48 | $doc = IOFactory::load($path); |
| 49 | |
| 50 | $writer = new DocumentWriter($doc); |
| 51 | |
| 52 | return $writer->toPdfString(); |
| 53 | } |
| 54 | |
| 55 | return ''; |
| 56 | } |
| 57 | } |