diff options
author | Toon Schoenmakers <toon.schoenmakers@copernica.com> | 2015-09-16 15:29:58 +0200 |
---|---|---|
committer | Toon Schoenmakers <toon.schoenmakers@copernica.com> | 2015-09-16 15:29:58 +0200 |
commit | 537636373c59b3ce33f15311d2bc89ce72d5cc45 (patch) | |
tree | a52ef6932895a0eb7b644d38dafdb2c26790d9c6 /zend/exception_handler.cpp | |
parent | 913cc8ac69ec9cc6705b26575644e887c2dedc30 (diff) |
Added support for setting a std::function as an exception handler
This is so far only tested with php 5.5.9, might not work on versions
below that.
Diffstat (limited to 'zend/exception_handler.cpp')
-rw-r--r-- | zend/exception_handler.cpp | 49 |
1 files changed, 49 insertions, 0 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 + */ +} |