From d87b3ca8f1dbcb395f2dfd6540483da7a0e5e15c Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Thu, 15 Jan 2015 16:34:14 +0100 Subject: Added the Php::Function class. This is an extension to the Php::Value class that can be used if you want to assign a std::function object to a Value. This is useful if you want to pass a C++ lambda to a PHP userspace function --- zend/function.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 zend/function.cpp (limited to 'zend/function.cpp') diff --git a/zend/function.cpp b/zend/function.cpp new file mode 100644 index 0000000..789175e --- /dev/null +++ b/zend/function.cpp @@ -0,0 +1,49 @@ +/** + * Function.cpp + * + * Implementation file for the Function class + * + * @author Emiel Bruijntjes + * @copyright 2015 Copernica BV + */ + +/** + * Dependencies + */ +#include "includes.h" + +/** + * Set up namespace + */ +namespace Php { + +/** + * Function returns a pointer to the class-entry of the Functor class + * @return zend_class_entry + */ +zend_class_entry *Function::entry() +{ + // and the actual class entry + static zend_class_entry *entry = nullptr; + + // is the class entry already valid? + if (entry) return entry; + + // construct functor object + static std::unique_ptr functor(new Class("Functor")); + + // initialize the functor class + return entry = functor->implementation()->initialize(functor.get(), "" TSRMLS_CC); +} + +/** + * Constructor + * @param function The function to be wrapped + */ +Function::Function(const std::function &function) : Value(Object(entry(), new Functor(function))) {} + +/** + * End of namespace + */ +} + -- cgit v1.2.3