qroptions-doc.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\QROptionsTrait;
  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 QROptionsTrait.php -->',
  16. ];
  17. $reflectionClass = new ReflectionClass(QROptionsTrait::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. // collect links for "see also"
  35. if(str_starts_with($line, '@see')){
  36. $see[] = $line;
  37. continue;
  38. }
  39. $content[] = $line;
  40. }
  41. // add a "see also" section
  42. if(!empty($see)){
  43. $content[] = "**See also:**\n";
  44. foreach($see as $line){
  45. $line = substr($line, 5); // cut off the "@see "
  46. // normal links
  47. if(str_starts_with($line, 'http')){
  48. $content[] = sprintf('- [%s](%s)', explode('://', $line)[1], $line);
  49. }
  50. // php.net documentation
  51. elseif(str_starts_with($line, '\\') && !str_contains($line, 'chillerlan')){
  52. $path = str_replace(['\\', '::', '()'], ['', '.', ''], strtolower($line));
  53. if(!str_contains($line, '::')){
  54. $path = 'function.'.$path;
  55. }
  56. $content[] = sprintf('- [php.net: `%s`](https://www.php.net/manual/%s)', $line, $path);
  57. }
  58. // FQCN
  59. else{
  60. $content[] = sprintf('- `%s`', $line);
  61. }
  62. }
  63. }
  64. $content[] = "\n";
  65. }
  66. file_put_contents(__DIR__.'/'.$file, implode("\n", $content));
  67. printf('Built "%s" from "%s"', $file, QROptionsTrait::class);
  68. exit(0);