-
Notifications
You must be signed in to change notification settings - Fork 39
/
Console.php
57 lines (42 loc) · 1.4 KB
/
Console.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
49
50
51
52
53
54
55
56
57
<?php
/**
* @link http://patchwork2.org/
* @author Ignas Rudaitis <ignas.rudaitis@gmail.com>
* @copyright 2010-2018 Ignas Rudaitis
* @license http://www.opensource.org/licenses/mit-license.html
*/
namespace Patchwork\Console;
use Patchwork\CodeManipulation as CM;
error_reporting(E_ALL | E_STRICT);
$argc > 2 && $argv[1] == 'prime'
or exit("\nUsage: php patchwork.phar prime DIR1 DIR2 ... DIRn\n" .
" (to recursively prime all PHP files under given directories)\n\n");
try {
CM\cacheEnabled()
or exit("\nError: no cache location set.\n\n");
} catch (Patchwork\Exceptions\CachePathUnavailable $e) {
exit("\nError: " . $e->getMessage() . "\n\n");
}
echo "\nCounting files...\n";
$files = [];
foreach (array_slice($argv, 2) as $path) {
$path = realpath($path);
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)) as $file) {
if (substr($file, -4) == '.php' && !CM\internalToCache($file) && !CM\availableCached($file)) {
$files[] = $file;
}
}
}
$count = count($files);
$count > 0 or exit("\nNothing to do.\n\n");
echo "\nPriming ($count files total):\n";
const CONSOLE_WIDTH = 80;
$progress = 0;
for ($i = 0; $i < $count; $i++) {
CM\prime($files[$i]->getRealPath());
while ((int) (($i + 1) / $count * CONSOLE_WIDTH) > $progress) {
echo '.';
$progress++;
}
}
echo "\n\n";