bootstrap.php 893 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace PhpParser;
  3. require __DIR__ . '/../vendor/autoload.php';
  4. function canonicalize($str) {
  5. // normalize EOL style
  6. $str = str_replace("\r\n", "\n", $str);
  7. // trim newlines at end
  8. $str = rtrim($str, "\n");
  9. // remove trailing whitespace on all lines
  10. $lines = explode("\n", $str);
  11. $lines = array_map(function($line) {
  12. return rtrim($line, " \t");
  13. }, $lines);
  14. return implode("\n", $lines);
  15. }
  16. function filesInDir($directory, $fileExtension) {
  17. $directory = realpath($directory);
  18. $it = new \RecursiveDirectoryIterator($directory);
  19. $it = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::LEAVES_ONLY);
  20. $it = new \RegexIterator($it, '(\.' . preg_quote($fileExtension) . '$)');
  21. foreach ($it as $file) {
  22. $fileName = $file->getPathname();
  23. yield $fileName => file_get_contents($fileName);
  24. }
  25. }