From: Derick Rethans Date: Thu, 30 Jun 2011 12:21:57 +0000 (+0100) Subject: Implemented TWIG_THROW_EXCEPTION. X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=0cc719add3a3dd8183671928a368600ce4a97929;p=web%2Fkonrad%2Ftwig.git Implemented TWIG_THROW_EXCEPTION. --- diff --git a/twig.c b/twig.c index 6c56b1b..c60c0df 100644 --- a/twig.c +++ b/twig.c @@ -334,6 +334,25 @@ char *TWIG_IMPLODE_ARRAY_KEYS(char *joiner, zval *array) return collector.c; } +static void TWIG_THROW_EXCEPTION(char *exception_name, char *message, ...) +{ + char *buffer; + va_list args; + + zend_class_entry **pce; + + if (zend_lookup_class(exception_name, strlen(exception_name), &pce TSRMLS_CC) == FAILURE) + { + return; + } + + va_start(args, message); + vspprintf(&buffer, 0, message, args); + va_end(args); + + zend_throw_exception_ex(*pce, 0 TSRMLS_CC, buffer); +} + static void twig_add_method_to_class(zend_function *mptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { zval *retval = va_arg(args, zval*); @@ -474,10 +493,11 @@ PHP_FUNCTION(twig_template_get_attributes) } */ if (Z_TYPE_P(object) == IS_OBJECT) { - TWIG_THROW_EXCEPTION("Twig_Error_Runtime", "Key \"%s\" in object (with ArrayAccess) of type \"%s\" does not exist", item, TWIG_GET_CLASS(object)); + TWIG_THROW_EXCEPTION("Twig_Error_Runtime", "Key \"%s\" in object (with ArrayAccess) of type \"%s\" does not exist", Z_STRVAL_P(item), TWIG_GET_CLASS(object)); } else { - TWIG_THROW_EXCEPTION("Twig_Error_Runtime", "Key \"%s\" for array with keys \"%s\" does not exist", item, TWIG_IMPLODE_ARRAY_KEYS(", ", object)); + TWIG_THROW_EXCEPTION("Twig_Error_Runtime", "Key \"%s\" for array with keys \"%s\" does not exist", Z_STRVAL_P(item), TWIG_IMPLODE_ARRAY_KEYS(", ", object)); } + return; } }