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.3KB

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