summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-14 07:42:37 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-14 07:42:37 -0700
commitb2042dbd58c043ab49e9b0dbb51bf8516fe8cea8 (patch)
tree25c7806d4c9d5fb237c0995b4bd12c4664bf853a /include
parent53272534a76a9d8cbee4ee887e1f360c4a99728b (diff)
Initial attempt to register native C++ class methods directly to PHP
Diffstat (limited to 'include')
-rw-r--r--include/base.h12
-rw-r--r--include/class.h14
-rw-r--r--include/classinfo.h18
-rw-r--r--include/function.h8
-rw-r--r--include/member.h38
-rw-r--r--include/members.h57
-rw-r--r--include/protected.h14
-rw-r--r--include/public.h18
8 files changed, 170 insertions, 9 deletions
diff --git a/include/base.h b/include/base.h
index 797aff6..6acd805 100644
--- a/include/base.h
+++ b/include/base.h
@@ -69,6 +69,18 @@ public:
};
/**
+ * Definition of a method
+ */
+typedef void (Base::*method_callback_0)();
+typedef void (Base::*method_callback_1)(Parameters &);
+typedef void (Base::*method_callback_2)(Environment &);
+typedef void (Base::*method_callback_3)(Environment &, Parameters &);
+typedef Value (Base::*method_callback_4)();
+typedef Value (Base::*method_callback_5)(Parameters &);
+typedef Value (Base::*method_callback_6)(Environment &);
+typedef Value (Base::*method_callback_7)(Environment &, Parameters &);
+
+/**
* End of namespace
*/
}
diff --git a/include/class.h b/include/class.h
index d5d48b4..3746cf3 100644
--- a/include/class.h
+++ b/include/class.h
@@ -81,13 +81,23 @@ public:
iter->declare(entry);
}
}
+
+ /**
+ * Retrieve the functions
+ * @param classname
+ * @return zend_function_entry*
+ */
+ struct _zend_function_entry *methods(const char *classname)
+ {
+ return _members.methods(classname);
+ }
protected:
/**
* The initial arguments
- * @var vector
+ * @var Members
*/
- std::vector<Member> _members;
+ Members _members;
};
diff --git a/include/classinfo.h b/include/classinfo.h
index cbf2c66..276bc63 100644
--- a/include/classinfo.h
+++ b/include/classinfo.h
@@ -63,7 +63,13 @@ public:
*/
virtual void initialize(struct _zend_class_entry *entry) = 0;
-private:
+ /**
+ * Retrieve the methods
+ * @return zend_function_entry[]
+ */
+ virtual struct _zend_function_entry *methods() = 0;
+
+protected:
/**
* The class entry
* @var zend_class_entry
@@ -130,6 +136,16 @@ public:
_type.initialize(entry);
}
+ /**
+ * Retrieve the methods
+ * @return zend_function_entry[]
+ */
+ virtual struct _zend_function_entry *methods()
+ {
+ // ask class object
+ return _type.methods(_name.c_str());
+ }
+
private:
/**
* The class object
diff --git a/include/function.h b/include/function.h
index 89ec3fd..3cb0e2d 100644
--- a/include/function.h
+++ b/include/function.h
@@ -135,18 +135,20 @@ protected:
*/
HiddenPointer<Function> _ptr;
-private:
+protected:
/**
* Fill a function entry
* @param entry Entry to be filled
+ * @param classname Optional class name
*/
- void fill(struct _zend_function_entry *entry) const;
+ void fill(struct _zend_function_entry *entry, const char *classname=NULL) const;
/**
* Fill function info
* @param info Info object to be filled
+ * @param classname Optional class name
*/
- void fill(struct _zend_internal_function_info *info) const;
+ void fill(struct _zend_internal_function_info *info, const char *classname=NULL) const;
/**
* Extension has access to the private members
diff --git a/include/member.h b/include/member.h
index 5043ead..0a7eb29 100644
--- a/include/member.h
+++ b/include/member.h
@@ -99,6 +99,21 @@ public:
* @param value The value to add
*/
Member(const char *name, bool pub, double value);
+
+ /**
+ * Constructor
+ * @param name Name of the method
+ * @param pub Is this a public method (otherwise it is protected)
+ * @param method The method to add
+ */
+ Member(const char *name, bool pub, method_callback_0 method, const std::initializer_list<Argument> &arguments = {});
+ Member(const char *name, bool pub, method_callback_1 method, const std::initializer_list<Argument> &arguments = {});
+ Member(const char *name, bool pub, method_callback_2 method, const std::initializer_list<Argument> &arguments = {});
+ Member(const char *name, bool pub, method_callback_3 method, const std::initializer_list<Argument> &arguments = {});
+ Member(const char *name, bool pub, method_callback_4 method, const std::initializer_list<Argument> &arguments = {});
+ Member(const char *name, bool pub, method_callback_5 method, const std::initializer_list<Argument> &arguments = {});
+ Member(const char *name, bool pub, method_callback_6 method, const std::initializer_list<Argument> &arguments = {});
+ Member(const char *name, bool pub, method_callback_7 method, const std::initializer_list<Argument> &arguments = {});
/**
* Copy constructor
@@ -119,10 +134,31 @@ public:
/**
* Internal method to declare the property
- * @var zend_class_entry
+ * @param zend_class_entry
+ * @internal
*/
void declare(struct _zend_class_entry *entry);
+ /**
+ * Internal method to fill a function entry
+ * @param zend_function_entry
+ * @param classname
+ * @internal
+ */
+ void fill(struct _zend_function_entry *entry, const char *classname);
+
+ /**
+ * Is this a property member
+ * @return bool
+ */
+ bool isProperty();
+
+ /**
+ * Is this a method member
+ * @return bool
+ */
+ bool isMethod();
+
private:
/**
diff --git a/include/members.h b/include/members.h
new file mode 100644
index 0000000..47cbebd
--- /dev/null
+++ b/include/members.h
@@ -0,0 +1,57 @@
+/**
+ * Members.h
+ *
+ * Internal helper class that holds all members of a class
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+
+/**
+ * Namespace
+ */
+namespace Php {
+
+/**
+ * Class definition
+ */
+class Members : public std::vector<Member>
+{
+public:
+ /**
+ * Constructor
+ * @param arguments
+ */
+ Members(const std::initializer_list<Member> &members) : std::vector<Member>(members), _methods(NULL) {}
+
+ /**
+ * Destructor
+ */
+ virtual ~Members();
+
+ /**
+ * Get access to the methods
+ * @param classname
+ * @return Methods
+ */
+ struct _zend_function_entry *methods(const char *classname);
+
+private:
+ /**
+ * Number of methods
+ * @return integer
+ */
+ int methods();
+
+ /**
+ * Array of method structures used internally in the Zend engine
+ * @var zend_function_entry
+ */
+ struct _zend_function_entry *_methods;
+};
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/include/protected.h b/include/protected.h
index a1fdde5..af2c252 100644
--- a/include/protected.h
+++ b/include/protected.h
@@ -32,6 +32,20 @@ public:
Protected(const char *name, const std::string &value) : Member(name, false, value) {}
Protected(const char *name, const char *value, int size=-1) : Member(name, false, value, size) {}
Protected(const char *name, double value) : Member(name, false, value) {}
+
+ /**
+ * Constructor
+ * @param name Name of the property
+ * @param method Method to add
+ */
+ Protected(const char *name, method_callback_0 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
+ Protected(const char *name, method_callback_1 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
+ Protected(const char *name, method_callback_2 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
+ Protected(const char *name, method_callback_3 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
+ Protected(const char *name, method_callback_4 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
+ Protected(const char *name, method_callback_5 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
+ Protected(const char *name, method_callback_6 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
+ Protected(const char *name, method_callback_7 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
/**
* Destructor
diff --git a/include/public.h b/include/public.h
index b37230b..09625fc 100644
--- a/include/public.h
+++ b/include/public.h
@@ -27,12 +27,26 @@ public:
Public(const char *name, std::nullptr_t value) : Member(name, true, value) {}
Public(const char *name, int value) : Member(name, true, value) {}
Public(const char *name, long value) : Member(name, true, value) {}
- Public(const char *name, bool value) : Member(name, true, value) {}
+// Public(const char *name, bool value) : Member(name, true, value) {}
Public(const char *name, char value) : Member(name, true, value) {}
Public(const char *name, const std::string &value) : Member(name, true, value) {}
Public(const char *name, const char *value, int size=-1) : Member(name, true, value, size) {}
Public(const char *name, double value) : Member(name, true, value) {}
-
+
+ /**
+ * Constructor
+ * @param name Name of the property
+ * @param method Method to add
+ */
+ Public(const char *name, method_callback_0 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
+ Public(const char *name, method_callback_1 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
+ Public(const char *name, method_callback_2 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
+ Public(const char *name, method_callback_3 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
+ Public(const char *name, method_callback_4 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
+ Public(const char *name, method_callback_5 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
+ Public(const char *name, method_callback_6 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
+ Public(const char *name, method_callback_7 method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
+
/**
* Destructor
*/