forked from doctrine-extensions/DoctrineExtensions
-
Notifications
You must be signed in to change notification settings - Fork 52
/
purify.php
48 lines (37 loc) · 1.21 KB
/
purify.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
define('VENDOR_PATH', realpath(__DIR__ . '/../vendor'));
set_include_path(implode(PATH_SEPARATOR, array(
VENDOR_PATH,
get_include_path(),
)));
$classLoaderFile = VENDOR_PATH . '/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
if (!file_exists($classLoaderFile)) {
die('cannot find vendor, git submodule init && git submodule update');
}
require_once $classLoaderFile;
$classLoader = new Doctrine\Common\ClassLoader('Symfony');
$classLoader->register();
$finder = new Symfony\Component\Finder\Finder;
$finder->files()
->name('*.php')
->in(__DIR__ . '/../lib')
->in(__DIR__ . '/../tests');
foreach ($finder as $fileInfo) {
if (!$fileInfo->isReadable()) {
continue;
}
$count = 0;
$total = 0;
$needsSave = false;
$content = file_get_contents($fileInfo->getRealPath());
$content = str_replace("\t", ' ', $content, $count);
$total += $count;
$content = str_replace("\r\n", "\n", $content, $count);
$total += $count;
$needsSave = $total != 0;
if ($needsSave) {
file_put_contents($fileInfo->getRealPath(), $content);
echo $fileInfo->getRealPath() . PHP_EOL;
}
}
echo 'done';