- Timestamp:
- 10/05/2007 10:34:34 (14 months ago)
- Location:
- trunk/ext/php
- Files:
-
- 1 added
- 5 modified
-
CHANGELOG (modified) (1 diff)
-
TODO (modified) (1 diff)
-
phpext.c (modified) (7 diffs)
-
phpunit-tests/TestDump.php (modified) (3 diffs)
-
phpunit-tests/TestLoad.php (modified) (7 diffs)
-
phpunit-tests/helpers.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/php/CHANGELOG
r278 r279 8 8 - fixed loading of maps with numeric keys 9 9 - short-and-flat arrays are dumped using inline-mode now (for readability) 10 - changed explicit type of DateTime class to be !php/object::DateTime 10 11 - added support for loading explicitly typed DateTime (with timestamp-compatible value) 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)13 - added support for loading classes which implement Serializable (!php :ClassName)14 - changed explicit type of DateTime class to be !php:DateTime12 - added support for loading sequences into classes which implement ArrayAccess (!php/array::ClassName) 13 - added support for loading maps into classes which implement ArrayAccess (!php/hash::ClassName) 14 - added support for loading classes which implement Serializable (!php/object::ClassName) 15 - added support for dumping classes which implement Serializable (!php/object::ClassName) 15 16 16 17 - version: 0.9.1 -
trunk/ext/php/TODO
r277 r279 13 13 - Iterator: 14 14 as: map 15 label: "!php/hash: ClassName"15 label: "!php/hash::ClassName" 16 16 - ArrayAccess: 17 17 as: sequence 18 label: "!php/array: ClassName"18 label: "!php/array::ClassName" 19 19 - Generic object (?) -
trunk/ext/php/phpext.c
r278 r279 360 360 } else if (strcmp(n->type_id, "float#neginf") == 0) { 361 361 ZVAL_DOUBLE(o, -inf()); 362 } else if (strncmp(n->type_id, "timestamp", 9) == 0 || strcmp(n->type_id, "php :Datetime") == 0) {362 } else if (strncmp(n->type_id, "timestamp", 9) == 0 || strcmp(n->type_id, "php/object::Datetime") == 0) { 363 363 zval fname, param, *params[1]; 364 364 TSRMLS_FETCH(); … … 373 373 zval_dtor(&fname); 374 374 zval_dtor(params[0]); 375 } else if (strncmp(n->type_id, "php :", 4) == 0) {375 } else if (strncmp(n->type_id, "php/object::", 12) == 0) { 376 376 /* Some custom php-class packed in a string. Only ones implementing Serializable ar supported */ 377 size_t classname_len = strlen(n->type_id) - 4;377 size_t classname_len = strlen(n->type_id) - 12; 378 378 char *classname = emalloc(classname_len + 1); 379 379 zend_class_entry **ce; … … 381 381 TSRMLS_FETCH(); 382 382 383 strncpy(classname, n->type_id + 4, classname_len + 1);383 strncpy(classname, n->type_id + 12, classname_len + 1); 384 384 385 385 if (FAILURE == zend_lookup_class_ex(classname, classname_len, 1, &ce TSRMLS_CC)) { … … 421 421 add_index_zval(o, i, o2); 422 422 } 423 } else if (strncmp(n->type_id, "php/array: ", 10) == 0) {423 } else if (strncmp(n->type_id, "php/array::", 11) == 0) { 424 424 /* some class which implements ArrayAccess */ 425 425 size_t i; 426 size_t classname_len = strlen(n->type_id) - 1 0;426 size_t classname_len = strlen(n->type_id) - 11; 427 427 char *classname = emalloc(classname_len + 1); 428 428 zend_class_entry **ce; 429 429 TSRMLS_FETCH(); 430 430 431 strncpy(classname, n->type_id + 1 0, classname_len + 1);431 strncpy(classname, n->type_id + 11, classname_len + 1); 432 432 433 433 if (FAILURE == zend_lookup_class_ex(classname, classname_len, 1, &ce TSRMLS_CC)) { … … 501 501 zval_ptr_dtor(&o2); 502 502 } 503 } else if (strncmp(n->type_id, "php/hash: ", 9) == 0) {503 } else if (strncmp(n->type_id, "php/hash::", 10) == 0) { 504 504 /* some classm which implements ArrayAccess */ 505 505 SYMID oid; 506 506 size_t i; 507 507 zval *o2, *o3; 508 size_t classname_len = strlen(n->type_id) - 9;508 size_t classname_len = strlen(n->type_id) - 10; 509 509 char *classname = emalloc(classname_len + 1); 510 510 zend_class_entry **ce; 511 511 TSRMLS_FETCH(); 512 512 513 strncpy(classname, n->type_id + 9, classname_len + 1);513 strncpy(classname, n->type_id + 10, classname_len + 1); 514 514 515 515 if (FAILURE == zend_lookup_class_ex(classname, classname_len, 1, &ce TSRMLS_CC)) { … … 733 733 zend_get_object_classname(data, &name, &name_len TSRMLS_CC); 734 734 735 /* DateTime is encoded as timestamp */ 735 736 if (strncmp(name, "DateTime", name_len) == 0) { 736 737 zval *retval; … … 745 746 zval_dtor(retval); 746 747 efree(retval); 748 } else { 749 if (0 != instanceof_function_ex(ce, zend_ce_serializable, 1 TSRMLS_CC)) { 750 char *prefix = "tag:php:object::"; 751 size_t prefix_len = strlen(prefix) + 1; 752 char *tagname = emalloc(name_len + prefix_len); 753 zval *serialized; 754 755 snprintf(tagname, name_len + prefix_len, "%s%s", prefix, name); 756 757 zend_call_method_with_0_params(&data, ce, NULL, "serialize", &serialized); 758 syck_emit_scalar(e, tagname, scalar_2quote, 0, 0, 0, Z_STRVAL_P(serialized), Z_STRLEN_P(serialized)); 759 760 efree(tagname); 761 } 747 762 } 748 763 -
trunk/ext/php/phpunit-tests/TestDump.php
r273 r279 5 5 6 6 require_once "PHPUnit/Framework/TestCase.php"; 7 require 'helpers.php'; 7 8 8 9 error_reporting(E_ALL); … … 10 11 class TestDump extends PHPUnit_Framework_TestCase 11 12 { 13 public function testNull() 14 { 15 $arr = array('qq' => null); 16 $this->assertEquals($arr, syck_load(syck_dump($arr))); 17 } 18 12 19 public function testArray() 13 20 { … … 47 54 $this->assertEquals($arr2, $arr); 48 55 } 56 57 public function testSerializable() 58 { 59 $obj = new MySerializable('some string'); 60 $this->assertEquals($obj, syck_load(syck_dump($obj))); 61 } 49 62 } -
trunk/ext/php/phpunit-tests/TestLoad.php
r278 r279 5 5 6 6 require_once "PHPUnit/Framework/TestCase.php"; 7 require 'helpers.php'; 7 8 8 9 error_reporting(E_ALL); 9 10 10 class SyckTestSomeClass {}11 12 class MySerializable implements Serializable13 {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 }36 11 37 12 class TestLoad extends PHPUnit_Framework_TestCase … … 165 140 166 141 // explicit 167 $this->assertType('DateTime', syck_load("!php :Datetime 2002-12-14"));142 $this->assertType('DateTime', syck_load("!php/object::Datetime 2002-12-14")); 168 143 } 169 144 … … 175 150 176 151 // ArrayObject implements ArrayAccess: OK 177 $this->assertEquals(syck_load('!php/array: ArrayObject []'), new ArrayObject());178 $this->assertEquals(syck_load('!php/array: ArrayObject [1, 2, 3]'), new ArrayObject(array(1, 2, 3)));152 $this->assertEquals(syck_load('!php/array::ArrayObject []'), new ArrayObject()); 153 $this->assertEquals(syck_load('!php/array::ArrayObject [1, 2, 3]'), new ArrayObject(array(1, 2, 3))); 179 154 180 155 // SyckTestSomeClass doesn't implement ArrayAccess: FAILURE 181 156 try { 182 syck_load('!php/array: SyckTestSomeClass []');157 syck_load('!php/array::SyckTestSomeClass []'); 183 158 $this->assertTrue(false); 184 159 } catch (SyckException $e) { … … 188 163 // SyckTestOtherClass doesn't exist: FAILURE 189 164 try { 190 syck_load('!php/array: SyckTestOtherClass []');165 syck_load('!php/array::SyckTestOtherClass []'); 191 166 $this->assertTrue(false); 192 167 } catch (SyckException $e) { … … 201 176 202 177 // ArrayObject implements ArrayAccess: OK 203 $this->assertEquals(new ArrayObject(), syck_load('!php/hash: ArrayObject {}'));178 $this->assertEquals(new ArrayObject(), syck_load('!php/hash::ArrayObject {}')); 204 179 $this->assertEquals( 205 180 new ArrayObject(array('a' => 1, 'b' => 2, 3 => 3, 4 => 'd', 'e' => 5)), 206 syck_load('!php/hash: ArrayObject {a: 1, b: 2, 3: 3, 4: d, e: 5}')181 syck_load('!php/hash::ArrayObject {a: 1, b: 2, 3: 3, 4: d, e: 5}') 207 182 ); 208 183 209 184 // SyckTestSomeClass doesn't implement ArrayAccess: FAILURE 210 185 try { 211 syck_load('!php/hash: SyckTestSomeClass {}');186 syck_load('!php/hash::SyckTestSomeClass {}'); 212 187 $this->assertTrue(false); 213 188 } catch (SyckException $e) { … … 217 192 // SyckTestOtherClass doesn't exist: FAILURE 218 193 try { 219 syck_load('!php/hash: SyckTestOtherClass {}');194 syck_load('!php/hash::SyckTestOtherClass {}'); 220 195 $this->assertTrue(false); 221 196 } catch (SyckException $e) { … … 226 201 public function testSerializable() 227 202 { 228 $obj = syck_load('!php :MySerializable teststring');203 $obj = syck_load('!php/object::MySerializable teststring'); 229 204 230 205 $this->assertType('MySerializable', $obj);