Skip to content

Commit

Permalink
PHALCON_VERIFY_INTERFACE() and PHALCON_VERIFY_CLASS()
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Aug 9, 2013
1 parent 0814cdc commit 6aed4b1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ext/kernel/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
+------------------------------------------------------------------------+
*/

#include "ext/spl/spl_exceptions.h"

/** Main macros */
#define PH_DEBUG 0

Expand Down Expand Up @@ -328,3 +330,34 @@ extern int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, i
} \
}

#define PHALCON_VERIFY_INTERFACE(instance, interface_ce) \
do { \
if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \
char *buf; \
if (Z_TYPE_P(instance) != IS_OBJECT) { \
spprintf(&buf, 0, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \
} \
else { \
spprintf(&buf, 0, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \
} \
PHALCON_THROW_EXCEPTION_STR(spl_ce_LogicException, buf); \
efree(buf); \
return; \
} \
} while (0)

#define PHALCON_VERIFY_CLASS(instance, class_ce) \
do { \
if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(instance), class_ce, 0 TSRMLS_CC)) { \
char *buf; \
if (Z_TYPE_P(instance) != IS_OBJECT) { \
spprintf(&buf, 0, "Unexpected value type: expected object of type %s, %s given", class_ce->name, zend_zval_type_name(instance)); \
} \
else { \
spprintf(&buf, 0, "Unexpected value type: expected object of type %s, object of type %s given", class_ce->name, Z_OBJCE_P(instance)->name); \
} \
PHALCON_THROW_EXCEPTION_STR(spl_ce_LogicException, buf); \
efree(buf); \
return; \
} \
} while (0)

0 comments on commit 6aed4b1

Please sign in to comment.