diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-08 16:26:11 -0700 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-08 16:26:11 -0700 |
commit | df2520e4b2c87e2302ee4c6cec1e672091efebfb (patch) | |
tree | f3bcd4fa7c4d0c6ee601268ceca4d6841ed90d0d /src/function.cpp | |
parent | eb86ac350756afeffa0e2db8be87876d35bc40a8 (diff) |
Refactoring function class, and making it even more easy to directly enable native C functions in PHP
Diffstat (limited to 'src/function.cpp')
-rw-r--r-- | src/function.cpp | 76 |
1 files changed, 67 insertions, 9 deletions
diff --git a/src/function.cpp b/src/function.cpp index cb56d78..8612cf1 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -11,25 +11,83 @@ /** * Set up namespace */ -namespace PhpCpp { +namespace Php { /** - * Constructor + * 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_function(INTERNAL_FUNCTION_PARAMETERS) +{ + // 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 ret(return_value, true); + + // construct parameters + Parameters params(ZEND_NUM_ARGS()); + + // call the appropriate object + ret = function->invoke(params); +} + +/** + * Fill a function entry + * + * This method is called when the extension is registering itself, when the + * function or method introces himself + * * @param name Name of the function - * @param arguments The arguments that can be passed to the function + * @param entry Entry to be filled */ -Function::Function(const std::string &name, const std::initializer_list<Argument> &arguments) +void Function::fill(const char *name, zend_function_entry *entry) { - // create callable object - _callable = new Callable(name, arguments); + // fill the members of the entity, and hide a pointer to the current object in the name + entry->fname = HiddenPointer<Function>(this, name); + entry->handler = invoke_function; + entry->arg_info = _arguments->internal(); + entry->num_args = _arguments->argc(); + + // there are no flags like deprecated, private or protected + entry->flags = 0; + + // we should fill the first argument as well + fill(name, (zend_internal_function_info *)entry->arg_info); } /** - * Destructor + * Fill a function entry + * @param name Name of the function + * @param info Info to be filled */ -Function::~Function() +void Function::fill(const char *name, zend_internal_function_info *info) { - if (_callable) delete _callable; + // fill in all the members, note that return reference is false by default, + // because we do want to return references, inside the name we hide a pointer + // to the current object + info->_name = HiddenPointer<Function>(this, name); + info->_name_len = strlen(name); + info->_class_name = NULL; + + // number of required arguments, and the expected return type + info->required_num_args = _arguments->required(); + info->_type_hint = _type; + + // we do not support return-by-reference + info->return_reference = false; + + // passing by reference is not used + info->pass_rest_by_reference = false; } /** |