summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasperVanEck <jaspergkurtz@gmail.com>2013-12-02 11:24:39 +0100
committerJasperVanEck <jaspergkurtz@gmail.com>2013-12-02 11:24:39 +0100
commitafa7694bcdb14e7a1d4b1acaf63a8f8eac2b9c05 (patch)
tree8f154746d5da09161b0c23e07ae69491ff457572
parentf4d0f6e5d97cca40ec62446bd038f78428e76adc (diff)
Implemented operator(), with support of upto 10 parameters
-rw-r--r--include/value.h30
-rwxr-xr-xsrc/libphpcpp.sobin132689 -> 137206 bytes
-rw-r--r--src/value.cpp124
3 files changed, 154 insertions, 0 deletions
diff --git a/include/value.h b/include/value.h
index bb7f354..6ea866d 100644
--- a/include/value.h
+++ b/include/value.h
@@ -38,6 +38,15 @@ template <class Type> class HashMember;
*/
class Value
{
+private:
+ /**
+ * Call function with a number of parameters
+ * @param argc Number of parameters
+ * @param argv The parameters
+ * @return Value
+ */
+ Value exec(int argc, zval ***params);
+
public:
/**
* Empty constructor (value = NULL)
@@ -290,6 +299,7 @@ public:
bool isFloat() const { return type() == floatType; }
bool isObject() const { return type() == objectType; }
bool isArray() const { return type() == arrayType; }
+ bool isCallable() const { return type() == callableType; }
/**
* Retrieve the value as number
@@ -527,6 +537,26 @@ public:
*/
HashMember<std::string> operator[](const char *key);
+ /**
+ * Call the function in PHP
+ * We have ten variants of this function, depending on the number of parameters
+ * This call operator is only useful when the variable represents a callable
+ * @param name Name of the function
+ * @return Value
+ */
+ Value operator()();
+ Value operator()(Value p0);
+ Value operator()(Value p0, Value p1);
+ Value operator()(Value p0, Value p1, Value p2);
+ Value operator()(Value p0, Value p1, Value p2, Value p3);
+ Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4);
+ Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5);
+ Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6);
+ Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7);
+ Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8);
+ Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9);
+
+
protected:
/**
* The wrapped zval
diff --git a/src/libphpcpp.so b/src/libphpcpp.so
index 2b81ba7..baef04f 100755
--- a/src/libphpcpp.so
+++ b/src/libphpcpp.so
Binary files differ
diff --git a/src/value.cpp b/src/value.cpp
index ded6c4a..9d382f1 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -660,6 +660,130 @@ Value Value::operator%(const char *value) { return Value(numericValue(
Value Value::operator%(double value) { return Value(numericValue() % (int)value); }
/**
+ * Call the function in PHP
+ * We have ten variants of this function, depending on the number of parameters
+ * This call operator is only useful when the variable represents a callable
+ * @param p0-p10 Parameters of the function to be called.
+ * @return Value
+ */
+Value Value::operator()()
+{
+ // call with zero parameters
+ return exec(0, NULL);
+}
+
+Value Value::operator()(Value p0)
+{
+ // array of parameters
+ zval **params[1] = { &p0._val };
+
+ // call the function
+ return exec(1, params);
+}
+
+Value Value::operator()(Value p0, Value p1)
+{
+ // array of parameters
+ zval **params[2] = { &p0._val, &p1._val };
+
+ // call the function
+ return exec(2, params);
+}
+
+Value Value::operator()(Value p0, Value p1, Value p2)
+{
+ // array of parameters
+ zval **params[3] = { &p0._val, &p1._val, &p2._val };
+
+ // call the function
+ return exec(3, params);
+}
+
+Value Value::operator()(Value p0, Value p1, Value p2, Value p3)
+{
+ // array of parameters
+ zval **params[4] = { &p0._val, &p1._val, &p2._val, &p3._val };
+
+ // call the function
+ return exec(4, params);
+}
+
+Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4)
+{
+ // array of parameters
+ zval **params[5] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val };
+
+ // call the function
+ return exec(5, params);
+}
+
+Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5)
+{
+ // array of parameters
+ zval **params[6] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val };
+
+ // call the function
+ return exec(6, params);
+}
+
+Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6)
+{
+ // array of parameters
+ zval **params[7] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val };
+
+ // call the function
+ return exec(7, params);
+}
+
+Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7)
+{
+ // array of parameters
+ zval **params[8] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val };
+
+ // call the function
+ return exec(8, params);
+}
+
+Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8)
+{
+ // array of parameters
+ zval **params[9] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val };
+
+ // call the function
+ return exec(9, params);
+}
+
+Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9)
+{
+ // array of parameters
+ zval **params[10] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val, &p9._val};
+
+ // call the function
+ return exec(10, params);
+}
+
+/**
+ * Call function with a number of parameters
+ * @param argc Number of parameters
+ * @param argv The parameters
+ * @return Value
+ */
+Value Value::exec(int argc, zval ***params)
+{
+ // the return zval
+ zval *retval = nullptr;
+
+ // call the function
+ if (call_user_function_ex(CG(function_table), NULL, _val, &retval, argc, params, 1, NULL) != SUCCESS) return nullptr;
+
+ // was a value returned?
+ if (retval) return Value(retval);
+
+ // no value was returned, return NULL
+ return nullptr;
+}
+
+/**
* The type of object
* @return Type
*/