|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the reliforp/reli-prof package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) sji <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Reli\Lib\PhpInternals\Types\Zend; |
|
15
|
|
|
|
|
16
|
|
|
use FFI\CData; |
|
17
|
|
|
use Reli\Lib\PhpInternals\CastedCData; |
|
18
|
|
|
use Reli\Lib\Process\Pointer\Dereferencable; |
|
19
|
|
|
use Reli\Lib\Process\Pointer\Pointer; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @psalm-consistent-constructor |
|
23
|
|
|
*/ |
|
24
|
|
|
class Zval implements Dereferencable |
|
25
|
|
|
{ |
|
26
|
|
|
/** @psalm-suppress PropertyNotSetInConstructor */ |
|
27
|
|
|
public ZendValue $value; |
|
28
|
|
|
/** @psalm-suppress PropertyNotSetInConstructor */ |
|
29
|
|
|
public ZvalU1 $u1; |
|
30
|
|
|
/** @psalm-suppress PropertyNotSetInConstructor */ |
|
31
|
|
|
public ZvalU2 $u2; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param CastedCData<\FFI\PhpInternals\zval> $casted_cdata |
|
35
|
|
|
* @param Pointer<Zval> $pointer |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct( |
|
38
|
|
|
protected CastedCData $casted_cdata, |
|
39
|
|
|
protected Pointer $pointer, |
|
40
|
|
|
) { |
|
41
|
|
|
unset($this->value); |
|
42
|
|
|
unset($this->u1); |
|
43
|
|
|
unset($this->u2); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function __get(string $field_name): mixed |
|
47
|
|
|
{ |
|
48
|
|
|
return match ($field_name) { |
|
49
|
|
|
'value' => $this->value = new ZendValue($this->casted_cdata->casted->value), |
|
50
|
|
|
'u1' => $this->u1 = new ZvalU1($this->casted_cdata->casted->u1), |
|
51
|
|
|
'u2' => $this->u2 = new ZvalU2($this->casted_cdata->casted->u2), |
|
52
|
|
|
}; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getType(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->u1->getType(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function isArray(): bool |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->getType() === 'IS_ARRAY'; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function isObject(): bool |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getType() === 'IS_OBJECT'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function isString(): bool |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->getType() === 'IS_STRING'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function isLong(): bool |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->getType() === 'IS_LONG'; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function isDouble(): bool |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->getType() === 'IS_DOUBLE'; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function isBool(): bool |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->getType() === 'IS_TRUE' || $this->getType() === 'IS_FALSE'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function isNull(): bool |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->getType() === 'IS_NULL'; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function isScalar(): bool |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->isLong() || $this->isDouble() || $this->isBool() || $this->isNull(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function isResource(): bool |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->getType() === 'IS_RESOURCE'; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function isReference(): bool |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->getType() === 'IS_REFERENCE'; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function isIndirect(): bool |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->getType() === 'IS_INDIRECT'; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function isUndef(): bool |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->getType() === 'IS_UNDEF'; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public static function getCTypeName(): string |
|
121
|
|
|
{ |
|
122
|
|
|
return 'zval'; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public static function fromCastedCData(CastedCData $casted_cdata, Pointer $pointer): static |
|
126
|
|
|
{ |
|
127
|
|
|
/** |
|
128
|
|
|
* @var CastedCData<\FFI\PhpInternals\zval> $casted_cdata |
|
129
|
|
|
* @var Pointer<Zval> $pointer |
|
130
|
|
|
*/ |
|
131
|
|
|
return new static($casted_cdata, $pointer); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return Pointer<Zval> |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getPointer(): Pointer |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->pointer; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|