forked from webvul/php-filter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterHelper.php
More file actions
executable file
·62 lines (49 loc) · 1.17 KB
/
Copy pathFilterHelper.php
File metadata and controls
executable file
·62 lines (49 loc) · 1.17 KB
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
<?php
/**
* 过滤器助手
*
* getResTrie 提供trie-tree对象;
* getFilterWords 提取过滤出的字符串
*
* @author W.Y.P (wyp@41ms.com)
*/
require_once 'Trie.php';
class FilterHelper
{
// trie-tree对象
private static $_trie = null;
// 字典树的更新时间
private static $_mtime = null;
/**
* 防止初始化
*/
private function __construct()
{
}
/**
* 防止克隆对象
*/
private function __clone()
{
}
/**
* 提供trie-tree对象
*
* @param $tree_file 字典树文件路径
* @param $new_mtime 当前调用时字典树的更新时间
* @return null
*/
static public function get_trie($tree_file, $new_mtime)
{
if (is_null(self::$_mtime)) {
self::$_mtime = $new_mtime;
}
if (($new_mtime != self::$_mtime) || is_null(self::$_trie)) {
self::$_trie = unserialize(gzinflate(file_get_contents($tree_file)));
self::$_mtime = $new_mtime;
// 输出字典文件重载时间
echo date('Y-m-d H:i:s') . "\ttree reload success!\n";
}
return self::$_trie;
}
}