/
index.php
100 lines (87 loc) · 2.82 KB
/
index.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* This software is the property of its authors.
* See the copyright.txt file for more details.
*
*/
function persistentIndex ($callback, $file = __FILE__, $line = __LINE__) {
var_dump($file);
var_dump($line);
assertTrue(false);
}
// back-compatibility function
function codeBaseTimestamp () {
return codeTimestamp();
}
function codeTimestamp () {
static $includedFiles = array();
static $timestamp = null;
$newIncludedFiles = includedFile();
if (isset($timestamp) && count($includedFiles) == count($newIncludedFiles))
return $timestamp;
foreach (array_diff($newIncludedFiles, $includedFiles) as $includedFile) {
if (!is_file($includedFile))
continue;
$mtime = filemtime($includedFile);
if (!isset($timestamp) || $mtime > $timestamp)
$timestamp = $mtime;
$includedFiles[] = $includedFile;
}
return $timestamp;
}
// back-compatibility function
function codeBaseChanged () {
return codeChanged();
}
function codeChanged () {
static $includedFiles = array();
static $result = true;
$newIncludedFiles = includedFile();
if (count($includedFiles) != count($newIncludedFiles)) {
$fingerprintFile = $_SERVER['cachePath'] . '/codeBase_' . sha1(serialize($newIncludedFiles)) . '.timestamp';
$result = !is_file($fingerprintFile) || codeTimestamp() > filemtime($fingerprintFile);
if ($result) {
directory(dirname($fingerprintFile));
$touchResult = touch($fingerprintFile);
enforce($touchResult, "Could not touch '$fingerprintFile'");
}
$includedFiles = $newIncludedFiles;
}
return $result;
}
function includedFile ($file = null) {
static $files = array();
if ($file === null)
return array_unique(array_merge(get_included_files(), $files));
version_assert and assertTrue(is_string($file));
version_assert and assertTrue(is_file($file));
$files[] = realpath($file);
}
/*
function codeIncludes ($path = null) {
static $paths = array();
static $pathsCacheCount = 0;
static $filesCache = array();
if (!isset($path)) {
if ($pathsCacheCount != count($paths)) {
version_profile and profileStopwatch('codeIncludes(): list files')->start();
$filesCache = array();
foreach ($paths as $path)
if (is_file($path))
$filesCache[] = $path;
else if (is_dir($path))
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $file)
$filesCache[] = (string) $file;
$pathsCacheCount = count($paths);
version_profile and profileStopwatch('codeIncludes(): list files')->stop();
}
return array_merge(get_included_files(), $filesCache);
}
$paths[] = $path;
}
/**/
// back-compatibility function
// staticIndex($file, $line, [$key,] $callback)
function staticIndex ($file, $line, $key, $callback = null) {
return staticCache($file, $line, $key, $callback);
}