summaryrefslogtreecommitdiff
path: root/src
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 /src
parent4415b472ae57e367e1fcece4c04355b55a868a1b (diff)
support for static methods
Diffstat (limited to 'src')
-rw-r--r--src/classbase.cpp70
-rw-r--r--src/function.h8
-rw-r--r--src/method.h46
-rw-r--r--src/namespace.cpp8
-rw-r--r--src/parameters.cpp5
5 files changed, 104 insertions, 33 deletions
diff --git a/src/classbase.cpp b/src/classbase.cpp
index f7d8d94..03c5512 100644
--- a/src/classbase.cpp
+++ b/src/classbase.cpp
@@ -1133,7 +1133,7 @@ void ClassBase::initialize(const std::string &prefix)
* @param flags Optional flags
* @param args Description of the supported arguments
*/
-void ClassBase::method(const char *name, method_callback_0 callback, int flags, const Arguments &args)
+void ClassBase::method(const char *name, const method_callback_0 &callback, int flags, const Arguments &args)
{
// add the method
_methods.push_back(std::make_shared<Method>(name, callback, flags, args));
@@ -1146,7 +1146,7 @@ void ClassBase::method(const char *name, method_callback_0 callback, int flags,
* @param flags Optional flags
* @param args Description of the supported arguments
*/
-void ClassBase::method(const char *name, method_callback_1 callback, int flags, const Arguments &args)
+void ClassBase::method(const char *name, const method_callback_1 &callback, int flags, const Arguments &args)
{
// add the method
_methods.push_back(std::make_shared<Method>(name, callback, flags, args));
@@ -1159,7 +1159,7 @@ void ClassBase::method(const char *name, method_callback_1 callback, int flags,
* @param flags Optional flags
* @param args Description of the supported arguments
*/
-void ClassBase::method(const char *name, method_callback_2 callback, int flags, const Arguments &args)
+void ClassBase::method(const char *name, const method_callback_2 &callback, int flags, const Arguments &args)
{
// add the method
_methods.push_back(std::make_shared<Method>(name, callback, flags, args));
@@ -1172,7 +1172,7 @@ void ClassBase::method(const char *name, method_callback_2 callback, int flags,
* @param flags Optional flags
* @param args Description of the supported arguments
*/
-void ClassBase::method(const char *name, method_callback_3 callback, int flags, const Arguments &args)
+void ClassBase::method(const char *name, const method_callback_3 &callback, int flags, const Arguments &args)
{
// add the method
_methods.push_back(std::make_shared<Method>(name, callback, flags, args));
@@ -1185,7 +1185,7 @@ void ClassBase::method(const char *name, method_callback_3 callback, int flags,
* @param flags Optional flags
* @param args Description of the supported arguments
*/
-void ClassBase::method(const char *name, method_callback_4 callback, int flags, const Arguments &args)
+void ClassBase::method(const char *name, const method_callback_4 &callback, int flags, const Arguments &args)
{
// add the method
_methods.push_back(std::make_shared<Method>(name, callback, flags, args));
@@ -1198,7 +1198,7 @@ void ClassBase::method(const char *name, method_callback_4 callback, int flags,
* @param flags Optional flags
* @param args Description of the supported arguments
*/
-void ClassBase::method(const char *name, method_callback_5 callback, int flags, const Arguments &args)
+void ClassBase::method(const char *name, const method_callback_5 &callback, int flags, const Arguments &args)
{
// add the method
_methods.push_back(std::make_shared<Method>(name, callback, flags, args));
@@ -1211,7 +1211,7 @@ void ClassBase::method(const char *name, method_callback_5 callback, int flags,
* @param flags Optional flags
* @param args Description of the supported arguments
*/
-void ClassBase::method(const char *name, method_callback_6 callback, int flags, const Arguments &args)
+void ClassBase::method(const char *name, const method_callback_6 &callback, int flags, const Arguments &args)
{
// add the method
_methods.push_back(std::make_shared<Method>(name, callback, flags, args));
@@ -1224,13 +1224,65 @@ void ClassBase::method(const char *name, method_callback_6 callback, int flags,
* @param flags Optional flags
* @param args Description of the supported arguments
*/
-void ClassBase::method(const char *name, method_callback_7 callback, int flags, const Arguments &args)
+void ClassBase::method(const char *name, const method_callback_7 &callback, int flags, const Arguments &args)
{
// add the method
_methods.push_back(std::make_shared<Method>(name, callback, flags, args));
}
/**
+ * Add a static method to the class
+ * @param name Name of the method
+ * @param method The actual method
+ * @param flags Optional flags
+ * @param args Description of the supported arguments
+ */
+void ClassBase::method(const char *name, const native_callback_0 &method, int flags, const Arguments &args)
+{
+ // add the method
+ _methods.push_back(std::make_shared<Method>(name, method, flags | ZEND_ACC_STATIC, args));
+}
+
+/**
+ * Add a static method to the class
+ * @param name Name of the method
+ * @param method The actual method
+ * @param flags Optional flags
+ * @param args Description of the supported arguments
+ */
+void ClassBase::method(const char *name, const native_callback_1 &method, int flags, const Arguments &args)
+{
+ // add the method
+ _methods.push_back(std::make_shared<Method>(name, method, flags | ZEND_ACC_STATIC, args));
+}
+
+/**
+ * Add a static method to the class
+ * @param name Name of the method
+ * @param method The actual method
+ * @param flags Optional flags
+ * @param args Description of the supported arguments
+ */
+void ClassBase::method(const char *name, const native_callback_2 &method, int flags, const Arguments &args)
+{
+ // add the method
+ _methods.push_back(std::make_shared<Method>(name, method, flags | ZEND_ACC_STATIC, args));
+}
+
+/**
+ * Add a static method to the class
+ * @param name Name of the method
+ * @param method The actual method
+ * @param flags Optional flags
+ * @param args Description of the supported arguments
+ */
+void ClassBase::method(const char *name, const native_callback_3 &method, int flags, const Arguments &args)
+{
+ // add the method
+ _methods.push_back(std::make_shared<Method>(name, method, flags | ZEND_ACC_STATIC, args));
+}
+
+/**
* Add an abstract method to the class
* @param name Name of the method
* @param flags Optional flags (like public or protected)
@@ -1242,6 +1294,8 @@ void ClassBase::method(const char *name, int flags, const Arguments &args)
_methods.push_back(std::make_shared<Method>(name, Abstract | flags, args));
}
+
+
/**
* Add a property to the class
* @param name Name of the property
diff --git a/src/function.h b/src/function.h
index eabc2e2..fd60944 100644
--- a/src/function.h
+++ b/src/function.h
@@ -24,10 +24,10 @@ public:
* @param name Function name
* @param function The native C function
*/
- Function(const char *name, native_callback_0 function, const Arguments &arguments = {}) : Callable(name, arguments), _type(0) { _function.f0 = function; }
- Function(const char *name, native_callback_1 function, const Arguments &arguments = {}) : Callable(name, arguments), _type(1) { _function.f1 = function; }
- Function(const char *name, native_callback_2 function, const Arguments &arguments = {}) : Callable(name, arguments), _type(2) { _function.f2 = function; }
- Function(const char *name, native_callback_3 function, const Arguments &arguments = {}) : Callable(name, arguments), _type(3) { _function.f3 = function; }
+ Function(const char *name, const native_callback_0 &function, const Arguments &arguments = {}) : Callable(name, arguments), _type(0) { _function.f0 = function; }
+ Function(const char *name, const native_callback_1 &function, const Arguments &arguments = {}) : Callable(name, arguments), _type(1) { _function.f1 = function; }
+ Function(const char *name, const native_callback_2 &function, const Arguments &arguments = {}) : Callable(name, arguments), _type(2) { _function.f2 = function; }
+ Function(const char *name, const native_callback_3 &function, const Arguments &arguments = {}) : Callable(name, arguments), _type(3) { _function.f3 = function; }
/**
* Copy constructor
diff --git a/src/method.h b/src/method.h
index f305d42..dd18a9a 100644
--- a/src/method.h
+++ b/src/method.h
@@ -27,15 +27,19 @@ public:
* @param flags Access flags
* @param args Argument description
*/
- Method(const char *name, method_callback_0 callback, int flags, const Arguments &args) : Callable(name, args), _type(0), _flags(flags) { _callback.m0 = callback; }
- Method(const char *name, method_callback_1 callback, int flags, const Arguments &args) : Callable(name, args), _type(1), _flags(flags) { _callback.m1 = callback; }
- Method(const char *name, method_callback_2 callback, int flags, const Arguments &args) : Callable(name, args), _type(2), _flags(flags) { _callback.m2 = callback; }
- Method(const char *name, method_callback_3 callback, int flags, const Arguments &args) : Callable(name, args), _type(3), _flags(flags) { _callback.m3 = callback; }
- Method(const char *name, method_callback_4 callback, int flags, const Arguments &args) : Callable(name, args), _type(4), _flags(flags) { _callback.m4 = callback; }
- Method(const char *name, method_callback_5 callback, int flags, const Arguments &args) : Callable(name, args), _type(5), _flags(flags) { _callback.m5 = callback; }
- Method(const char *name, method_callback_6 callback, int flags, const Arguments &args) : Callable(name, args), _type(6), _flags(flags) { _callback.m6 = callback; }
- Method(const char *name, method_callback_7 callback, int flags, const Arguments &args) : Callable(name, args), _type(7), _flags(flags) { _callback.m7 = callback; }
- Method(const char *name, int flags, const Arguments &args) : Callable(name, args), _type(9999), _flags(flags) { _callback.m0 = nullptr; }
+ Method(const char *name, const method_callback_0 &callback, int flags, const Arguments &args) : Callable(name, args), _type(0), _flags(flags) { _callback.m0 = callback; }
+ Method(const char *name, const method_callback_1 &callback, int flags, const Arguments &args) : Callable(name, args), _type(1), _flags(flags) { _callback.m1 = callback; }
+ Method(const char *name, const method_callback_2 &callback, int flags, const Arguments &args) : Callable(name, args), _type(2), _flags(flags) { _callback.m2 = callback; }
+ Method(const char *name, const method_callback_3 &callback, int flags, const Arguments &args) : Callable(name, args), _type(3), _flags(flags) { _callback.m3 = callback; }
+ Method(const char *name, const method_callback_4 &callback, int flags, const Arguments &args) : Callable(name, args), _type(4), _flags(flags) { _callback.m4 = callback; }
+ Method(const char *name, const method_callback_5 &callback, int flags, const Arguments &args) : Callable(name, args), _type(5), _flags(flags) { _callback.m5 = callback; }
+ Method(const char *name, const method_callback_6 &callback, int flags, const Arguments &args) : Callable(name, args), _type(6), _flags(flags) { _callback.m6 = callback; }
+ Method(const char *name, const method_callback_7 &callback, int flags, const Arguments &args) : Callable(name, args), _type(7), _flags(flags) { _callback.m7 = callback; }
+ Method(const char *name, const native_callback_0 &callback, int flags, const Arguments &args) : Callable(name, args), _type(8), _flags(flags) { _callback.m8 = callback; }
+ Method(const char *name, const native_callback_1 &callback, int flags, const Arguments &args) : Callable(name, args), _type(9), _flags(flags) { _callback.m9 = callback; }
+ Method(const char *name, const native_callback_2 &callback, int flags, const Arguments &args) : Callable(name, args), _type(10), _flags(flags) { _callback.m10 = callback; }
+ Method(const char *name, const native_callback_3 &callback, int flags, const Arguments &args) : Callable(name, args), _type(11), _flags(flags) { _callback.m11 = callback; }
+ Method(const char *name, int flags, const Arguments &args) : Callable(name, args), _type(9999), _flags(flags) { _callback.m0 = nullptr; }
/**
* Copy and move constructors
@@ -86,6 +90,10 @@ public:
case 5: (base->*_callback.m5)(parameters); return Value();
case 6: return (base->*_callback.m6)();
case 7: return (base->*_callback.m7)(parameters);
+ case 8: _callback.m8(); return Value();
+ case 9: _callback.m9(parameters); return Value();
+ case 10: return _callback.m10();
+ case 11: return _callback.m11(parameters);
default: return Value();
}
}
@@ -109,14 +117,18 @@ private:
* @var void*
*/
union {
- method_callback_0 m0;
- method_callback_1 m1;
- method_callback_2 m2;
- method_callback_3 m3;
- method_callback_4 m4;
- method_callback_5 m5;
- method_callback_6 m6;
- method_callback_7 m7;
+ method_callback_0 m0;
+ method_callback_1 m1;
+ method_callback_2 m2;
+ method_callback_3 m3;
+ method_callback_4 m4;
+ method_callback_5 m5;
+ method_callback_6 m6;
+ method_callback_7 m7;
+ native_callback_0 m8;
+ native_callback_1 m9;
+ native_callback_2 m10;
+ native_callback_3 m11;
} _callback;
};
diff --git a/src/namespace.cpp b/src/namespace.cpp
index 5efaf45..8dda791 100644
--- a/src/namespace.cpp
+++ b/src/namespace.cpp
@@ -19,7 +19,7 @@ namespace Php {
* @param function The function to add
* @param arguments Optional argument specification
*/
-void Namespace::add(const char *name, native_callback_0 function, const Arguments &arguments)
+void Namespace::add(const char *name, const native_callback_0 &function, const Arguments &arguments)
{
// add a function
_functions.push_back(std::make_shared<Function>(name, function, arguments));
@@ -31,7 +31,7 @@ void Namespace::add(const char *name, native_callback_0 function, const Argument
* @param function The function to add
* @param arguments Optional argument specification
*/
-void Namespace::add(const char *name, native_callback_1 function, const Arguments &arguments)
+void Namespace::add(const char *name, const native_callback_1 &function, const Arguments &arguments)
{
// add a function
_functions.push_back(std::make_shared<Function>(name, function, arguments));
@@ -43,7 +43,7 @@ void Namespace::add(const char *name, native_callback_1 function, const Argument
* @param function The function to add
* @param arguments Optional argument specification
*/
-void Namespace::add(const char *name, native_callback_2 function, const Arguments &arguments)
+void Namespace::add(const char *name, const native_callback_2 &function, const Arguments &arguments)
{
// add a function
_functions.push_back(std::make_shared<Function>(name, function, arguments));
@@ -55,7 +55,7 @@ void Namespace::add(const char *name, native_callback_2 function, const Argument
* @param function The function to add
* @param arguments Optional argument specification
*/
-void Namespace::add(const char *name, native_callback_3 function, const Arguments &arguments)
+void Namespace::add(const char *name, const native_callback_3 &function, const Arguments &arguments)
{
// add a function
_functions.push_back(std::make_shared<Function>(name, function, arguments));
diff --git a/src/parameters.cpp b/src/parameters.cpp
index 2fb2eef..b923bd5 100644
--- a/src/parameters.cpp
+++ b/src/parameters.cpp
@@ -39,6 +39,11 @@ Parameters::Parameters(zval *this_ptr, int argc TSRMLS_DC) : _this(this_ptr)
*/
Base *Parameters::object()
{
+ // do we have a this pointer in the first place? The member is not set
+ // when static methods are being called, or when a regular function is
+ // called in a static context
+ if (!_this) return nullptr;
+
// get the mixed object
MixedObject *obj = (MixedObject *)zend_object_store_get_object(_this TSRMLS_CC);