api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. function removeIgnored(string $dir, array &$entries, array $ignore)
  3. {
  4. foreach ($entries as $i => $entry) {
  5. if (isset($ignore[$dir . '/' . $entry])) {
  6. unset($entries[$i]);
  7. }
  8. }
  9. }
  10. function prioritySort(string $dir, array &$entries, array $priority)
  11. {
  12. $first = array();
  13. foreach ($entries as $i => $entry) {
  14. if (isset($priority[$dir . '/' . $entry])) {
  15. array_push($first, $entry);
  16. unset($entries[$i]);
  17. }
  18. }
  19. sort($entries);
  20. foreach ($first as $entry) {
  21. array_unshift($entries, $entry);
  22. }
  23. }
  24. function runDir(string $base, string $dir, array &$lines, array $ignore, array $priority): int
  25. {
  26. $count = 0;
  27. $entries = scandir($dir);
  28. removeIgnored($dir, $entries, $ignore);
  29. prioritySort($dir, $entries, $priority);
  30. foreach ($entries as $entry) {
  31. if ($entry === '.' || $entry === '..') {
  32. continue;
  33. }
  34. $filename = "$base/$dir/$entry";
  35. if (is_dir($filename)) {
  36. $count += runDir($base, "$dir/$entry", $lines, $ignore, $priority);
  37. }
  38. }
  39. foreach ($entries as $entry) {
  40. $filename = "$base/$dir/$entry";
  41. if (is_file($filename)) {
  42. if (substr($entry, -4) != '.php') {
  43. continue;
  44. }
  45. $data = file_get_contents($filename);
  46. $data = preg_replace('|/\*\*.*?\*/|s', '', $data);
  47. array_push($lines, "// file: $dir/$entry");
  48. foreach (explode("\n", $data) as $line) {
  49. if (!preg_match('/^<\?php|^namespace |^use |vendor\/autoload|declare\s*\(\s*strict_types\s*=\s*1|^\s*\/\//', $line)) {
  50. array_push($lines, $line);
  51. }
  52. }
  53. $count++;
  54. }
  55. }
  56. return $count;
  57. }
  58. function addHeader(array &$lines)
  59. {
  60. $head = <<<EOF
  61. <?php
  62. /**
  63. * PHP-CRUD-API v2 License: MIT
  64. * Maurits van der Schee: maurits@vdschee.nl
  65. * https://github.com/mevdschee/php-crud-api
  66. *
  67. * Dependencies:
  68. * - vendor/psr/*: PHP-FIG
  69. * https://github.com/php-fig
  70. * - vendor/nyholm/*: Tobias Nyholm
  71. * https://github.com/Nyholm
  72. **/
  73. namespace Tqdev\PhpCrudApi;
  74. EOF;
  75. foreach (explode("\n", $head) as $line) {
  76. array_push($lines, $line);
  77. }
  78. }
  79. function run(string $base, array $dirs, string $filename, array $ignore, array $priority)
  80. {
  81. $lines = [];
  82. $start = microtime(true);
  83. addHeader($lines);
  84. $ignore = array_flip($ignore);
  85. $priority = array_flip($priority);
  86. $count = 0;
  87. foreach ($dirs as $dir) {
  88. $count += runDir($base, $dir, $lines, $ignore, $priority);
  89. }
  90. $data = implode("\n", $lines);
  91. $data = preg_replace('/\n({)?\s*\n\s*\n/', "\n$1\n", $data);
  92. file_put_contents('tmp_' . $filename, $data);
  93. ob_start();
  94. include 'tmp_' . $filename;
  95. ob_end_clean();
  96. rename('tmp_' . $filename, $filename);
  97. $end = microtime(true);
  98. $time = ($end - $start) * 1000;
  99. echo sprintf("%d files combined in %d ms into '%s'\n", $count, $time, $filename);
  100. }
  101. $ignore = [
  102. 'vendor/autoload.php',
  103. 'vendor/composer',
  104. 'vendor/php-http',
  105. 'vendor/nyholm/psr7/src/Factory/HttplugFactory.php',
  106. ];
  107. $priority = [
  108. 'vendor/psr',
  109. ];
  110. run(__DIR__, ['vendor', 'src'], 'api.php', $ignore, $priority);