purify.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. define('VENDOR_PATH', realpath(__DIR__ . '/../vendor'));
  3. set_include_path(implode(PATH_SEPARATOR, array(
  4. VENDOR_PATH,
  5. get_include_path(),
  6. )));
  7. $classLoaderFile = VENDOR_PATH . '/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
  8. if (!file_exists($classLoaderFile)) {
  9. die('cannot find vendor, run: php bin/vendors.php');
  10. }
  11. require_once $classLoaderFile;
  12. $classLoader = new Doctrine\Common\ClassLoader('Symfony');
  13. $classLoader->register();
  14. $finder = new Symfony\Component\Finder\Finder;
  15. $finder->files()
  16. ->name('*.php')
  17. ->in(__DIR__ . '/../lib')
  18. ->in(__DIR__ . '/../tests');
  19. foreach ($finder as $fileInfo) {
  20. if (!$fileInfo->isReadable()) {
  21. continue;
  22. }
  23. $count = 0;
  24. $total = 0;
  25. $needsSave = false;
  26. $content = file_get_contents($fileInfo->getRealPath());
  27. $content = str_replace("\t", ' ', $content, $count);
  28. $total += $count;
  29. $content = str_replace("\r\n", "\n", $content, $count);
  30. $total += $count;
  31. $needsSave = $total != 0;
  32. if ($needsSave) {
  33. file_put_contents($fileInfo->getRealPath(), $content);
  34. echo $fileInfo->getRealPath() . PHP_EOL;
  35. }
  36. }
  37. echo 'done';