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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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