summaryrefslogtreecommitdiff
path: root/src/namespace.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-01 10:32:26 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-01 10:32:26 +0100
commitc8d1519f31baed0fb399dac9333e48e2f9e910ad (patch)
tree1e2192f0b91d55512d26f4a14c8eae6b5a1f6ece /src/namespace.cpp
parent73945a9cb2b096a5379d17c028bda102b87aedce (diff)
namespace implementation, compile issue for php 5.4 and higher
Diffstat (limited to 'src/namespace.cpp')
-rw-r--r--src/namespace.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/namespace.cpp b/src/namespace.cpp
new file mode 100644
index 0000000..0938a90
--- /dev/null
+++ b/src/namespace.cpp
@@ -0,0 +1,103 @@
+/**
+ * Namespace.cpp
+ *
+ * Implementation of the namespace class
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2014 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Open namespace
+ */
+namespace Php {
+
+/**
+ * Add a native function directly to the extension
+ * @param name Name of the function
+ * @param function The function to add
+ * @param arguments Optional argument specification
+ */
+void Namespace::add(const char *name, native_callback_0 function, const Arguments &arguments)
+{
+ // add a function
+ _functions.push_back(std::make_shared<Function>(name, function, arguments));
+}
+
+/**
+ * Add a native function directly to the extension
+ * @param name Name of the function
+ * @param function The function to add
+ * @param arguments Optional argument specification
+ */
+void Namespace::add(const char *name, native_callback_1 function, const Arguments &arguments)
+{
+ // add a function
+ _functions.push_back(std::make_shared<Function>(name, function, arguments));
+}
+
+/**
+ * Add a native function directly to the extension
+ * @param name Name of the function
+ * @param function The function to add
+ * @param arguments Optional argument specification
+ */
+void Namespace::add(const char *name, native_callback_2 function, const Arguments &arguments)
+{
+ // add a function
+ _functions.push_back(std::make_shared<Function>(name, function, arguments));
+}
+
+/**
+ * Add a native function directly to the extension
+ * @param name Name of the function
+ * @param function The function to add
+ * @param arguments Optional argument specification
+ */
+void Namespace::add(const char *name, native_callback_3 function, const Arguments &arguments)
+{
+ // add a function
+ _functions.push_back(std::make_shared<Function>(name, function, arguments));
+}
+
+/**
+ * Initialize all functions in this namespace
+ * @param parent Namespace prefix of the parent
+ * @param entries The array to be filled
+ * @return int Number of functions that were initialized
+ */
+size_t Namespace::initialize(const std::string &parent, zend_function_entry entries[])
+{
+ // keep iterator counter
+ int count = 0;
+
+ // the namespace to use
+ std::string prefix = parent.size() ? parent + "\\" + _name : _name;
+
+ // loop through the functions
+ for (auto &function : _functions)
+ {
+ // retrieve entry
+ zend_function_entry *entry = &entries[count++];
+
+ // let the function fill the entry
+ function->initialize(prefix, entry);
+ }
+
+ // loop through the namespace
+ for (auto &ns : _namespaces)
+ {
+ // let the namespace initialize
+ count += ns->initialize(prefix, &entries[count]);
+ }
+
+ // done
+ return count;
+}
+
+/**
+ * End namespace
+ */
+}
+