Skip to content

Commit 1b67997

Browse files
committed
ini entries were not always correctly registered when a extension was reloaded
1 parent ea0989a commit 1b67997

File tree

4 files changed

+207
-101
lines changed

4 files changed

+207
-101
lines changed

include/extension.h

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PHPCPP_EXPORT Extension : public Namespace
8686
* @return Extension Same object to allow chaining
8787
*/
8888
Extension &onShutdown(const Callback &callback);
89-
89+
9090
/**
9191
* Register a callback that is called at the beginning of each pageview/request
9292
*
@@ -118,50 +118,27 @@ class PHPCPP_EXPORT Extension : public Namespace
118118
* @param ini The php.ini setting
119119
* @return Extension Same object to allow chaining
120120
*/
121-
Extension &add(Ini &&ini)
122-
{
123-
// skip when locked
124-
if (locked()) return *this;
125-
126-
// and add it to the list of classes
127-
_ini_entries.emplace_back(new Ini(std::move(ini)));
128-
129-
// allow chaining
130-
return *this;
131-
}
121+
Extension &add(Ini &&ini);
132122

133123
/**
134124
* Add a ini entry to the extension by copying it
135125
* @param ini The php.ini setting
136126
* @param Extension Same object to allow chaining
137127
*/
138-
Extension &add(const Ini &ini)
139-
{
140-
// skip when locked
141-
if (locked()) return *this;
142-
143-
// and add it to the list of classes
144-
_ini_entries.emplace_back(new Ini(ini));
145-
146-
// allow chaining
147-
return *this;
148-
}
128+
Extension &add(const Ini &ini);
149129

150130
/**
151131
* Because the add function exists in both the Namespace base class
152132
* as well as this extended Extension class, we have to tell the compiler
153-
* that the add methods from the base are accessible too
133+
* that the add methods from the base are accessble too
154134
*/
155135
using Namespace::add;
156-
136+
157137
/**
158138
* The total number of php.ini variables
159139
* @return size_t
160140
*/
161-
size_t iniVariables() const
162-
{
163-
return _ini_entries.size();
164-
}
141+
size_t iniVariables() const;
165142

166143
/**
167144
* Apply a callback to each php.ini variable
@@ -170,11 +147,7 @@ class PHPCPP_EXPORT Extension : public Namespace
170147
*
171148
* @param callback
172149
*/
173-
void iniVariables(const std::function<void(Ini &ini)> &callback)
174-
{
175-
// loop through the entries and apply the callback to each one
176-
for (auto ini : _ini_entries) callback(*ini);
177-
}
150+
void iniVariables(const std::function<void(Ini &ini)> &callback);
178151

179152
/**
180153
* Retrieve the module pointer
@@ -213,13 +186,6 @@ class PHPCPP_EXPORT Extension : public Namespace
213186
* @var std::unique_ptr<ExtensionImpl>
214187
*/
215188
std::unique_ptr<ExtensionImpl> _impl;
216-
217-
/**
218-
* Ini entry defined by the extension
219-
* @var list
220-
*/
221-
std::list<std::shared_ptr<Ini>> _ini_entries;
222-
223189
};
224190

225191
/**

zend/extension.cpp

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Php {
1919
*/
2020
Extension::Extension(const char *name, const char *version, int apiversion) :
2121
Namespace(""), _impl(new ExtensionImpl(this, name, version, apiversion)) {}
22-
22+
2323
/**
2424
* Destructor
2525
*/
@@ -34,7 +34,7 @@ Extension &Extension::onStartup(const Callback &callback)
3434
{
3535
// pass on to the implementation
3636
_impl->onStartup(callback);
37-
37+
3838
// allow chaining
3939
return *this;
4040
}
@@ -48,7 +48,7 @@ Extension &Extension::onShutdown(const Callback &callback)
4848
{
4949
// pass on to the implementation
5050
_impl->onShutdown(callback);
51-
51+
5252
// allow chaining
5353
return *this;
5454
}
@@ -61,7 +61,7 @@ Extension &Extension::onRequest(const Callback &callback)
6161
{
6262
// pass on to the implementation
6363
_impl->onRequest(callback);
64-
64+
6565
// allow chaining
6666
return *this;
6767
}
@@ -74,14 +74,14 @@ Extension &Extension::onIdle(const Callback &callback)
7474
{
7575
// pass on to the implementation
7676
_impl->onIdle(callback);
77-
77+
7878
// allow chaining
7979
return *this;
8080
}
8181

8282
/**
8383
* Retrieve the module pointer
84-
*
84+
*
8585
* This is the memory address that should be exported by the get_module()
8686
* function.
8787
*
@@ -97,14 +97,65 @@ void *Extension::module()
9797
* Is the extension object in a locked state? This happens after the
9898
* get_module() function was called for the first time ("apache reload"
9999
* forces a new call to get_module())
100-
*
100+
*
101101
* @return bool
102102
*/
103103
bool Extension::locked() const
104104
{
105105
return _impl->locked();
106106
}
107107

108+
/**
109+
* Add a ini entry to the extension by moving it
110+
* @param ini The php.ini setting
111+
* @return Extension Same object to allow chaining
112+
*/
113+
Extension &Extension::add(Ini &&ini)
114+
{
115+
// pass on to the implementation
116+
_impl->add(std::move(ini));
117+
118+
// allow chaining
119+
return *this;
120+
}
121+
122+
/**
123+
* Add a ini entry to the extension by copying it
124+
* @param ini The php.ini setting
125+
* @param Extension Same object to allow chaining
126+
*/
127+
Extension &Extension::add(const Ini &ini)
128+
{
129+
// pass on to the implementation
130+
_impl->add(ini);
131+
132+
// allow chaining
133+
return *this;
134+
}
135+
136+
/**
137+
* The total number of php.ini variables
138+
* @return size_t
139+
*/
140+
size_t Extension::iniVariables() const
141+
{
142+
// pass on to the implementation
143+
return _impl->iniVariables();
144+
}
145+
146+
/**
147+
* Apply a callback to each php.ini variable
148+
*
149+
* The callback will be called with a reference to the ini variable.
150+
*
151+
* @param callback
152+
*/
153+
void Extension::iniVariables(const std::function<void(Ini &ini)> &callback)
154+
{
155+
// pass on to the implementation
156+
_impl->iniVariables(callback);
157+
}
158+
108159
/**
109160
* End of namespace
110161
*/

0 commit comments

Comments
 (0)