Changeset 275 for trunk

Show
Ignore:
Timestamp:
10/04/2007 17:54:50 (14 months ago)
Author:
indeyets
Message:

- added support for loading sequences into classes which implement ArrayAccess?

Location:
trunk/ext/php
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/CHANGELOG

    r274 r275  
    99    - added support for loading explicitly typed DateTime (with timestamp-compatible value) 
    1010    - fixed loading of maps with numeric keys 
     11    - added support for loading sequences into classes which implement ArrayAccess  
    1112 
    1213- version: 0.9.1 
  • trunk/ext/php/TODO

    r274 r275  
    88load: 
    99  - objects: 
    10     - "!php/hash:YAML::ClassName" 
    11     - "!php/array:YAML::ClassName" 
    12     - "!php:YAML::ClassName (?)" 
     10    - "!php/hash:ClassName" 
     11    - "!php:ClassName (?)" 
    1312  - allow user to assign custom handler for loading any other type of objects (java, ruby, etc.) 
    1413dump: 
     
    1716    - Iterator: 
    1817      as: map 
    19       label: "!php/hash:YAML::ClassName" 
     18      label: "!php/hash:ClassName" 
    2019    - ArrayAccess: 
    2120      as: sequence 
    22       label: "!php/array:YAML::ClassName" 
     21      label: "!php/array:ClassName" 
    2322    - Generic object (?) 
  • trunk/ext/php/phpext.c

    r274 r275  
    396396                                } 
    397397                        } else if (strncmp(n->type_id, "php/array:", 10) == 0) { 
    398                                 /* some classm which implements ArrayAccess */ 
     398                                /* some class which implements ArrayIterator */ 
     399                                size_t i; 
    399400                                size_t classname_len = strlen(n->type_id) - 10; 
    400401                                char *classname = emalloc(classname_len + 1); 
     
    410411                                } 
    411412 
    412                                 if (0 == instanceof_function_ex(*ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) { 
    413                                         zend_throw_exception_ex(syck_exception_entry, 0 TSRMLS_CC, "Class %s doesn't implement ArrayAccess on line %d, col %d: '%s'", classname, p->linect, p->cursor - p->lineptr, p->lineptr); 
     413                                if (0 != instanceof_function_ex(*ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) { 
     414                                        object_init_ex(o, *ce); 
     415 
     416                                        for (i = 0; i < n->data.list->idx; i++) { 
     417                                                SYMID oid = syck_seq_read(n, i); 
     418                                                zval *o2; 
     419                                                zval *key; 
     420 
     421                                                syck_lookup_sym(p, oid, (char **) &o2); /* retrieving child-node */ 
     422 
     423                                                MAKE_STD_ZVAL(key); 
     424                                                ZVAL_LONG(key, i); 
     425 
     426                                                zend_call_method_with_2_params(&o, *ce, NULL, "offsetset", NULL, key, o2); 
     427                                                zval_ptr_dtor(&o2); 
     428                                                efree(key); 
     429                                        } 
     430                                } else { 
     431                                        zend_throw_exception_ex(syck_exception_entry, 0 TSRMLS_CC, "Class %s doesn't implement ArrayIterator on line %d, col %d: '%s'", classname, p->linect, p->cursor - p->lineptr, p->lineptr); 
    414432                                        efree(classname); 
    415433                                        break; 
    416434                                } 
    417435 
    418                                 /* 
    419                                  * TODO: add filling of ArrayAccess object with values 
    420                                  */ 
    421                                 array_init(o); 
     436 
    422437 
    423438                                efree(classname); 
  • trunk/ext/php/phpunit-tests/TestLoad.php

    r274 r275  
    151151 
    152152        // ArrayObject implements ArrayAccess: OK 
    153         $this->assertEquals(syck_load('!php/array:ArrayObject []'), array()); 
     153        $this->assertEquals(syck_load('!php/array:ArrayObject []'), new ArrayObject()); 
     154        $this->assertEquals(syck_load('!php/array:ArrayObject [1, 2, 3]'), new ArrayObject(array(1, 2, 3))); 
    154155 
    155156        // SyckTestSomeClass doesn't implement ArrayAccess: FAILURE