Skip to content

Commit

Permalink
ini entries were not always correctly registered when a extension was…
Browse files Browse the repository at this point in the history
… reloaded
  • Loading branch information
Aljar committed Dec 29, 2017
1 parent ea0989a commit 1b67997
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 101 deletions.
48 changes: 7 additions & 41 deletions include/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PHPCPP_EXPORT Extension : public Namespace
* @return Extension Same object to allow chaining
*/
Extension &onShutdown(const Callback &callback);

/**
* Register a callback that is called at the beginning of each pageview/request
*
Expand Down Expand Up @@ -118,50 +118,27 @@ class PHPCPP_EXPORT Extension : public Namespace
* @param ini The php.ini setting
* @return Extension Same object to allow chaining
*/
Extension &add(Ini &&ini)
{
// skip when locked
if (locked()) return *this;

// and add it to the list of classes
_ini_entries.emplace_back(new Ini(std::move(ini)));

// allow chaining
return *this;
}
Extension &add(Ini &&ini);

/**
* Add a ini entry to the extension by copying it
* @param ini The php.ini setting
* @param Extension Same object to allow chaining
*/
Extension &add(const Ini &ini)
{
// skip when locked
if (locked()) return *this;

// and add it to the list of classes
_ini_entries.emplace_back(new Ini(ini));

// allow chaining
return *this;
}
Extension &add(const Ini &ini);

/**
* Because the add function exists in both the Namespace base class
* as well as this extended Extension class, we have to tell the compiler
* that the add methods from the base are accessible too
* that the add methods from the base are accessble too
*/
using Namespace::add;

/**
* The total number of php.ini variables
* @return size_t
*/
size_t iniVariables() const
{
return _ini_entries.size();
}
size_t iniVariables() const;

/**
* Apply a callback to each php.ini variable
Expand All @@ -170,11 +147,7 @@ class PHPCPP_EXPORT Extension : public Namespace
*
* @param callback
*/
void iniVariables(const std::function<void(Ini &ini)> &callback)
{
// loop through the entries and apply the callback to each one
for (auto ini : _ini_entries) callback(*ini);
}
void iniVariables(const std::function<void(Ini &ini)> &callback);

/**
* Retrieve the module pointer
Expand Down Expand Up @@ -213,13 +186,6 @@ class PHPCPP_EXPORT Extension : public Namespace
* @var std::unique_ptr<ExtensionImpl>
*/
std::unique_ptr<ExtensionImpl> _impl;

/**
* Ini entry defined by the extension
* @var list
*/
std::list<std::shared_ptr<Ini>> _ini_entries;

};

/**
Expand Down
65 changes: 58 additions & 7 deletions zend/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Php {
*/
Extension::Extension(const char *name, const char *version, int apiversion) :
Namespace(""), _impl(new ExtensionImpl(this, name, version, apiversion)) {}

/**
* Destructor
*/
Expand All @@ -34,7 +34,7 @@ Extension &Extension::onStartup(const Callback &callback)
{
// pass on to the implementation
_impl->onStartup(callback);

// allow chaining
return *this;
}
Expand All @@ -48,7 +48,7 @@ Extension &Extension::onShutdown(const Callback &callback)
{
// pass on to the implementation
_impl->onShutdown(callback);

// allow chaining
return *this;
}
Expand All @@ -61,7 +61,7 @@ Extension &Extension::onRequest(const Callback &callback)
{
// pass on to the implementation
_impl->onRequest(callback);

// allow chaining
return *this;
}
Expand All @@ -74,14 +74,14 @@ Extension &Extension::onIdle(const Callback &callback)
{
// pass on to the implementation
_impl->onIdle(callback);

// allow chaining
return *this;
}

/**
* Retrieve the module pointer
*
*
* This is the memory address that should be exported by the get_module()
* function.
*
Expand All @@ -97,14 +97,65 @@ void *Extension::module()
* Is the extension object in a locked state? This happens after the
* get_module() function was called for the first time ("apache reload"
* forces a new call to get_module())
*
*
* @return bool
*/
bool Extension::locked() const
{
return _impl->locked();
}

/**
* Add a ini entry to the extension by moving it
* @param ini The php.ini setting
* @return Extension Same object to allow chaining
*/
Extension &Extension::add(Ini &&ini)
{
// pass on to the implementation
_impl->add(std::move(ini));

// allow chaining
return *this;
}

/**
* Add a ini entry to the extension by copying it
* @param ini The php.ini setting
* @param Extension Same object to allow chaining
*/
Extension &Extension::add(const Ini &ini)
{
// pass on to the implementation
_impl->add(ini);

// allow chaining
return *this;
}

/**
* The total number of php.ini variables
* @return size_t
*/
size_t Extension::iniVariables() const
{
// pass on to the implementation
return _impl->iniVariables();
}

/**
* Apply a callback to each php.ini variable
*
* The callback will be called with a reference to the ini variable.
*
* @param callback
*/
void Extension::iniVariables(const std::function<void(Ini &ini)> &callback)
{
// pass on to the implementation
_impl->iniVariables(callback);
}

/**
* End of namespace
*/
Expand Down
Loading

0 comments on commit 1b67997

Please sign in to comment.