|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Auto generates the configuration settings markdown source |
| 4 | + * |
| 5 | + * @created 03.10.2023 |
| 6 | + * @author smiley <[email protected]> |
| 7 | + * @copyright 2023 smiley |
| 8 | + * @license MIT |
| 9 | + */ |
| 10 | + |
| 11 | +use chillerlan\QRCode\QROptionsTrait; |
| 12 | + |
| 13 | +require_once __DIR__.'/../vendor/autoload.php'; |
| 14 | + |
| 15 | +$file = 'Usage/Configuration-settings.md'; |
| 16 | +$content = [ |
| 17 | + '# Configuration settings', |
| 18 | + '<!-- This file is auto generated from the source of QROptionsTrait.php -->', |
| 19 | +]; |
| 20 | + |
| 21 | +$reflectionClass = new ReflectionClass(QROptionsTrait::class); |
| 22 | + |
| 23 | +foreach($reflectionClass->getProperties(ReflectionProperty::IS_PROTECTED) as $reflectionProperty){ |
| 24 | + $docblock = $reflectionProperty->getDocComment(); |
| 25 | + |
| 26 | + // don't document deprecated settings |
| 27 | + if(str_contains($docblock, '@deprecated')){ |
| 28 | + continue; |
| 29 | + } |
| 30 | + |
| 31 | + $content[] = sprintf("## %s\n", $reflectionProperty->getName()); |
| 32 | + |
| 33 | + $lines = array_map(fn($l) => trim($l, "\ \t\n\r\0\x0B*"), explode("\n", $docblock)); |
| 34 | + |
| 35 | + array_shift($lines); |
| 36 | + array_pop($lines); |
| 37 | + |
| 38 | + $see = []; |
| 39 | + |
| 40 | + foreach($lines as $line){ |
| 41 | + |
| 42 | + // skip @todo and @var |
| 43 | + if(str_contains($line, '@todo') || str_contains($line, '@var')){ |
| 44 | + continue; |
| 45 | + } |
| 46 | + |
| 47 | + // collect links for "see also" |
| 48 | + if(str_starts_with($line, '@see')){ |
| 49 | + $see[] = $line; |
| 50 | + |
| 51 | + continue; |
| 52 | + } |
| 53 | + |
| 54 | + $content[] = $line; |
| 55 | + } |
| 56 | + |
| 57 | + // add a "see also" section |
| 58 | + if(!empty($see)){ |
| 59 | + $content[] = "**See also:**\n"; |
| 60 | + |
| 61 | + foreach($see as $line){ |
| 62 | + $line = substr($line, 5); // cut off the "@see " |
| 63 | + |
| 64 | + // normal links |
| 65 | + if(str_starts_with($line, 'http')){ |
| 66 | + $content[] = sprintf('- [%s](%s)', explode('://', $line)[1], $line); |
| 67 | + } |
| 68 | + // php.net documentation |
| 69 | + elseif(str_starts_with($line, '\\') && !str_contains($line, 'chillerlan')){ |
| 70 | + $path = str_replace(['\\', '::', '()'], ['', '.', ''], strtolower($line)); |
| 71 | + |
| 72 | + if(!str_contains($line, '::')){ |
| 73 | + $path = 'function.'.$path; |
| 74 | + } |
| 75 | + |
| 76 | + $content[] = sprintf('- [php.net: `%s`](https://www.php.net/manual/%s)', $line, $path); |
| 77 | + } |
| 78 | + // FQCN |
| 79 | + else{ |
| 80 | + $content[] = sprintf('- `%s`', $line); |
| 81 | + } |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | + $content[] = "\n"; |
| 88 | +} |
| 89 | + |
| 90 | +file_put_contents(__DIR__.'/'.$file, implode("\n", $content)); |
| 91 | + |
| 92 | +printf('Built "%s" from "%s"', $file, QROptionsTrait::class); |
| 93 | + |
| 94 | +exit(0); |
0 commit comments