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 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 |spl_autoload_register|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. namespace Tqdev\PhpCrudApi;
  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, array $priority)
  74. {
  75. $lines = [];
  76. $start = microtime(true);
  77. addHeader($lines);
  78. $ignore = array_flip($ignore);
  79. $priority = array_flip($priority);
  80. $count = 0;
  81. foreach ($dirs as $dir) {
  82. $count += runDir($base, $dir, $lines, $ignore, $priority);
  83. }
  84. $data = implode("\n", $lines);
  85. $data = preg_replace('/\n\s*\n\s*\n/', "\n\n", $data);
  86. file_put_contents('tmp_' . $filename, $data);
  87. ob_start();
  88. include 'tmp_' . $filename;
  89. ob_end_clean();
  90. rename('tmp_' . $filename, $filename);
  91. $end = microtime(true);
  92. $time = ($end - $start) * 1000;
  93. echo sprintf("%d files combined in %d ms into '%s'\n", $count, $time, $filename);
  94. }
  95. $ignore = [
  96. 'vendor/autoload.php',
  97. 'vendor/composer',
  98. 'vendor/php-http',
  99. 'vendor/nyholm/psr7/src/Factory/HttplugFactory.php',
  100. ];
  101. $priority = [
  102. 'vendor/psr',
  103. ];
  104. run(__DIR__, ['vendor', 'src'], 'api.php', $ignore, $priority);