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 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. function prioritySort(string $dir, array $entries, array $priority): array
  3. {
  4. $result = array();
  5. foreach ($priority as $file) {
  6. if (dirname($file) == $dir) {
  7. if (in_array(basename($file), $entries)) {
  8. array_push($result, basename($file));
  9. }
  10. }
  11. }
  12. $entries = array_diff($entries, $result);
  13. sort($entries);
  14. foreach ($entries as $entry) {
  15. array_push($result, $entry);
  16. }
  17. return $result;
  18. }
  19. function runDir(string $base, string $dir, array &$lines, array $priority): int
  20. {
  21. $count = 0;
  22. $entries = scandir($dir);
  23. $entries = prioritySort($dir, $entries, $priority);
  24. foreach ($entries as $entry) {
  25. if ($entry === '.' || $entry === '..') {
  26. continue;
  27. }
  28. $filename = "$base/$dir/$entry";
  29. if (is_dir($filename)) {
  30. $count += runDir($base, "$dir/$entry", $lines, $priority);
  31. }
  32. }
  33. foreach ($entries as $entry) {
  34. $filename = "$base/$dir/$entry";
  35. if (is_file($filename)) {
  36. if (substr($entry, -4) != '.php') {
  37. continue;
  38. }
  39. $data = file_get_contents($filename);
  40. $data = preg_replace('|/\*\*.*?\*/|s', '', $data);
  41. array_push($lines, "// file: $dir/$entry");
  42. foreach (explode("\n", $data) as $line) {
  43. if (!preg_match('/^<\?php|^namespace |^use |spl_autoload_register|declare\s*\(\s*strict_types\s*=\s*1|^\s*\/\//', $line)) {
  44. array_push($lines, $line);
  45. }
  46. }
  47. $count++;
  48. }
  49. }
  50. return $count;
  51. }
  52. function addHeader(array &$lines)
  53. {
  54. $head = <<<EOF
  55. <?php
  56. /**
  57. * PHP-CRUD-API v2 License: MIT
  58. * Maurits van der Schee: maurits@vdschee.nl
  59. * https://github.com/mevdschee/php-crud-api
  60. **/
  61. namespace Tqdev\PhpCrudApi;
  62. EOF;
  63. foreach (explode("\n", $head) as $line) {
  64. array_push($lines, $line);
  65. }
  66. }
  67. function run(string $base, string $dir, string $filename, array $priority)
  68. {
  69. $lines = [];
  70. $start = microtime(true);
  71. addHeader($lines);
  72. $count = runDir($base, 'src', $lines, $priority);
  73. $data = implode("\n", $lines);
  74. $data = preg_replace('/\n\s*\n\s*\n/', "\n\n", $data);
  75. file_put_contents('tmp_' . $filename, $data);
  76. ob_start();
  77. include 'tmp_' . $filename;
  78. ob_end_clean();
  79. rename('tmp_' . $filename, $filename);
  80. $end = microtime(true);
  81. $time = ($end - $start) * 1000;
  82. echo sprintf("%d files combined in %d ms into '%s'\n", $count, $time, $filename);
  83. }
  84. run(__DIR__, 'src', 'api.php', ['src/Psr']);