summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-12 15:45:19 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-12 15:45:19 +0100
commit21edee4d584dbf757b006349e903ff7a3b398a1d (patch)
tree2532ec92649726a2ff59ba440c4090e80c679d9d /include
parent4415b472ae57e367e1fcece4c04355b55a868a1b (diff)
support for static methods
Diffstat (limited to 'include')
-rw-r--r--include/class.h28
-rw-r--r--include/classbase.h43
-rw-r--r--include/namespace.h18
3 files changed, 65 insertions, 24 deletions
diff --git a/include/class.h b/include/class.h
index 427aa64..d1afab2 100644
--- a/include/class.h
+++ b/include/class.h
@@ -73,7 +73,7 @@ public:
virtual ~Class() {}
/**
- * Add a method to the class
+ * Add a regular method to the class
*
* The method will be accessible as one of the class methods in your PHP
* code. When the method is called, it will automatically be forwarded
@@ -105,6 +105,30 @@ public:
void method(const char *name, Value (T::*method)(Parameters &params) const, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_7>(method), Public, args); }
/**
+ * Add a static method to a class
+ *
+ * In C++ a static method is just a plain function, that only at compile
+ * time has access to the private variables. You can therefore also supply
+ * global functions as static method, and real static methods (that do not
+ * even have to come from the same class.
+ *
+ * In PHP scripts, the function will only be callable as real static method
+ *
+ * @param name Name of the method
+ * @param method The actual method
+ * @param flags Optional flags
+ * @param args Argument descriptions
+ */
+ void method(const char *name, const native_callback_0 &function, int flags, const Arguments &args = {}) { ClassBase::method(name, function, flags, args); }
+ void method(const char *name, const native_callback_1 &function, int flags, const Arguments &args = {}) { ClassBase::method(name, function, flags, args); }
+ void method(const char *name, const native_callback_2 &function, int flags, const Arguments &args = {}) { ClassBase::method(name, function, flags, args); }
+ void method(const char *name, const native_callback_3 &function, int flags, const Arguments &args = {}) { ClassBase::method(name, function, flags, args); }
+ void method(const char *name, const native_callback_0 &function, const Arguments &args = {}) { ClassBase::method(name, function, Public, args); }
+ void method(const char *name, const native_callback_1 &function, const Arguments &args = {}) { ClassBase::method(name, function, Public, args); }
+ void method(const char *name, const native_callback_2 &function, const Arguments &args = {}) { ClassBase::method(name, function, Public, args); }
+ void method(const char *name, const native_callback_3 &function, const Arguments &args = {}) { ClassBase::method(name, function, Public, args); }
+
+ /**
* Add an abstract method to the class
*
* This is only meaningful for classes that can be extended. Because the
@@ -198,7 +222,7 @@ private:
// compare the two objects
if (*t1 < *t2) return -1;
- if (*t1 > *t2) return 1;
+ if (*t2 < *t1) return 1;
// they must be identical
return 0;
diff --git a/include/classbase.h b/include/classbase.h
index 01f1d55..814feaf 100644
--- a/include/classbase.h
+++ b/include/classbase.h
@@ -28,6 +28,16 @@ union _zend_function;
namespace Php {
/**
+ * A couple of predefined native callback functions that can be registered.
+ * These are functions that optional accept a Request and/or Parameters object,
+ * and that either return void or a Value object.
+ */
+typedef void (*native_callback_0)();
+typedef void (*native_callback_1)(Parameters &);
+typedef Value (*native_callback_2)();
+typedef Value (*native_callback_3)(Parameters &);
+
+/**
* Method signatures
*/
typedef void (Base::*method_callback_0)();
@@ -151,14 +161,31 @@ protected:
* @param flags Optional flags
* @param args Description of the supported arguments
*/
- void method(const char *name, method_callback_0, int flags=0, const Arguments &args = {});
- void method(const char *name, method_callback_1, int flags=0, const Arguments &args = {});
- void method(const char *name, method_callback_2, int flags=0, const Arguments &args = {});
- void method(const char *name, method_callback_3, int flags=0, const Arguments &args = {});
- void method(const char *name, method_callback_4, int flags=0, const Arguments &args = {});
- void method(const char *name, method_callback_5, int flags=0, const Arguments &args = {});
- void method(const char *name, method_callback_6, int flags=0, const Arguments &args = {});
- void method(const char *name, method_callback_7, int flags=0, const Arguments &args = {});
+ void method(const char *name, const method_callback_0 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const method_callback_1 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const method_callback_2 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const method_callback_3 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const method_callback_4 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const method_callback_5 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const method_callback_6 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const method_callback_7 &method, int flags=0, const Arguments &args = {});
+
+ /**
+ * Add a static method to the class
+ *
+ * Because a C++ static method is just a regular function, that happens to
+ * have access to the private variables of the class at compile time, you
+ * can register any function that matches one of the function signatures
+ *
+ * @param name Name of the method
+ * @param method The actual method
+ * @param flags Optional flags
+ * @param args Description of the supported arguments
+ */
+ void method(const char *name, const native_callback_0 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const native_callback_1 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const native_callback_2 &method, int flags=0, const Arguments &args = {});
+ void method(const char *name, const native_callback_3 &method, int flags=0, const Arguments &args = {});
/**
* Add an abstract method to the class
diff --git a/include/namespace.h b/include/namespace.h
index 4cbf43e..9d6e6f2 100644
--- a/include/namespace.h
+++ b/include/namespace.h
@@ -14,16 +14,6 @@
namespace Php {
/**
- * A couple of predefined native callback functions that can be registered.
- * These are functions that optional accept a Request and/or Parameters object,
- * and that either return void or a Value object.
- */
-typedef void (*native_callback_0)();
-typedef void (*native_callback_1)(Parameters &);
-typedef Value (*native_callback_2)();
-typedef Value (*native_callback_3)(Parameters &);
-
-/**
* Forward declaration
*/
class Function;
@@ -71,10 +61,10 @@ public:
* @param function The function to add
* @param arguments Optional argument specification
*/
- void add(const char *name, native_callback_0 function, const Arguments &arguments = {});
- void add(const char *name, native_callback_1 function, const Arguments &arguments = {});
- void add(const char *name, native_callback_2 function, const Arguments &arguments = {});
- void add(const char *name, native_callback_3 function, const Arguments &arguments = {});
+ void add(const char *name, const native_callback_0 &function, const Arguments &arguments = {});
+ void add(const char *name, const native_callback_1 &function, const Arguments &arguments = {});
+ void add(const char *name, const native_callback_2 &function, const Arguments &arguments = {});
+ void add(const char *name, const native_callback_3 &function, const Arguments &arguments = {});
/**
* Add a native class to the extension by moving it