- Timestamp:
- 03/03/2007 15:55:01 (21 months ago)
- Location:
- trunk/ext/php
- Files:
-
- 2 modified
-
phpext.c (modified) (8 diffs)
-
tests/003.phpt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/php/phpext.c
r242 r244 20 20 #include "php_syck.h" 21 21 22 #define PHP_SYCK_EXCEPTION_PARENT "UnexpectedValueException" 23 #define PHP_SYCK_EXCEPTION_PARENT_LC "unexpectedvalueexception" 24 #define PHP_SYCK_EXCEPTION_NAME "SyckException" 25 26 static zend_class_entry *spl_ce_RuntimeException; 27 28 PHP_SYCK_API zend_class_entry *php_syck_get_exception_base(TSRMLS_DC) 29 { 30 #if defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1)) 31 if (!spl_ce_RuntimeException) { 32 zend_class_entry **pce; 33 34 if (zend_hash_find(CG(class_table), PHP_SYCK_EXCEPTION_PARENT_LC, sizeof(PHP_SYCK_EXCEPTION_PARENT_LC), (void **) &pce) == SUCCESS) { 35 spl_ce_RuntimeException = *pce; 36 return *pce; 37 } 38 } else { 39 return spl_ce_RuntimeException; 40 } 41 #endif 42 #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2) 43 return zend_exception_get_default(); 44 #else 45 return zend_exception_get_default(TSRMLS_C); 46 #endif 47 } 48 49 22 50 static double zero() { return 0.0; } 23 51 static double one() { return 1.0; } … … 43 71 "syck", 44 72 syck_functions, 45 NULL,/* module init function */73 PHP_MINIT(syck), /* module init function */ 46 74 NULL, /* module shutdown function */ 47 75 NULL, /* request init function */ 48 76 NULL, /* request shutdown function */ 49 PHP_MINFO(syck), /* module info function */77 PHP_MINFO(syck), /* module info function */ 50 78 #if ZEND_MODULE_API_NO >= 20010901 51 "0. 1",/* Replace with version number for your extension */79 "0.2", /* Replace with version number for your extension */ 52 80 #endif 53 81 STANDARD_MODULE_PROPERTIES … … 59 87 #endif 60 88 61 /* {{{ PHP_INI 62 */ 63 /* Remove comments and fill if you need to have entries in php.ini 64 PHP_INI_BEGIN() 65 STD_PHP_INI_ENTRY("syck.global_value", "42", PHP_INI_ALL, OnUpdateInt, global_value, zend_syck_globals, syck_globals) 66 STD_PHP_INI_ENTRY("syck.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_syck_globals, syck_globals) 67 PHP_INI_END() 68 */ 69 /* }}} */ 70 71 /* {{{ php_syck_init_globals 72 */ 73 /* Uncomment this function if you have INI entries 74 static void php_syck_init_globals(zend_syck_globals *syck_globals) 75 { 76 syck_globals->global_value = 0; 77 syck_globals->global_string = NULL; 78 } 79 */ 80 /* }}} */ 81 89 /** 90 * "Merge" class 91 **/ 82 92 static int le_mergekeyp; 83 84 zend_class_entry merge_key_entry; 85 86 /* {{{ MergeKey */ 93 zend_class_entry *merge_key_entry; 87 94 88 95 static zend_function_entry mergekey_functions[] = { 89 PHP_FALIAS(mergekey, mergekey_init,NULL)90 { NULL, NULL, NULL }96 PHP_FALIAS(mergekey, mergekey_init, NULL) 97 { NULL, NULL, NULL } 91 98 }; 92 99 93 /* {{{ swfmovie_init */94 95 100 PHP_FUNCTION(mergekey_init) 96 { 97 object_init_ex(getThis(), &merge_key_entry); 98 } 99 101 { 102 object_init_ex(getThis(), merge_key_entry); 103 } 100 104 101 105 static void destroy_MergeKey_resource(zend_rsrc_list_entry *resource TSRMLS_DC) … … 103 107 } 104 108 105 /* }}} */ 106 109 110 /** 111 * SyckException class 112 **/ 113 114 zend_class_entry *syck_exception_entry; 107 115 /* }}} */ 108 116 … … 111 119 PHP_MINIT_FUNCTION(syck) 112 120 { 121 zend_class_entry ce; 122 123 INIT_CLASS_ENTRY(ce, PHP_SYCK_EXCEPTION_NAME, NULL); 124 syck_exception_entry = zend_register_internal_class_ex(&ce, php_syck_get_exception_base(TSRMLS_CC), PHP_SYCK_EXCEPTION_PARENT TSRMLS_CC); 125 113 126 le_mergekeyp = zend_register_list_destructors_ex(destroy_MergeKey_resource, NULL, "MergeKey", module_number); 114 115 INIT_CLASS_ENTRY(merge_key_entry, "mergekey", mergekey_functions); 116 117 zend_register_internal_class(&merge_key_entry TSRMLS_CC); 118 119 /* If you have INI entries, uncomment these lines 120 ZEND_INIT_MODULE_GLOBALS(syck, php_syck_init_globals, NULL); 121 REGISTER_INI_ENTRIES(); 122 */ 127 INIT_CLASS_ENTRY(ce, "mergekey", mergekey_functions); 128 merge_key_entry = zend_register_internal_class(&ce TSRMLS_CC); 129 123 130 return SUCCESS; 124 131 } … … 167 174 } 168 175 /* }}} */ 176 169 177 170 178 … … 233 241 TSRMLS_FETCH(); 234 242 MAKE_STD_ZVAL( o ); 235 object_init_ex( o, &merge_key_entry );243 object_init_ex( o, merge_key_entry ); 236 244 } 237 245 else … … 273 281 { 274 282 TSRMLS_FETCH(); 275 zend_class_entry *exc = zend_get_error_exception(); 276 zend_throw_error_exception(exc, str, 1, 1 TSRMLS_CC); 283 zend_throw_exception(syck_exception_entry, str, 0 TSRMLS_CC); 277 284 } 278 285 -
trunk/ext/php/tests/003.phpt
r243 r244 1 1 --TEST-- 2 Check valid-yaml parsing2 Check invalid-yaml parsing 3 3 --SKIPIF-- 4 4 <?php if (!extension_loaded("syck")) print "skip"; ?> … … 18 18 syck_load($yaml); 19 19 echo "loaded fine"; 20 } catch ( ErrorException $e) {20 } catch (SyckException $e) { 21 21 echo $e->getMessage(); 22 22 }