-
Notifications
You must be signed in to change notification settings - Fork 0
/
SplPhpObject.php
80 lines (71 loc) · 1.72 KB
/
SplPhpObject.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
<?php
namespace Php;
class SplPhpObject extends \SplFileObject implements \JsonSerializable
{
private array $I = [];
private array $L = [];
private array $N = [];
public function A(int $F = JSON_NUMERIC_CHECK | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES | JSON_BIGINT_AS_STRING | JSON_FORCE_OBJECT | JSON_PRETTY_PRINT, $D = 1024): Object
{
return (object)json_encode($this, $F, $D);
}
private function C(): String
{
return '<?php ' . join('', $this->L()) . ' ?>';
}
public function jsonSerialize(): mixed
{
return [
'I' => $this->I,
'L' => $this->L,
'N' => $this->N
];
}
private function L(): array
{
$L = [];
do {
array_push($L, mb_ereg_replace("\r", ' ', rtrim(ltrim($this->fgets()), '')));
} while (!$this->eof());
return $L;
}
private function P(): void
{
foreach ($this->T() as $Token) {
$I = $Token->id;
$L = $Token->line - 1;
$N = token_name($I);
$P = intval($Token->pos);
$T = trim($Token->text);
if (!empty($T)) {
if (!isset($this->N[$N])) {
$this->N[$N] = [];
}
if (mb_ereg_replace('[^\$\_a-zA-Z0-9]', '', $T, null) == $T) {
if (isset($this->L[$L]) == false) {
$this->L[$L] = [];
}
array_push($this->N[$N], $T);
$C = count($this->N[$N]);
array_push($this->I, strip_tags($L . '/' . $P . '/' . $N . '[' . $C . ']/@' . $I . '=' . $T));
array_push($this->L[$L], $T);
} else {
if (isset($this->N[$N][$T])) {
$this->N[$N][$T] += 1;
} else {
$this->N[$N][$T] = 0;
}
}
}
}
}
private function T(): array
{
return \PhpToken::tokenize($this->C());
}
public function __construct(string $F, $M = 'r', bool $U = false, $C = null)
{
parent::__construct($F, $M, $U, $C);
$this->P();
}
}