diff options
Diffstat (limited to 'zend')
-rw-r--r-- | zend/exception_handler.cpp | 49 | ||||
-rw-r--r-- | zend/functor.h | 8 |
2 files changed, 53 insertions, 4 deletions
diff --git a/zend/exception_handler.cpp b/zend/exception_handler.cpp new file mode 100644 index 0000000..51874a4 --- /dev/null +++ b/zend/exception_handler.cpp @@ -0,0 +1,49 @@ +/** + * Exception_handler.cpp + * + * Set the exception handler + * + * @author Toon Schoenmakers <toon.schoenmakers@copernica.com> + */ + +/** + * Dependencies + */ +#include "includes.h" + +/** + * Open the PHP namespace + */ +namespace Php { + +/** + * Set a std::function as a php exception handler + */ +Value set_exception_handler(const std::function<Value(Parameters ¶ms)> &handler) +{ + // create a functor which wraps our callback + Function functor(handler); + + // initialize our output value + Value output; + + // turn our user_exception_handler into a Value so we can return the original one later on + if (EG(user_exception_handler)) output = EG(user_exception_handler); + + // detach so we have the zval + auto value = functor.detach(true); + + // allocate the user_exception_handler + ALLOC_ZVAL(EG(user_exception_handler)); + + // copy our zval into the user_exception_handler + MAKE_COPY_ZVAL(&value, EG(user_exception_handler)); + + // return the original handler + return output; +} + +/** + * End of namespace + */ +} diff --git a/zend/functor.h b/zend/functor.h index 503a05c..5458027 100644 --- a/zend/functor.h +++ b/zend/functor.h @@ -29,12 +29,12 @@ public: * @param function The function to wrap */ Functor(const std::function<Value(Parameters ¶ms)> &function) : _function(function) {} - + /** * Destructor */ virtual ~Functor() {} - + /** * Invoke the functor * @param params @@ -61,7 +61,7 @@ public: * @param tsrmls */ static void initialize(TSRMLS_D); - + /** * Shutdown the class * @param tsrmls @@ -80,7 +80,7 @@ private: * @var zend_class_entry */ static zend_class_entry *_entry; - + }; /** |