blob: 51874a41233bfe38caf24d279fd3b41dec4bc868 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
*/
}
|