qroptions-doc.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. $link = [];
  30. foreach($lines as $line){
  31. // skip @todo and @var
  32. if(str_contains($line, '@todo') || str_contains($line, '@var')){
  33. continue;
  34. }
  35. if(str_contains($line, '@deprecated')){
  36. $line = str_replace('@deprecated', '**Deprecated:**', $line);
  37. }
  38. // collect links for "see also"
  39. if(str_starts_with($line, '@see')){
  40. $see[] = substr($line, 5); // cut off the "@see "
  41. continue;
  42. }
  43. // collect links for "links"
  44. if(str_starts_with($line, '@link')){
  45. $link[] = substr($line, 6); // cut off the "@link "
  46. continue;
  47. }
  48. $content[] = $line;
  49. }
  50. // add a "see also" section
  51. if(!empty($see)){
  52. $content[] = "\n**See also:**\n";
  53. foreach($see as $line){
  54. // normal links
  55. if(str_starts_with($line, 'http')){
  56. $content[] = sprintf('- [%s](%s)', explode('://', $line)[1], $line);
  57. }
  58. // php.net documentation
  59. elseif(str_starts_with($line, '\\') && !str_contains($line, 'chillerlan')){
  60. $path = str_replace(['\\', '::', '()', '_'], ['', '.', '', '-'], strtolower($line));
  61. if(!str_contains($line, '::')){
  62. $path = 'function.'.$path;
  63. }
  64. $content[] = sprintf('- [php.net: `%s`](https://www.php.net/manual/%s)', $line, $path);
  65. }
  66. // FQCN
  67. else{
  68. $content[] = sprintf('- `%s`', $line);
  69. }
  70. }
  71. }
  72. // add "Links" section
  73. if(!empty($link)){
  74. $content[] = "\n**Links:**\n";
  75. foreach($link as $line){
  76. // skip non-url
  77. if(!str_starts_with($line, 'http')){
  78. continue;
  79. }
  80. $url = explode(' ', $line, 2);
  81. $content[] = match(count($url)){
  82. 1 => sprintf('- [%s](%s)', explode('://', $url[0])[1], $url[0]),
  83. 2 => sprintf('- [%s](%s)', trim($url[1]), $url[0]),
  84. };
  85. }
  86. }
  87. $content[] = "\n";
  88. }
  89. file_put_contents(__DIR__.'/'.$file, implode("\n", $content));
  90. printf('Built "%s" from "%s"', $file, QROptions::class);
  91. exit(0);