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

OpcacheProxy::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
rs 9.4285
nc 1
cc 1
eloc 8
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 OpcacheProxy 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
            'opcache_compile_file',
31
            'opcache_get_configuration',
32
            'opcache_get_status',
33
            'opcache_invalidate',
34
            'opcache_reset',
35
36
            'opcache_version'
37
        );
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function setAdapter(AbstractAdapter $adapter)
44
    {
45
        $this->adapter = $adapter;
46
    }
47
48
    /**
49
     * Compiles and caches a PHP script without executing it
50
     *
51
     * This function compiles a PHP script and adds it to the opcode cache without executing it. This can be used to
52
     * prime the cache after a Web server restart by pre-caching files that will be included in later requests.
53
     *
54
     * @since  5.5.5
55
     * @since  7.0.2
56
     * @param  string $file The path to the PHP script to be compiled.
57
     * @return boolean      Returns TRUE if file was compiled successfully or FALSE on failure.
58
     */
59
    public function opcache_compile_file($file)
60
    {
61
        $code = new Code();
62
        $code->addStatement(sprintf(
63
            'return opcache_compile_file(%s);',
64
            var_export($file, true)
65
        ));
66
67
        return $this->adapter->run($code);
68
    }
69
70
    /**
71
     * Get configuration information about the cache
72
     *
73
     * @since  5.5.5
74
     * @since  7.0.2
75
     * @return array Returns an array of information, including ini, blacklist and version
76
     */
77
    public function opcache_get_configuration()
78
    {
79
        $code = new Code();
80
        $code->addStatement('return opcache_get_configuration();');
81
82
        return $this->adapter->run($code);
83
    }
84
85
    /**
86
     * Get status information about the cache
87
     *
88
     * @since  5.5.5
89
     * @since  7.0.2
90
     * @param  boolean $get_scripts Include script specific state information
91
     * @return array                Returns an array of information, optionally containing script specific state
92
     *                              information
93
     */
94
    public function opcache_get_status($get_scripts = true)
95
    {
96
        $code = new Code();
97
        $code->addStatement(sprintf(
98
            'return opcache_get_status(%s);',
99
            var_export($get_scripts, true)
100
        ));
101
102
        return $this->adapter->run($code);
103
    }
104
105
    /**
106
     * Get status information about the cache
107
     *
108
     * @since  5.5.0
109
     * @since  7.0.0
110
     * @param  string  $script The path to the script being invalidated.
111
     * @param  boolean $force  If set to TRUE, the script will be invalidated regardless of whether invalidation is
112
     *                         necessary.
113
     * @return boolean         Returns TRUE if the opcode cache for script was invalidated or if there was nothing to
114
     *                         invalidate, or FALSE if the opcode cache is disabled.
115
     */
116
    public function opcache_invalidate($script, $force = false)
117
    {
118
        $code = new Code();
119
        $code->addStatement(sprintf(
120
            'return opcache_invalidate(%s, %s);',
121
            var_export($script, true),
122
            var_export($force, true)
123
        ));
124
125
        return $this->adapter->run($code);
126
    }
127
128
    /**
129
     * Resets the contents of the opcode cache
130
     *
131
     * @since  5.5.0
132
     * @since  7.0.0
133
     * @return boolean Returns TRUE if the opcode cache was reset, or FALSE if the opcode cache is disabled.
134
     */
135
    public function opcache_reset()
136
    {
137
        $code = new Code();
138
        $code->addStatement('return opcache_reset();');
139
140
        return $this->adapter->run($code);
141
    }
142
143
    /**
144
     * @return string
145
     */
146
    public function opcache_version()
147
    {
148
        $code = new Code();
149
        $code->addStatement('return phpversion("Zend OPcache");');
150
151
        return $this->adapter->run($code);
152
    }
153
}
154