summaryrefslogtreecommitdiff
path: root/zend
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-10 11:36:44 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-10 11:36:44 +0200
commitf0dec5907bd49bb468089b0fe50d8cbf2979272e (patch)
treef6ca989d6233cfc591efe07660e6dbb774d5f505 /zend
parentec2ee67b805b3f431db4ce2f9cdfc8d74aadfe35 (diff)
parent3119060c9c8905b9d07e04a342a2c32cf0bf1358 (diff)
Merge pull request #76 from valmat/ini
Implemented issue # 64
Diffstat (limited to 'zend')
-rw-r--r--zend/extensionimpl.cpp22
-rw-r--r--zend/includes.h3
-rw-r--r--zend/ini.cpp57
-rw-r--r--zend/namespace.cpp15
4 files changed, 94 insertions, 3 deletions
diff --git a/zend/extensionimpl.cpp b/zend/extensionimpl.cpp
index b1ec6e8..0308c63 100644
--- a/zend/extensionimpl.cpp
+++ b/zend/extensionimpl.cpp
@@ -110,10 +110,20 @@ int ExtensionImpl::processStartup(int type, int module_number TSRMLS_DC)
{
// initialize and allocate the "global" variables
ZEND_INIT_MODULE_GLOBALS(phpcpp, init_globals, NULL);
-
+
+
// get the extension
auto *extension = find(module_number TSRMLS_CC);
+
+ // array contains ini settings
+ static zend_ini_entry *ini_entries = new zend_ini_entry[ extension->_data->ini_size()+1 ];
+
+ // Filling ini entries
+ extension->_data->fill_ini(ini_entries, module_number);
+ // register ini entries in Zend core
+ REGISTER_INI_ENTRIES();
+
// initialize the extension
extension->initialize(TSRMLS_C);
@@ -135,7 +145,13 @@ int ExtensionImpl::processShutdown(int type, int module_number TSRMLS_DC)
{
// get the extension
auto *extension = find(module_number TSRMLS_CC);
-
+
+
+ UNREGISTER_INI_ENTRIES();
+ // free memory from array ini entries
+ static zend_ini_entry *ini_entries;
+ delete [] ini_entries;
+
// is the callback registered?
if (extension->_onShutdown) extension->_onShutdown();
@@ -197,7 +213,7 @@ ExtensionImpl::ExtensionImpl(Extension *data, const char *name, const char *vers
_entry.zend_api = ZEND_MODULE_API_NO; // api number
_entry.zend_debug = ZEND_DEBUG; // debug mode enabled?
_entry.zts = USING_ZTS; // is thread safety enabled?
- _entry.ini_entry = NULL; // the php.ini record
+ _entry.ini_entry = NULL; // the php.ini record, will be filled by Zend engine
_entry.deps = NULL; // dependencies on other modules
_entry.name = name; // extension name
_entry.functions = NULL; // functions supported by this module (none for now)
diff --git a/zend/includes.h b/zend/includes.h
index 274ad85..4aa5eb0 100644
--- a/zend/includes.h
+++ b/zend/includes.h
@@ -15,6 +15,7 @@
#include <initializer_list>
#include <vector>
#include <map>
+#include <set>
#include <memory>
#include <list>
#include <exception>
@@ -34,6 +35,7 @@
#include <php.h>
#include <zend_exceptions.h>
#include <zend_interfaces.h>
+#include <zend_ini.h>
/**
* Macro to convert results to success status
@@ -43,6 +45,7 @@
/**
* Include other files from this library
*/
+#include "../include/ini.h"
#include "../include/exception.h"
#include "../include/streams.h"
#include "../include/type.h"
diff --git a/zend/ini.cpp b/zend/ini.cpp
new file mode 100644
index 0000000..0c04d6a
--- /dev/null
+++ b/zend/ini.cpp
@@ -0,0 +1,57 @@
+/**
+ * Ini.cpp
+ *
+ * Implementation for ....
+ *
+ * @copyright 2013 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+ /**
+ * Filling ini_entries
+ * @param zend_ini_entry *ini_entry, int module_number
+ * @param int module_number
+ */
+ void Ini::fill(zend_ini_entry *ini_entry, int module_number)
+ {
+ ini_entry->module_number = module_number;
+ ini_entry->modifiable = static_cast<int>(this->_place);
+ ini_entry->name = const_cast<char*>(this->_name.c_str());
+ ini_entry->name_length = this->_name.size()+1;
+ ini_entry->on_modify = OnUpdateString;
+ ini_entry->mh_arg1 = nullptr;
+ #ifdef ZTS
+ ini_entry->mh_arg2 = (void *) &phpcpp_globals_id;
+ #else
+ ini_entry->mh_arg2 = (void *) &phpcpp_globals;
+ #endif
+ ini_entry->mh_arg3 = nullptr;
+ ini_entry->value = const_cast<char*>(this->_value.c_str());
+ ini_entry->value_length = this->_value.size();
+ if( this->_orig_empty)
+ {
+ ini_entry->orig_value = nullptr;
+ ini_entry->orig_value_length = 0;
+ }
+ else
+ {
+ ini_entry->orig_value = const_cast<char*>(this->_orig_value.c_str());
+ ini_entry->orig_value_length = this->_orig_value.size();
+ }
+ ini_entry->orig_modifiable = 0;
+ ini_entry->modified = 0;
+ ini_entry->displayer = nullptr;
+ }
+
+
+/**
+ * End of namespace
+ */
+}
+
+
diff --git a/zend/namespace.cpp b/zend/namespace.cpp
index 2b4b62a..8b97c52 100644
--- a/zend/namespace.cpp
+++ b/zend/namespace.cpp
@@ -128,6 +128,21 @@ void Namespace::classes(const std::function<void(const std::string &ns, ClassBas
}
/**
+ * Filling ini entries into external zend_ini_entry array
+ * @param zend_ini_entry*
+ */
+void Namespace::fill_ini(zend_ini_entry *ini_entries, int module_number)
+{
+ // loop through the ini entries
+ unsigned int Ind = 0;
+ for (auto &ini : _ini_entries) ini->fill(&ini_entries[Ind++], module_number);
+
+ // add last empty ini entry (Zend, for some reason, it requires)
+ zend_ini_entry empty_entry { 0, 0, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, 0, nullptr, 0, 0, 0, nullptr };
+ ini_entries[Ind] = empty_entry;
+}
+
+/**
* End namespace
*/
}