-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_cli.php
77 lines (70 loc) · 1.87 KB
/
index_cli.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
ini_set("memory_limit","256M");
$b = new \PMVC\MappingBuilder();
${_INIT_CONFIG}[_CLASS] = 'FileSign';
${_INIT_CONFIG}[_INIT_BUILDER] = $b;
$b->addAction('index', [
_FORM => 'FileSignVerify'
]);
\PMVC\plug('view_cli',[
'flush'=>true
]);
class FileSign extends \PMVC\Action
{
function index($m, $f)
{
$path = $f['path'];
$pattern = $f['pattern'];
$exclude = $f['exclude'];
$log = $f['log'];
\PMVC\plug('view_cli',[
'plainText'=>$log
]);
$go = $m['dump'];
$go->set('Run', $path);
$go->set('Pattern', $pattern);
$go->set('Log', $log ? 'enable' : 'disable');
$files = PMVC\plug('file_list', [
'hash' => true,
'maskKey' => $path,
'exclude' => $exclude
])->ls($path, $pattern);
ksort($files);
foreach ($files as $k=>$v) {
$hash = \PMVC\value($v, ['hash']) ?: '';
if ($hash) {
$hash = ','.$hash;
}
$go->set($k.$hash);
}
return $go;
}
}
class FileSignVerify extends PMVC\ActionForm
{
function validate()
{
$inputPath = $this['path'];
if (is_dir($inputPath)) {
$path = $inputPath;
} else {
$inputPathInfo = pathinfo($inputPath);
$dir = \PMVC\value($inputPathInfo, ['dirname']);
if (in_array($dir, ['.', '/'])) {
$dir = null;
}
$path = $dir;
$pattern = $inputPathInfo['basename'];
}
if ( empty($path) || !realpath($path) ) {
return !trigger_error('No path found.');
} else {
if(empty($pattern)){
$pattern='*';
}
$this['path'] = $path;
$this['pattern'] = $pattern;
return true;
}
}
}