| Conditions | 3 |
| Paths | 1 |
| Total Lines | 36 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function runMacro( |
||
| 20 | string $inputDirectory, |
||
| 21 | string $outputDirectory, |
||
| 22 | string & $content // Intentionally & |
||
| 23 | ): void |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Substitute "#include" macros with actual files |
||
| 27 | */ |
||
| 28 | $content = preg_replace_callback( |
||
| 29 | self::LINK_PATTERN, |
||
| 30 | function(array $input) use ($inputDirectory, $outputDirectory): string { |
||
| 31 | $text = $input[1]; |
||
| 32 | $path = trim($input[2], '/'); |
||
| 33 | |||
| 34 | if (file_exists($inputDirectory . '/' . $path)) { |
||
| 35 | $targetPath = str_replace(['../', './'], '', $outputDirectory . '/' . $path); |
||
| 36 | |||
| 37 | if (!file_exists(dirname($targetPath))) { |
||
| 38 | mkdir(dirname($targetPath), 0755, true); |
||
| 39 | } |
||
| 40 | |||
| 41 | copy($inputDirectory . '/' . $path, $targetPath); |
||
| 42 | |||
| 43 | $targetPath = preg_replace('~^[^/]+/~', '', $targetPath); |
||
| 44 | |||
| 45 | return (string) Html::el('a')->href($targetPath) |
||
| 46 | ->setText($text) |
||
| 47 | ->target('_blank'); |
||
| 48 | } |
||
| 49 | |||
| 50 | return "[$text]($path)"; |
||
| 51 | }, |
||
| 52 | $content |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | } |
||
| 56 |