This repository was archived by the owner on Jul 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathphp_ref_notifier_exception.c
More file actions
120 lines (88 loc) · 3.51 KB
/
php_ref_notifier_exception.c
File metadata and controls
120 lines (88 loc) · 3.51 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* This file is part of the pinepain/php-ref PHP extension.
*
* Copyright (c) 2016-2018 Bogdan Padalko <pinepain@gmail.com>
*
* Licensed under the MIT license: http://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the
* LICENSE file that was distributed with this source or visit
* http://opensource.org/licenses/MIT
*/
#include "php_ref_notifier_exception.h"
#include "php_ref.h"
#include "zend_exceptions.h"
zend_class_entry *php_ref_notifier_exception_class_entry;
#define this_ce php_ref_notifier_exception_class_entry
static zend_object *php_ref_notifier_exception_ctor(zend_class_entry *ce)
{
zval obj, thrown;
zend_object *object;
Z_OBJ(obj) = object = ce->parent->create_object(ce);
array_init_size(&thrown, 0);
zend_update_property(php_ref_notifier_exception_class_entry, &obj, ZEND_STRL("exceptions"), &thrown);
return object;
}
void php_ref_create_notifier_exception(zval *exception, const char *message, zval *thrown)
{
object_init_ex(exception, this_ce);
zend_update_property_string(zend_ce_exception, exception, ZEND_STRL("message"), message);
zend_update_property(php_ref_notifier_exception_class_entry, exception, ZEND_STRL("exceptions"), thrown);
}
static PHP_METHOD(NotifierException, __construct)
{
zend_string *message = NULL;
zend_long code = 0;
zval tmp;
zval *exceptions = NULL;
zval *previous = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SalO!", &message, &exceptions, &code, &previous, zend_ce_throwable) == FAILURE) {
return;
}
if (message) {
zend_update_property_str(zend_ce_exception, getThis(), ZEND_STRL("message"), message);
}
if (exceptions) {
zend_update_property(this_ce, getThis(), ZEND_STRL("exceptions"), exceptions);
} else {
array_init_size(&tmp, 0);
zend_update_property(this_ce, getThis(), ZEND_STRL("exceptions"), &tmp);
zval_dtor(&tmp);
}
if (code) {
zend_update_property_long(zend_ce_exception, getThis(), ZEND_STRL("code"), code);
}
if (previous) {
zend_update_property(zend_ce_exception, getThis(), ZEND_STRL("previous"), previous);
}
}
static PHP_METHOD(NotifierException, getExceptions)
{
zval rv;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETVAL_ZVAL(zend_read_property(php_ref_notifier_exception_class_entry, getThis(), ZEND_STRL("exceptions"), 0, &rv), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_notifier_exception___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
ZEND_ARG_INFO(0, message)
ZEND_ARG_INFO(0, exceptions)
ZEND_ARG_INFO(0, code)
ZEND_ARG_INFO(0, previous)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_notifier_exception_getExceptions, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry php_ref_notifier_exception_methods[] = {
PHP_ME(NotifierException, __construct, arginfo_notifier_exception___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(NotifierException, getExceptions, arginfo_notifier_exception_getExceptions, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHP_MINIT_FUNCTION (php_ref_notifier_exception)
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, PHP_REF_NS, "NotifierException", php_ref_notifier_exception_methods);
this_ce = zend_register_internal_class_ex(&ce, zend_ce_exception);
/*this_ce->create_object = php_ref_notifier_exception_ctor;*/
zend_declare_property_null(this_ce, ZEND_STRL("exceptions"), ZEND_ACC_PRIVATE);
return SUCCESS;
}