From: Derick Rethans Date: Thu, 30 Jun 2011 13:25:45 +0000 (+0100) Subject: Implement TWIG_GET_CLASS_NAME and make use of it. X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=6e1dd5617281e0857d768f180711f4dc6efb920e;p=konrad%2Ftwig.git Implement TWIG_GET_CLASS_NAME and make use of it. --- diff --git a/twig.c b/twig.c index 02dfa2b..96b8e5b 100644 --- a/twig.c +++ b/twig.c @@ -339,6 +339,18 @@ static void TWIG_THROW_EXCEPTION(char *exception_name, char *message, ...) zend_throw_exception_ex(*pce, 0 TSRMLS_CC, buffer); } +char *TWIG_GET_CLASS_NAME(zval *object) +{ + char *class_name; + zend_uint class_name_len; + + if (Z_TYPE_P(object) != IS_OBJECT) { + return ""; + } + zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC); + return class_name; +} + 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*); @@ -479,7 +491,7 @@ 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", Z_STRVAL_P(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_NAME(object)); } else { 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)); } @@ -525,11 +537,9 @@ PHP_FUNCTION(twig_template_get_attributes) } } */ - char *class_name; - zend_uint class_name_len; + char *class_name = TWIG_GET_CLASS_NAME(object); zval *tmp_self_cache; - zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC); tmp_self_cache = TWIG_GET_STATIC_PROPERTY(template, "cache"); if (!TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name)) {