summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-06 20:07:15 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-06 20:07:15 +0200
commite8b7f9a5f80c0f296d05403a84a5259cb48f9329 (patch)
tree9540b2d1844286526a508baaefabc24ca5d2f9f3
parent436cab2f1646a7fe54d977b7abf49fa3dfd86639 (diff)
refactored parameters class so that no zend engine dependency is necessary in the include files
-rw-r--r--include/parameters.h29
-rw-r--r--include/valueiterator.h6
-rw-r--r--src/callable.cpp2
-rw-r--r--src/classimpl.cpp4
-rw-r--r--src/includes.h1
-rw-r--r--src/parameters.cpp46
-rw-r--r--src/parametersimpl.h53
7 files changed, 73 insertions, 68 deletions
diff --git a/include/parameters.h b/include/parameters.h
index fa53004..b464260 100644
--- a/include/parameters.h
+++ b/include/parameters.h
@@ -22,15 +22,25 @@ class Base;
*/
class Parameters : public std::vector<Value>
{
-public:
+private:
/**
- * Constructor
- * @param this_ptr Optional this_ptr
- * @param argc Number of arguments
- * @param tsrm_ls
+ * The base object
+ * @var Base
*/
- Parameters(struct _zval_struct *this_ptr, int argc TSRMLS_DC);
+ Base *_object = nullptr;
+protected:
+ /**
+ * Protected constructor
+ *
+ * The constructor is protected because extension programmers are not
+ * supposed to instantiate parameters objects themselves
+ *
+ * @param object The 'this' object
+ */
+ Parameters(Base *object) : _object(object) {}
+
+public:
/**
* Destructor
*/
@@ -44,13 +54,6 @@ public:
{
return _object;
}
-
-private:
- /**
- * The base object
- * @var Base
- */
- Base *_object = nullptr;
};
/**
diff --git a/include/valueiterator.h b/include/valueiterator.h
index 8bc9208..95cdac6 100644
--- a/include/valueiterator.h
+++ b/include/valueiterator.h
@@ -12,12 +12,6 @@
*/
/**
- * Forward declaration
- */
-struct _hashtable;
-struct bucket;
-
-/**
* Set up namespace
*/
namespace Php {
diff --git a/src/callable.cpp b/src/callable.cpp
index 5e37df7..d1b94c5 100644
--- a/src/callable.cpp
+++ b/src/callable.cpp
@@ -35,7 +35,7 @@ static void invoke_callable(INTERNAL_FUNCTION_PARAMETERS)
Value result(return_value, true);
// construct parameters
- Parameters params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
+ ParametersImpl params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
// the function could throw an exception
try
diff --git a/src/classimpl.cpp b/src/classimpl.cpp
index 84b43df..8e062d4 100644
--- a/src/classimpl.cpp
+++ b/src/classimpl.cpp
@@ -97,7 +97,7 @@ void ClassImpl::callMethod(INTERNAL_FUNCTION_PARAMETERS)
Value result(return_value, true);
// construct parameters
- Parameters params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
+ ParametersImpl params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
// retrieve the base object
Base *base = params.object();
@@ -143,7 +143,7 @@ void ClassImpl::callInvoke(INTERNAL_FUNCTION_PARAMETERS)
Value result(return_value, true);
// construct parameters
- Parameters params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
+ ParametersImpl params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
// retrieve the base object
Base *base = params.object();
diff --git a/src/includes.h b/src/includes.h
index 6f28362..f547eb2 100644
--- a/src/includes.h
+++ b/src/includes.h
@@ -100,6 +100,7 @@
#include "streambuf.h"
#include "classimpl.h"
#include "objectimpl.h"
+#include "parametersimpl.h"
#include "extensionimpl.h"
#ifndef ZVAL_COPY_VALUE
diff --git a/src/parameters.cpp b/src/parameters.cpp
deleted file mode 100644
index c7b61a0..0000000
--- a/src/parameters.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Parameters.cpp
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- */
-#include "includes.h"
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-/**
- * Parameters
- * @param this_ptr Pointer to the object
- * @param argc Number of arguments
- * @param tsrm_ls
- */
-Parameters::Parameters(zval *this_ptr, int argc TSRMLS_DC)
-{
- // reserve plenty of space
- reserve(argc);
-
- // loop through the arguments
- for (int i=0; i<argc; i++)
- {
- // get the argument
- zval **arg = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (argc-i));
-
- // append value
- push_back(Value(*arg));
- }
-
- // skip if there is no this_ptr
- if (!this_ptr) return;
-
- // store the CPP object
- _object = ObjectImpl::find(this_ptr TSRMLS_CC)->object();
-}
-
-/**
- * End of namespace
- */
-}
-
diff --git a/src/parametersimpl.h b/src/parametersimpl.h
new file mode 100644
index 0000000..fd14238
--- /dev/null
+++ b/src/parametersimpl.h
@@ -0,0 +1,53 @@
+/**
+ * ParametersImpl.h
+ *
+ * Extended parameters class that can be instantiated
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Class definition
+ */
+class ParametersImpl : public Parameters
+{
+public:
+ /**
+ * Constructor
+ * @param this_ptr Pointer to the object
+ * @param argc Number of arguments
+ * @param tsrm_ls
+ */
+ ParametersImpl(zval *this_ptr, int argc TSRMLS_DC) : Parameters(this_ptr ? ObjectImpl::find(this_ptr TSRMLS_CC)->object() : nullptr)
+ {
+ // reserve plenty of space
+ reserve(argc);
+
+ // loop through the arguments
+ for (int i=0; i<argc; i++)
+ {
+ // get the argument
+ zval **arg = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (argc-i));
+
+ // append value
+ push_back(Value(*arg));
+ }
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~ParametersImpl() {}
+};
+
+/**
+ * End of namespace
+ */
+}
+