qroptions-doc.php 2.2 KB

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