diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-25 09:41:17 -0700 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-25 09:41:17 -0700 |
commit | 753402a84b40ff4dc9697dea1d2d4aa037ea7624 (patch) | |
tree | 9ff5e95a534265d01ae732a1e39dd3aaf3127803 /src | |
parent | 49ac629257835426c311fb7b92b23a9138a9d77b (diff) |
Constructor gets almost called when object is constructed
Diffstat (limited to 'src')
-rw-r--r-- | src/classinfo.cpp | 79 | ||||
-rw-r--r-- | src/includes.h | 1 | ||||
-rw-r--r-- | src/internalfunction.h | 80 |
3 files changed, 160 insertions, 0 deletions
diff --git a/src/classinfo.cpp b/src/classinfo.cpp new file mode 100644 index 0000000..760df5c --- /dev/null +++ b/src/classinfo.cpp @@ -0,0 +1,79 @@ +/** + * ClassInfo.cpp + * + * Implementation for the class info + * + * @documentation private + */ +#include "includes.h" + +/** + * Set up namespace + */ +namespace Php { + +/** + * Function that is called by the Zend engine every time that a function gets called + * @param ht + * @param return_value + * @param return_value_ptr + * @param this_ptr + * @param return_value_used + * @param tsrm_ls + * @return integer + */ +void invoke_method(INTERNAL_FUNCTION_PARAMETERS) +{ + std::cout << "invoke method" << std::endl; + + return; + + // find the function name + const char *name = get_active_function_name(TSRMLS_C); + + // uncover the hidden pointer inside the function name + Function *function = HiddenPointer<Function>(name); + + // wrap the return value + Value result(return_value, true); + + // construct parameters + Parameters params(ZEND_NUM_ARGS()); + + // get the result + result = function->invoke(*PHPCPP_G(environment), params); +} + +/** + * Helper struct to create an internal method + */ + + +/** + * Initialize the class + * @param mixed Optional threading ID + */ +void _ClassInfo::initialize(TSRMLS_D) +{ + // the class entry + zend_class_entry entry; + + // initialize the class entry + INIT_CLASS_ENTRY_EX(entry, _name.c_str(), _name.size(), NULL); + + // functions we need + // @todo should not be static + static InternalFunction constructor(invoke_method, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC); + + // we need a special constructor + entry.__call = constructor; + + // register the class + _entry = zend_register_internal_class(&entry TSRMLS_CC); +} + +/** + * End of namespace + */ +} + diff --git a/src/includes.h b/src/includes.h index 8eae5f7..20e7e95 100644 --- a/src/includes.h +++ b/src/includes.h @@ -55,4 +55,5 @@ * Interface files for internal use only */ #include "nativefunction.h" +#include "internalfunction.h" diff --git a/src/internalfunction.h b/src/internalfunction.h new file mode 100644 index 0000000..741ea5b --- /dev/null +++ b/src/internalfunction.h @@ -0,0 +1,80 @@ +/** + * InternalFunction.h + * + * Helper union to create an internal function + * + * @documentation private + */ + +/** + * Namespace + */ +namespace Php { + +/** + * An internal function + */ +class InternalFunction +{ +public: + /** + * Constructor + * @param handler + * @param flags + */ + InternalFunction(void (*handler)(INTERNAL_FUNCTION_PARAMETERS), int flags = 0) + { + // set everything to zero + memset(&_func, 0, sizeof(zend_internal_function)); + + // set the appropriate properties + _func.type = ZEND_INTERNAL_FUNCTION; + _func.handler = handler; + _func.fn_flags = flags; + +// _func.function_name = NULL; +// _func.scope = NULL; +// _func.prototype = NULL; +// _func.num_args = 0; +// _func.required_num_args = 0; +// _func.arg_info = NULL; +// _func.module = NULL; + } + + /** + * Destructor + */ + virtual ~InternalFunction() {} + + /** + * Cast to zend_internal_function pointer + * @return zend_internal_function + */ + operator zend_internal_function *() + { + return &_func; + } + + /** + * Cast to zend_function pointer + * @return zend_function + */ + operator zend_function *() + { + return (zend_function *)&_func; + } + +private: + /** + * The internal function object + * @var zend_internal_function + */ + zend_internal_function _func; +}; + + +/** + * End of namespace + */ +} + |