Completed
Push — 1.x ( 8c31f4...5f4811 )
by Samuel
7s
created

PhpProxy::stat_realpath_get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
nc 1
cc 1
eloc 4
nop 0
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
    public function getFunctions()
28
    {
29
        return array(
30
            '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
    public function setAdapter(AbstractAdapter $adapter)
46
    {
47
        $this->adapter = $adapter;
48
    }
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
    public function extension_loaded($name)
57
    {
58
        $code = new Code();
59
        $code->addStatement(sprintf(
60
            "return extension_loaded(%s);",
61
            var_export($name, true)
62
        ));
63
64
        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
    public function ini_get($varname)
75
    {
76
        $code = new Code();
77
        $code->addStatement(sprintf(
78
            "return ini_get(%s);",
79
            var_export($varname, true)
80
        ));
81
82
        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
    public function ini_set($varname, $newvalue)
94
    {
95
        $code = new Code();
96
        $code->addStatement(sprintf(
97
            "return ini_set(%s, %s);",
98
            var_export($varname, true),
99
            var_export($newvalue, true)
100
        ));
101
102
        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
    public function phpversion($extension = null)
112
    {
113
        $code = new Code();
114
        $code->addStatement(sprintf(
115
            "return phpversion(%s);",
116
            var_export($extension, true)
117
        ));
118
119
        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
    public function stat_realpath_get()
131
    {
132
        $code = new Code();
133
        $code->addStatement('return realpath_cache_get();');
134
135
        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
    public function stat_realpath_size()
145
    {
146
        $code = new Code();
147
        $code->addStatement('return realpath_cache_size();');
148
149
        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
    public function stat_cache_clear()
158
    {
159
        $code = new Code();
160
        $code->addStatement('return clearstatcache(true);');
161
162
        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
    public function _eval($expression)
172
    {
173
        $code = new Code();
174
        $code->addStatement($expression);
175
176
        return $this->adapter->run($code);
177
    }
178
}
179