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.

build.php 2.8KB

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