Changeset 244 for trunk/ext/php

Show
Ignore:
Timestamp:
03/03/2007 15:55:01 (21 months ago)
Author:
indeyets
Message:

exception class is SyckException? now (derived from SPL's UnexpectedValueException?)

Location:
trunk/ext/php
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/phpext.c

    r242 r244  
    2020#include "php_syck.h" 
    2121 
     22#define PHP_SYCK_EXCEPTION_PARENT "UnexpectedValueException" 
     23#define PHP_SYCK_EXCEPTION_PARENT_LC "unexpectedvalueexception" 
     24#define PHP_SYCK_EXCEPTION_NAME "SyckException" 
     25 
     26static zend_class_entry *spl_ce_RuntimeException; 
     27 
     28PHP_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 
    2250static double zero()    { return 0.0; } 
    2351static double one() { return 1.0; } 
     
    4371        "syck", 
    4472        syck_functions, 
    45         NULL,                   /* module init function */ 
     73        PHP_MINIT(syck),        /* module init function */ 
    4674        NULL,                   /* module shutdown function */ 
    4775        NULL,                   /* request init function */ 
    4876        NULL,                   /* request shutdown function */ 
    49         PHP_MINFO(syck), /* module info function */ 
     77        PHP_MINFO(syck),        /* module info function */ 
    5078#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 */ 
    5280#endif 
    5381        STANDARD_MODULE_PROPERTIES 
     
    5987#endif 
    6088 
    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**/ 
    8292static int le_mergekeyp; 
    83  
    84 zend_class_entry merge_key_entry; 
    85          
    86 /* {{{ MergeKey */ 
     93zend_class_entry *merge_key_entry; 
    8794 
    8895static 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 } 
    9198}; 
    9299 
    93 /* {{{ swfmovie_init */ 
    94  
    95100PHP_FUNCTION(mergekey_init) 
    96 {    
    97   object_init_ex(getThis(), &merge_key_entry); 
    98 }  
    99                                                                                                  
     101{ 
     102        object_init_ex(getThis(), merge_key_entry); 
     103} 
    100104 
    101105static void destroy_MergeKey_resource(zend_rsrc_list_entry *resource TSRMLS_DC) 
     
    103107} 
    104108 
    105 /* }}} */ 
    106  
     109 
     110/** 
     111 * SyckException class 
     112**/ 
     113 
     114zend_class_entry *syck_exception_entry; 
    107115/* }}} */ 
    108116 
     
    111119PHP_MINIT_FUNCTION(syck) 
    112120{ 
     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 
    113126        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 
    123130        return SUCCESS; 
    124131} 
     
    167174} 
    168175/* }}} */ 
     176 
    169177 
    170178 
     
    233241                                TSRMLS_FETCH(); 
    234242                                MAKE_STD_ZVAL( o ); 
    235                                 object_init_ex( o, &merge_key_entry ); 
     243                                object_init_ex( o, merge_key_entry ); 
    236244                        } 
    237245                        else 
     
    273281{ 
    274282        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); 
    277284} 
    278285 
  • trunk/ext/php/tests/003.phpt

    r243 r244  
    11--TEST-- 
    2 Check valid-yaml parsing 
     2Check invalid-yaml parsing 
    33--SKIPIF-- 
    44<?php if (!extension_loaded("syck")) print "skip"; ?> 
     
    1818        syck_load($yaml); 
    1919        echo "loaded fine"; 
    20 } catch (ErrorException $e) { 
     20} catch (SyckException $e) { 
    2121        echo $e->getMessage(); 
    2222}