summaryrefslogtreecommitdiff
path: root/zend
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-17 22:19:08 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-17 22:19:08 +0100
commit5fd8b29a1981d2d4f7c4e9925729fbe9f1c558bb (patch)
treee0738b3ebb653d1a7ae8a8c1f62f309f1895bfe5 /zend
parent821e65d876cc0ce2b32471791b02d9f7cc784c99 (diff)
added initial implementation for registering constants
Diffstat (limited to 'zend')
-rw-r--r--zend/constant.cpp28
-rw-r--r--zend/constantimpl.h81
-rw-r--r--zend/extensionimpl.cpp14
-rw-r--r--zend/extensionimpl.h3
-rw-r--r--zend/includes.h2
5 files changed, 124 insertions, 4 deletions
diff --git a/zend/constant.cpp b/zend/constant.cpp
new file mode 100644
index 0000000..a5358c6
--- /dev/null
+++ b/zend/constant.cpp
@@ -0,0 +1,28 @@
+/**
+ * Constant.cpp
+ *
+ * Implementation file for the constant class
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2015 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Constructor
+ * @param name Constant name
+ * @param value Constant value
+ */
+Constant::Constant(const char *name, const Value &value) :
+ _impl(new ConstantImpl(name, value)) {}
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/zend/constantimpl.h b/zend/constantimpl.h
new file mode 100644
index 0000000..0545253
--- /dev/null
+++ b/zend/constantimpl.h
@@ -0,0 +1,81 @@
+/**
+ * ConstantImpl.h
+ *
+ * Implementation file for the constant class
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2015 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Class definition
+ */
+class ConstantImpl
+{
+public:
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ */
+ ConstantImpl(const char *name, const Value &value) :
+ _name(name), _value(value) {}
+
+ /**
+ * Destructor
+ */
+ virtual ~ConstantImpl() {}
+
+ /**
+ * Initialize the constant
+ * @param prefix Namespace prefix
+ * @param module_number The module number
+ * @param tsrmls Optional parameter when running in multi-threading context
+ */
+ void initialize(const std::string &prefix, int module_number TSRMLS_DC) const
+ {
+ // create constant structure
+ zend_constant constant;
+
+ // copy zval
+ INIT_PZVAL_COPY(&constant.value, _value._val);
+
+ // we have to call the copy constructor to copy the entire other zval
+ zval_copy_ctor(&constant.value);
+
+ // @todo include prefix
+
+ // set all the other constant properties
+ constant.flags = CONST_CS | CONST_PERSISTENT;
+ constant.name_len = ::strlen(_name);
+ constant.name = zend_strndup(_name, constant.name_len);
+ constant.module_number = module_number;
+
+ // register the zval
+ zend_register_constant(&constant TSRMLS_CC);
+ }
+
+private:
+ /**
+ * The name of the constant
+ * @var const char *
+ */
+ const char *_name;
+
+ /**
+ * The value of the constant
+ * @var Value
+ */
+ Value _value;
+};
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/zend/extensionimpl.cpp b/zend/extensionimpl.cpp
index 262ecdb..7e1f1ce 100644
--- a/zend/extensionimpl.cpp
+++ b/zend/extensionimpl.cpp
@@ -140,7 +140,7 @@ int ExtensionImpl::processStartup(int type, int module_number TSRMLS_DC)
zend_register_ini_entries(entries, module_number TSRMLS_CC);
// initialize the extension
- extension->initialize(TSRMLS_C);
+ extension->initialize(module_number TSRMLS_CC);
// remember that we're initialized (when you use "apache reload" it is
// possible that the processStartup() method is called more than once)
@@ -322,11 +322,19 @@ zend_module_entry *ExtensionImpl::module()
/**
* Initialize the extension after it was started
+ * @param module_number
* @param tsrm_ls
*/
-void ExtensionImpl::initialize(TSRMLS_D)
+void ExtensionImpl::initialize(int module_number TSRMLS_DC)
{
- // we need to register each class, find out all classes
+ // the constants are registered after the module is ready
+ _data->constants([module_number TSRMLS_CC](const std::string &prefix, Constant &c) {
+
+ // forward to implementation class
+ c.implementation()->initialize(prefix, module_number TSRMLS_CC);
+ });
+
+ // we also need to register each class, find out all classes
_data->classes([TSRMLS_C](const std::string &prefix, ClassBase &c) {
// forward to implementation class
diff --git a/zend/extensionimpl.h b/zend/extensionimpl.h
index 0e9a289..a2a3a44 100644
--- a/zend/extensionimpl.h
+++ b/zend/extensionimpl.h
@@ -91,9 +91,10 @@ public:
private:
/**
* Initialize the namespace after it was registered
+ * @param module_number
* @param tsrm_ls
*/
- void initialize(TSRMLS_D);
+ void initialize(int module_number TSRMLS_DC);
/**
* Function that is called when the extension initializes
diff --git a/zend/includes.h b/zend/includes.h
index 83b1086..d013774 100644
--- a/zend/includes.h
+++ b/zend/includes.h
@@ -77,6 +77,7 @@
#include "../include/classbase.h"
#include "../include/interface.h"
#include "../include/class.h"
+#include "../include/constant.h"
#include "../include/namespace.h"
#include "../include/extension.h"
#include "../include/call.h"
@@ -120,6 +121,7 @@
#include "executestate.h"
#include "opcodes.h"
#include "functor.h"
+#include "constantimpl.h"
#ifndef ZVAL_COPY_VALUE
#define ZVAL_COPY_VALUE(z, v) \