Changeset 276 for trunk/ext/php

Show
Ignore:
Timestamp:
10/05/2007 01:52:32 (14 months ago)
Author:
indeyets
Message:

added support for loading maps into classes which implement ArrayAccess? (!php/hash:ClassName)

Location:
trunk/ext/php
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/CHANGELOG

    r275 r276  
    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  
     11    - added support for loading sequences into classes which implement ArrayAccess (!php/array:ClassName) 
     12    - added support for loading maps into classes which implement ArrayAccess (!php/hash:ClassName) 
    1213 
    1314- version: 0.9.1 
  • trunk/ext/php/TODO

    r275 r276  
    88load: 
    99  - objects: 
    10     - "!php/hash:ClassName" 
    1110    - "!php:ClassName (?)" 
    1211  - allow user to assign custom handler for loading any other type of objects (java, ruby, etc.) 
  • trunk/ext/php/phpext.c

    r275 r276  
    396396                                } 
    397397                        } else if (strncmp(n->type_id, "php/array:", 10) == 0) { 
    398                                 /* some class which implements ArrayIterator */ 
     398                                /* some class which implements ArrayAccess */ 
    399399                                size_t i; 
    400400                                size_t classname_len = strlen(n->type_id) - 10; 
     
    428428                                                efree(key); 
    429429                                        } 
     430 
     431                                        if (zend_hash_exists(&(*ce)->function_table, "__wakeup", 9)) { 
     432                                                zend_call_method_with_0_params(&o, *ce, NULL, "__wakeup", NULL); 
     433                                        } 
    430434                                } 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); 
     435                                        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); 
    432436                                        efree(classname); 
    433437                                        break; 
     
    473477                        } else if (strncmp(n->type_id, "php/hash:", 9) == 0) { 
    474478                                /* some classm which implements ArrayAccess */ 
     479                                SYMID oid; 
     480                                size_t i; 
     481                                zval *o2, *o3; 
    475482                                size_t classname_len = strlen(n->type_id) - 9; 
    476483                                char *classname = emalloc(classname_len + 1); 
     
    492499                                } 
    493500 
    494                                 /* 
    495                                  * TODO: add filling of ArrayAccess object with values 
    496                                  */ 
    497                                 array_init(o); 
     501                                object_init_ex(o, *ce); 
     502 
     503                                for (i = 0; i < n->data.pairs->idx; i++) { 
     504                                        oid = syck_map_read(n, map_key, i); 
     505                                        syck_lookup_sym(p, oid, (char **) &o2); /* retrieving key-node */ 
     506 
     507                                        if (o2->type == IS_STRING || o2->type == IS_LONG) { 
     508                                                oid = syck_map_read(n, map_value, i); 
     509                                                syck_lookup_sym(p, oid, (char **) &o3); /* retrieving value-node */ 
     510 
     511                                                zend_call_method_with_2_params(&o, *ce, NULL, "offsetset", NULL, o2, o3); 
     512                                                zval_ptr_dtor(&o3); 
     513                                        } 
     514 
     515                                        zval_ptr_dtor(&o2); 
     516                                } 
     517 
     518                                if (zend_hash_exists(&(*ce)->function_table, "__wakeup", 9)) { 
     519                                        zend_call_method_with_0_params(&o, *ce, NULL, "__wakeup", NULL); 
     520                                } 
    498521 
    499522                                efree(classname); 
  • trunk/ext/php/phpunit-tests/TestLoad.php

    r275 r276  
    177177 
    178178        // ArrayObject implements ArrayAccess: OK 
    179         $this->assertEquals(syck_load('!php/hash:ArrayObject {}'), array()); 
     179        $this->assertEquals(new ArrayObject(), syck_load('!php/hash:ArrayObject {}')); 
     180        $this->assertEquals( 
     181            new ArrayObject(array('a' => 1, 'b' => 2, 3 => 3, 4 => 'd', 'e' => 5)), 
     182            syck_load('!php/hash:ArrayObject {a: 1, b: 2, 3: 3, 4: d, e: 5}') 
     183        ); 
    180184 
    181185        // SyckTestSomeClass doesn't implement ArrayAccess: FAILURE