summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-01 10:51:37 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-01 10:51:37 +0100
commita05b25d54df9d42a8fe4632073538ba47eb710ab (patch)
tree30d8aa3bcf304800ba4c02ef8eaffb695bb10a0f
parentc8d1519f31baed0fb399dac9333e48e2f9e910ad (diff)
fixed various compile issues and namespace implementation
-rw-r--r--Examples/CppClassesInPhp/Makefile2
-rw-r--r--Examples/CppClassesInPhp/cppclassinphp.cpp8
-rw-r--r--include/class.h4
-rw-r--r--include/extension.h8
-rw-r--r--include/namespace.h9
-rw-r--r--phpcpp.h1
-rw-r--r--src/classbase.cpp8
-rw-r--r--src/extension.cpp2
-rw-r--r--src/namespace.cpp2
9 files changed, 25 insertions, 19 deletions
diff --git a/Examples/CppClassesInPhp/Makefile b/Examples/CppClassesInPhp/Makefile
index 872cce3..0260376 100644
--- a/Examples/CppClassesInPhp/Makefile
+++ b/Examples/CppClassesInPhp/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -g -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20090626
+LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/CppClassesInPhp/cppclassinphp.cpp b/Examples/CppClassesInPhp/cppclassinphp.cpp
index 3164866..b13602e 100644
--- a/Examples/CppClassesInPhp/cppclassinphp.cpp
+++ b/Examples/CppClassesInPhp/cppclassinphp.cpp
@@ -63,6 +63,9 @@ extern "C"
// create extension
static Php::Extension extension("Cpp_classes_in_php","1.0");
+ // create a namespace too
+ Php::Namespace ns("MyNamespace");
+
// add custom function
extension.add("myFunction", myFunction, { });
@@ -76,7 +79,10 @@ extern "C"
// add the class to the extension
extension.add(customClass);
-
+
+ // add the namespace to the extension
+ extension.add(ns);
+
// return the extension module
return extension.module();
}
diff --git a/include/class.h b/include/class.h
index 1ac4f00..72615e5 100644
--- a/include/class.h
+++ b/include/class.h
@@ -116,9 +116,9 @@ private:
}
/**
- * Extensions have access to the private base class
+ * Namespaces have access to the private base class
*/
- friend class Extension;
+ friend class Namespace;
};
/**
diff --git a/include/extension.h b/include/extension.h
index 72c7d56..f04dc8c 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -152,14 +152,6 @@ public:
private:
/**
- * Initialize all functions in this namespace
- * @param ns Namespace prefix
- * @param entries The array to be filled
- * @return int Number of functions that were initialized
- */
- size_t initialize(const std::string &ns, zend_function_entry entries[]);
-
- /**
* The information that is passed to the Zend engine
*
* Although it would be slightly faster to not make this a pointer, this
diff --git a/include/namespace.h b/include/namespace.h
index 727f1dd..ef625fc 100644
--- a/include/namespace.h
+++ b/include/namespace.h
@@ -180,7 +180,7 @@ protected:
* @param entries The array to be filled
* @return int Number of functions that were initialized
*/
- size_t initialize(const std::string &ns, zend_function_entry entries[]);
+ size_t initialize(const std::string &ns, struct _zend_function_entry entries[]);
/**
* Initialize the namespace after it was registered
@@ -188,11 +188,14 @@ protected:
*/
void initialize(const std::string &parent)
{
+ // the namespace to use
+ std::string prefix = parent.size() ? parent + "\\" + _name : _name;
+
// loop through the classes in this namespace
- for (auto &c : _classes) c->initialize(parent+"\\"+_name);
+ for (auto &c : _classes) c->initialize(prefix);
// and loop through the other namespaces
- for (auto &n : _namespaces) n->initialize(parent+"\\"+_name);
+ for (auto &n : _namespaces) n->initialize(prefix);
}
};
diff --git a/phpcpp.h b/phpcpp.h
index 497f056..7c15f7e 100644
--- a/phpcpp.h
+++ b/phpcpp.h
@@ -43,6 +43,7 @@
#include <phpcpp/abstractclass.h>
#include <phpcpp/finalclass.h>
#include <phpcpp/interface.h>
+#include <phpcpp/namespace.h>
#include <phpcpp/extension.h>
#include <phpcpp/exception.h>
diff --git a/src/classbase.cpp b/src/classbase.cpp
index b38f6d3..71dd09d 100644
--- a/src/classbase.cpp
+++ b/src/classbase.cpp
@@ -165,9 +165,13 @@ void ClassBase::initialize(const std::string &prefix)
// the class entry
zend_class_entry entry;
+ std::cout << "prefix " << prefix << std::endl;
+
// update the name
if (prefix.size() > 0) _name = prefix + "\\" + _name;
+ std::cout << "init class " << _name << std::endl;
+
// initialize the class entry
INIT_CLASS_ENTRY_EX(entry, _name.c_str(), _name.size(), entries());
@@ -272,7 +276,7 @@ void ClassBase::add(const char *name, std::nullptr_t value, int flags)
// add property
_members.push_back(std::make_shared<NullMember>(name, flags));
}
-
+
/**
* Add a property to the class
* @param name Name of the property
@@ -368,7 +372,7 @@ void ClassBase::add(const char *name, double value, int flags)
// add property
_members.push_back(std::make_shared<FloatMember>(name, value, flags));
}
-
+
/**
* End namespace
*/
diff --git a/src/extension.cpp b/src/extension.cpp
index 20d5627..89ec3b9 100644
--- a/src/extension.cpp
+++ b/src/extension.cpp
@@ -228,7 +228,7 @@ zend_module_entry *Extension::module()
zend_function_entry *entries = new zend_function_entry[functions() + 1];
// initialize the entries
- int count = initialize(_name, entries);
+ int count = Namespace::initialize("", entries);
// last entry should be set to all zeros
zend_function_entry *last = &entries[count];
diff --git a/src/namespace.cpp b/src/namespace.cpp
index 0938a90..5efaf45 100644
--- a/src/namespace.cpp
+++ b/src/namespace.cpp
@@ -67,7 +67,7 @@ void Namespace::add(const char *name, native_callback_3 function, const Argument
* @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[])
+size_t Namespace::initialize(const std::string &parent, struct _zend_function_entry entries[])
{
// keep iterator counter
int count = 0;