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.

patch.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. // patch files for PHP 7.0 compatibility
  3. function patchDir(string $base, string $dir): int
  4. {
  5. $count = 0;
  6. $entries = scandir($dir);
  7. foreach ($entries as $entry) {
  8. if ($entry === '.' || $entry === '..') {
  9. continue;
  10. }
  11. $filename = "$base/$dir/$entry";
  12. if (is_dir($filename)) {
  13. $count += patchDir($base, "$dir/$entry");
  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. $patched = $original = file_get_contents($filename);
  23. $patched = preg_replace('/\):\s*(\?[a-zA-Z]+|void)\s*\n/', ") /*:$1*/\n", $patched);
  24. $patched = preg_replace('/([\(,])\s*(\?[a-zA-Z]+|void)\s+\$/', "$1 /*$2*/ \$", $patched);
  25. $patched = preg_replace('/(private|public|protected) const/', "/*$1*/ const", $patched);
  26. if ($patched && $patched != $original) {
  27. file_put_contents($filename, $patched);
  28. $count++;
  29. }
  30. }
  31. }
  32. return $count;
  33. }
  34. function patch(string $base, array $dirs)
  35. {
  36. $start = microtime(true);
  37. $count = 0;
  38. foreach ($dirs as $dir) {
  39. $count += patchDir($base, $dir);
  40. }
  41. $end = microtime(true);
  42. $time = ($end - $start) * 1000;
  43. if ($count) {
  44. fwrite(STDERR, sprintf("%d files patched in %d ms\n", $count, $time));
  45. }
  46. }
  47. patch(__DIR__, ['vendor']);