summaryrefslogtreecommitdiff
path: root/zend/extensionimpl.h
blob: aef480258257522f01e7dce11b75ccc1097fcd18 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
 *  ExtensionImpl.h
 *
 *  Extension implementation for the Zend engine.
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013, 2014 Copernica BV
 */

/**
 *  Set up namespace
 */
namespace Php {

/**
 *  Class definition
 */
class ExtensionImpl : public ExtensionBase
{
protected:
    /**
     *  The information that is passed to the Zend engine
     *  @var zend_module_entry
     */
    zend_module_entry _entry;

    /**
     *  Is the object locked? This prevents crashes for 'apache reload'
     *  because we then do not have to re-initialize the entire php engine
     *  @var bool
     */
    bool _locked = false;

    /**
     *  The .ini entries
     *
     *  @var std::unique_ptr<zend_ini_entry_def[]>
     */
    std::unique_ptr<zend_ini_entry_def[]> _ini = nullptr;

public:
    /**
     *  Constructor
     *  @param  data        Extension object created by the extension programmer
     *  @param  name        Name of the extension
     *  @param  version     Version number
     *  @param  apiversion  API version number
     */
    ExtensionImpl(Extension *data, const char *name, const char *version, int apiversion);

    /**
     *  No copy'ing and no moving
     */
    ExtensionImpl(const ExtensionImpl &extension) = delete;
    ExtensionImpl(ExtensionImpl &&extension) = delete;

    /**
     *  Destructor
     */
    virtual ~ExtensionImpl();

    /**
     *  The extension name
     *  @return const char *
     */
    const char *name() const;

    /**
     *  The extension version
     *  @return const char *
     */
    const char *version() const;

    /**
     *  Is the object locked (true) or is it still possible to add more functions,
     *  classes and other elements to it?
     *  @return bool
     */
    bool locked()
    {
        // return member
        return _locked;
    }

    /**
     *  Retrieve the module entry
     *
     *  This is the memory address that should be exported by the get_module()
     *  function.
     *
     *  @return _zend_module_entry
     */
    zend_module_entry *module();

    /**
     *  Cast to a module entry
     *  @return _zend_module_entry*
     */
    operator zend_module_entry * ()
    {
        return module();
    }

private:
    /**
     *  Initialize the extension after it was registered
     *  @param  module_number
     *  @param  tsrm_ls
     *  @return bool
     */
    bool initialize(int module_number TSRMLS_DC);

    /**
     *  Shutdown the extension
     *  @param  module_number
     *  @param  tsrm_ls
     *  @return bool
     */
    bool shutdown(int module_number TSRMLS_DC);

    /**
     *  Function that is called when the extension initializes
     *  @param  type        Module type
     *  @param  number      Module number
     *  @param  tsrm_ls
     *  @return int         0 on success
     */
    static int processStartup(int type, int module_number TSRMLS_DC);

    /**
     *  Function that is called when the extension is about to be stopped
     *  @param  type        Module type
     *  @param  number      Module number
     *  @param  tsrm_ls
     *  @return int
     */
    static int processShutdown(int type, int module_number TSRMLS_DC);

    /**
     *  Function that is called when a request starts
     *  @param  type        Module type
     *  @param  number      Module number
     *  @param  tsrm_ls
     *  @return int         0 on success
     */
    static int processRequest(int type, int module_number TSRMLS_DC);

    /**
     *  Function that is called when a request is ended
     *  @param  type        Module type
     *  @param  number      Module number
     *  @param  tsrm_ls
     *  @return int         0 on success
     */
    static int processIdle(int type, int module_number TSRMLS_DC);

    /**
     *  Function that is called when the PHP engine initializes with a different PHP-CPP
     *  version for the libphpcpp.so file than the version the extension was compiled for
     *  @param  type        Module type
     *  @param  number      Module number
     *  @param  tsrm_ls
     *  @return int         0 on success
     */
    static int processMismatch(int type, int module_number TSRMLS_DC);
};

/**
 *  End of namespace
 */
}