- Timestamp:
- 10/05/2007 04:48:38 (14 months ago)
- Location:
- trunk/ext/php
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/php/CHANGELOG
r276 r277 11 11 - added support for loading sequences into classes which implement ArrayAccess (!php/array:ClassName) 12 12 - added support for loading maps into classes which implement ArrayAccess (!php/hash:ClassName) 13 - added support for loading classes which implement Serializable (!php:ClassName) 13 14 14 15 - version: 0.9.1 -
trunk/ext/php/TODO
r276 r277 7 7 - "add PHP6 (unicode strings) support" 8 8 load: 9 - objects:10 - "!php:ClassName (?)"11 9 - allow user to assign custom handler for loading any other type of objects (java, ruby, etc.) 12 10 dump: -
trunk/ext/php/phpext.c
r276 r277 142 142 * 0 for sequential numeric arrays 143 143 * 1 for insequential or associative arrays 144 */144 **/ 145 145 static int psex_determine_array_type(HashTable *myht TSRMLS_DC) /* {{{ */ 146 146 { … … 373 373 zval_dtor(&fname); 374 374 zval_dtor(params[0]); 375 } else if (strncmp(n->type_id, "php:", 4) == 0) { 376 size_t classname_len = strlen(n->type_id) - 4; 377 char *classname = emalloc(classname_len + 1); 378 zend_class_entry **ce; 379 zval param; 380 TSRMLS_FETCH(); 381 382 strncpy(classname, n->type_id + 4, classname_len + 1); 383 384 if (FAILURE == zend_lookup_class_ex(classname, classname_len, 1, &ce TSRMLS_CC)) { 385 zend_throw_exception_ex(syck_exception_entry, 0 TSRMLS_CC, "Couldn't find %s class on line %d, col %d: '%s'", classname, p->linect, p->cursor - p->lineptr, p->lineptr); 386 efree(classname); 387 break; 388 } 389 390 if (0 == instanceof_function_ex(*ce, zend_ce_serializable, 1 TSRMLS_CC)) { 391 zend_throw_exception_ex(syck_exception_entry, 0 TSRMLS_CC, "Class %s doesn't implement Serializable on line %d, col %d: '%s'", classname, p->linect, p->cursor - p->lineptr, p->lineptr); 392 efree(classname); 393 break; 394 } 395 efree(classname); 396 397 object_init_ex(o, *ce); 398 ZVAL_STRINGL(¶m, n->data.str->ptr, n->data.str->len, 1); 399 zend_call_method_with_1_params(&o, *ce, NULL, "unserialize", NULL, ¶m); 375 400 } else { 376 401 php_error(E_NOTICE, "syck extension didn't handle %s type => treating as a string", n->type_id); -
trunk/ext/php/phpunit-tests/TestLoad.php
r276 r277 10 10 class SyckTestSomeClass {} 11 11 12 class MySerializable implements Serializable 13 { 14 private $string = null; 15 16 public function __construct() 17 { 18 throw new Exception('This is not supposed to be called'); 19 } 20 21 public function serialize() 22 { 23 return 'test'; 24 } 25 26 public function unserialize($string) 27 { 28 $this->string = $string; 29 } 30 31 public function test() 32 { 33 return $this->string; 34 } 35 } 12 36 13 37 class TestLoad extends PHPUnit_Framework_TestCase … … 199 223 } 200 224 } 225 226 public function testSerializable() 227 { 228 $obj = syck_load('!php:MySerializable teststring'); 229 230 $this->assertType('MySerializable', $obj); 231 $this->assertSame('teststring', $obj->test()); 232 } 201 233 }