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.

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