|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of CacheTool. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Samuel Gordalina <[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
|
|
|
namespace CacheTool\Proxy; |
|
13
|
|
|
|
|
14
|
|
|
use CacheTool\Adapter\AbstractAdapter; |
|
15
|
|
|
use CacheTool\Code; |
|
16
|
|
|
|
|
17
|
|
|
class PhpProxy implements ProxyInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var AbstractAdapter |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $adapter; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
15 |
|
public function getFunctions() |
|
28
|
|
|
{ |
|
29
|
|
|
return [ |
|
30
|
15 |
|
'extension_loaded', |
|
31
|
|
|
'ini_get', |
|
32
|
|
|
'ini_set', |
|
33
|
|
|
'phpversion', |
|
34
|
|
|
'stat_realpath_get', |
|
35
|
|
|
'stat_realpath_size', |
|
36
|
|
|
'stat_cache_clear', |
|
37
|
|
|
|
|
38
|
|
|
'_eval', |
|
39
|
|
|
]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
15 |
|
public function setAdapter(AbstractAdapter $adapter) |
|
46
|
|
|
{ |
|
47
|
15 |
|
$this->adapter = $adapter; |
|
48
|
15 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Find out whether an extension is loaded |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $name The extension name. This parameter is case-insensitive |
|
54
|
|
|
* @return boolean Returns TRUE if the extension identified by name is loaded, FALSE otherwise |
|
55
|
|
|
*/ |
|
56
|
15 |
|
public function extension_loaded($name) |
|
57
|
|
|
{ |
|
58
|
15 |
|
$code = new Code(); |
|
59
|
15 |
|
$code->addStatement(sprintf( |
|
60
|
15 |
|
"return extension_loaded(%s);", |
|
61
|
15 |
|
var_export($name, true) |
|
62
|
|
|
)); |
|
63
|
|
|
|
|
64
|
15 |
|
return $this->adapter->run($code); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Gets the value of a configuration option |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $varname The configuration option name |
|
71
|
|
|
* @return string Returns the value of the configuration option as a string on success, or an empty string |
|
72
|
|
|
* for null values. Returns FALSE if the configuration option doesn't exist. |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function ini_get($varname) |
|
75
|
|
|
{ |
|
76
|
1 |
|
$code = new Code(); |
|
77
|
1 |
|
$code->addStatement(sprintf( |
|
78
|
1 |
|
"return ini_get(%s);", |
|
79
|
1 |
|
var_export($varname, true) |
|
80
|
|
|
)); |
|
81
|
|
|
|
|
82
|
1 |
|
return $this->adapter->run($code); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Gets the value of a configuration option |
|
87
|
|
|
* |
|
88
|
|
|
* @param string $varname Not all the available options can be changed using ini_set(). There is a list of all |
|
89
|
|
|
* available options in the appendix. |
|
90
|
|
|
* @param string $newvalue The new value for the option |
|
91
|
|
|
* @return string Returns the old value on success, FALSE on failure |
|
92
|
|
|
*/ |
|
93
|
1 |
|
public function ini_set($varname, $newvalue) |
|
94
|
|
|
{ |
|
95
|
1 |
|
$code = new Code(); |
|
96
|
1 |
|
$code->addStatement(sprintf( |
|
97
|
1 |
|
"return ini_set(%s, %s);", |
|
98
|
1 |
|
var_export($varname, true), |
|
99
|
1 |
|
var_export($newvalue, true) |
|
100
|
|
|
)); |
|
101
|
|
|
|
|
102
|
1 |
|
return $this->adapter->run($code); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Returns a string containing the version of the currently running PHP parser or extension. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $extension An optional extension name |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
1 |
|
public function phpversion($extension = null) |
|
112
|
|
|
{ |
|
113
|
1 |
|
$code = new Code(); |
|
114
|
1 |
|
$code->addStatement(sprintf( |
|
115
|
1 |
|
"return phpversion(%s);", |
|
116
|
1 |
|
var_export($extension, true) |
|
117
|
|
|
)); |
|
118
|
|
|
|
|
119
|
1 |
|
return $this->adapter->run($code); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Get contents of the realpath cache |
|
124
|
|
|
* |
|
125
|
|
|
* @since 5.3.2 |
|
126
|
|
|
* @return array Returns an array of realpath cache entries. The keys are original path entries, |
|
127
|
|
|
* and the values are arrays of data items, containing the resolved path, expiration date, and |
|
128
|
|
|
* other options kept in the cache. |
|
129
|
|
|
*/ |
|
130
|
1 |
|
public function stat_realpath_get() |
|
131
|
|
|
{ |
|
132
|
1 |
|
$code = new Code(); |
|
133
|
1 |
|
$code->addStatement('return realpath_cache_get();'); |
|
134
|
|
|
|
|
135
|
1 |
|
return $this->adapter->run($code); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Returns how much memory realpath cache is using. |
|
140
|
|
|
* |
|
141
|
|
|
* @since 5.3.2 |
|
142
|
|
|
* @return int Memory usage in bytes |
|
143
|
|
|
*/ |
|
144
|
1 |
|
public function stat_realpath_size() |
|
145
|
|
|
{ |
|
146
|
1 |
|
$code = new Code(); |
|
147
|
1 |
|
$code->addStatement('return realpath_cache_size();'); |
|
148
|
|
|
|
|
149
|
1 |
|
return $this->adapter->run($code); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Resets the contents of the file status cache, including the realpath cache |
|
154
|
|
|
* |
|
155
|
|
|
* @return void |
|
156
|
|
|
*/ |
|
157
|
1 |
|
public function stat_cache_clear() |
|
158
|
|
|
{ |
|
159
|
1 |
|
$code = new Code(); |
|
160
|
1 |
|
$code->addStatement('return clearstatcache(true);'); |
|
161
|
|
|
|
|
162
|
1 |
|
return $this->adapter->run($code); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Evaluate a string as PHP code |
|
167
|
|
|
* |
|
168
|
|
|
* @param string $expression Evaluates the given code as PHP |
|
169
|
|
|
* @return mixed |
|
170
|
|
|
*/ |
|
171
|
1 |
|
public function _eval($expression) |
|
172
|
|
|
{ |
|
173
|
1 |
|
$code = new Code(); |
|
174
|
1 |
|
$code->addStatement($expression); |
|
175
|
|
|
|
|
176
|
1 |
|
return $this->adapter->run($code); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|