|
| 1 | +/* |
| 2 | + +----------------------------------------------------------------------+ |
| 3 | + | This file is part of the pinepain/php-weak PHP extension. | |
| 4 | + | | |
| 5 | + | Copyright (c) 2016 Bogdan Padalko <zaq178miami@gmail.com> | |
| 6 | + | | |
| 7 | + | Licensed under the MIT license: http://opensource.org/licenses/MIT | |
| 8 | + | | |
| 9 | + | For the full copyright and license information, please view the | |
| 10 | + | LICENSE file that was distributed with this source or visit | |
| 11 | + | http://opensource.org/licenses/MIT | |
| 12 | + +----------------------------------------------------------------------+ |
| 13 | +*/ |
| 14 | + |
| 15 | +#include "php_weak_notifier_exception.h" |
| 16 | +#include "php_weak.h" |
| 17 | +#include "zend_exceptions.h" |
| 18 | + |
| 19 | + |
| 20 | +zend_class_entry *php_weak_notifier_exception_class_entry; |
| 21 | +#define this_ce php_weak_notifier_exception_class_entry |
| 22 | + |
| 23 | + |
| 24 | +static zend_object *php_weak_notifier_exception_ctor(zend_class_entry *ce) /* {{{ */ |
| 25 | +{ |
| 26 | + zval obj, thrown; |
| 27 | + zend_object *object; |
| 28 | + |
| 29 | + Z_OBJ(obj) = object = ce->parent->create_object(ce); |
| 30 | + |
| 31 | + array_init_size(&thrown, 0); |
| 32 | + zend_update_property(php_weak_notifier_exception_class_entry, &obj, ZEND_STRL("exceptions"), &thrown); |
| 33 | + |
| 34 | + return object; |
| 35 | +} /* }}} */ |
| 36 | + |
| 37 | + |
| 38 | +void php_weak_create_notifier_exception(zval *exception, const char *message, zval *thrown) /* {{{ */ |
| 39 | +{ |
| 40 | + object_init_ex(exception, this_ce); |
| 41 | + zend_update_property_string(zend_ce_exception, exception, ZEND_STRL("message"), message); |
| 42 | + zend_update_property(php_weak_notifier_exception_class_entry, exception, ZEND_STRL("exceptions"), thrown); |
| 43 | +} /* }}} */ |
| 44 | + |
| 45 | +static PHP_METHOD(NotifierException, __construct) /* {{{ */ |
| 46 | +{ |
| 47 | + zend_string *message = NULL; |
| 48 | + zend_long code = 0; |
| 49 | + |
| 50 | + zval tmp; |
| 51 | + zval *exceptions = NULL; |
| 52 | + zval *previous = NULL; |
| 53 | + |
| 54 | + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SalO!", &message, &exceptions, &code, &previous, zend_ce_throwable) == FAILURE) { |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + if (message) { |
| 59 | + zend_update_property_str(zend_ce_exception, getThis(), ZEND_STRL("message"), message); |
| 60 | + } |
| 61 | + |
| 62 | + if (exceptions) { |
| 63 | + zend_update_property(this_ce, getThis(), ZEND_STRL("exceptions"), exceptions); |
| 64 | + } else { |
| 65 | + array_init_size(&tmp, 0); |
| 66 | + zend_update_property(this_ce, getThis(), ZEND_STRL("exceptions"), &tmp); |
| 67 | + } |
| 68 | + |
| 69 | + if (code) { |
| 70 | + zend_update_property_long(zend_ce_exception, getThis(), ZEND_STRL("code"), code); |
| 71 | + } |
| 72 | + |
| 73 | + if (previous) { |
| 74 | + zend_update_property(zend_ce_exception, getThis(), ZEND_STRL("previous"), previous); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +static PHP_METHOD(NotifierException, getExceptions) /* {{{ */ |
| 79 | +{ |
| 80 | + zval rv; |
| 81 | + |
| 82 | + if (zend_parse_parameters_none() == FAILURE) { |
| 83 | + return; |
| 84 | + } |
| 85 | + |
| 86 | + RETVAL_ZVAL(zend_read_property(php_weak_notifier_exception_class_entry, getThis(), ZEND_STRL("exceptions"), 0, &rv), 1, 0); |
| 87 | +} /* }}} */ |
| 88 | + |
| 89 | + |
| 90 | +ZEND_BEGIN_ARG_INFO_EX(arginfo_notifier_exception___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) |
| 91 | + ZEND_ARG_INFO(0, message) |
| 92 | + ZEND_ARG_INFO(0, exceptions) |
| 93 | + ZEND_ARG_INFO(0, code) |
| 94 | + ZEND_ARG_INFO(0, previous) |
| 95 | +ZEND_END_ARG_INFO() |
| 96 | + |
| 97 | +ZEND_BEGIN_ARG_INFO_EX(arginfo_notifier_exception_getExceptions, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) |
| 98 | +ZEND_END_ARG_INFO() |
| 99 | + |
| 100 | + |
| 101 | +static const zend_function_entry php_weak_notifier_exception_methods[] = { /* {{{ */ |
| 102 | + PHP_ME(NotifierException, __construct, arginfo_notifier_exception___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) |
| 103 | + PHP_ME(NotifierException, getExceptions, arginfo_notifier_exception_getExceptions, ZEND_ACC_PUBLIC) |
| 104 | + |
| 105 | + PHP_FE_END |
| 106 | +}; /* }}} */ |
| 107 | + |
| 108 | + |
| 109 | +PHP_MINIT_FUNCTION (php_weak_notifier_exception) /* {{{ */ |
| 110 | +{ |
| 111 | + zend_class_entry ce; |
| 112 | + |
| 113 | + INIT_NS_CLASS_ENTRY(ce, PHP_WEAK_NS, "NotifierException", php_weak_notifier_exception_methods); |
| 114 | + this_ce = zend_register_internal_class_ex(&ce, zend_ce_exception); |
| 115 | + /*this_ce->create_object = php_weak_notifier_exception_ctor;*/ |
| 116 | + |
| 117 | + zend_declare_property_null(this_ce, ZEND_STRL("exceptions"), ZEND_ACC_PRIVATE); |
| 118 | + |
| 119 | + |
| 120 | + return SUCCESS; |
| 121 | +} /* }}} */ |
| 122 | + |
| 123 | + |
| 124 | +/* |
| 125 | + * Local variables: |
| 126 | + * tab-width: 4 |
| 127 | + * c-basic-offset: 4 |
| 128 | + * End: |
| 129 | + * vim600: noet sw=4 ts=4 fdm=marker |
| 130 | + * vim<600: noet sw=4 ts=4 |
| 131 | + */ |
0 commit comments