Changeset 7981
- Timestamp:
- 03/19/08 18:25:29 (1 year ago)
- Files:
-
- branches/1.1/lib/util/sfYamlInline.class.php (modified) (3 diffs)
- branches/1.1/test/unit/util/fixtures/yaml/index.yml (modified) (1 diff)
- branches/1.1/test/unit/util/fixtures/yaml/sfObjects.yml (added)
- branches/1.1/test/unit/util/sfYamlDumperTest.php (modified) (2 diffs)
- branches/1.1/test/unit/util/sfYamlParserTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/util/sfYamlInline.class.php
r7923 r7981 49 49 * Dumps PHP array to YAML. 50 50 * 51 * @param mixed PHP51 * @param mixed PHP 52 52 * 53 53 * @return string YAML … … 60 60 throw new InvalidArgumentException('Unable to dump PHP resources in a YAML file.'); 61 61 case is_object($value): 62 throw new InvalidArgumentException('Unable to dump objects to a YAML string.');62 return '!!php/object:'.serialize($value); 63 63 case is_array($value): 64 64 return self::dumpArray($value); … … 368 368 case 0 === strpos($scalar, '! '): 369 369 return intval(self::parseScalar(substr($scalar, 2))); 370 case 0 === strpos($scalar, '!!php/object:'): 371 return unserialize(substr($scalar, 13)); 370 372 case ctype_digit($scalar): 371 373 return '0' == $scalar[0] ? octdec($scalar) : intval($scalar); branches/1.1/test/unit/util/fixtures/yaml/index.yml
r7923 r7981 1 1 - sfComments 2 2 - sfTests 3 - sfObjects 3 4 #- YtsAnchorAlias 4 5 - YtsBasicTests branches/1.1/test/unit/util/sfYamlDumperTest.php
r7923 r7981 13 13 require_once(dirname(__FILE__).'/../../../lib/util/sfYamlDumper.class.php'); 14 14 15 $t = new lime_test(13 4, new lime_output_color());15 $t = new lime_test(136, new lime_output_color()); 16 16 17 17 $parser = new sfYamlParser(); … … 134 134 $t->is(sfYaml::dump($array, 4), $expected, '::dump() takes an inline level argument'); 135 135 $t->is(sfYaml::dump($array, 10), $expected, '::dump() takes an inline level argument'); 136 137 // objects 138 $t->diag('Objects support'); 139 class A 140 { 141 public $a = 'foo'; 142 } 143 $a = array('foo' => new A(), 'bar' => 1); 144 $t->is(sfYaml::dump($a), <<<EOF 145 foo: !!php/object:O:1:"A":1:{s:1:"a";s:3:"foo";} 146 bar: 1 147 148 EOF 149 , '::dump() is able to dump objects'); branches/1.1/test/unit/util/sfYamlParserTest.php
r7923 r7981 12 12 require_once(dirname(__FILE__).'/../../../lib/util/sfYamlParser.class.php'); 13 13 14 $t = new lime_test(13 3, new lime_output_color());14 $t = new lime_test(135, new lime_output_color()); 15 15 16 16 $parser = new sfYamlParser(); … … 66 66 } 67 67 } 68 69 // objects 70 $t->diag('Objects support'); 71 class A 72 { 73 public $a = 'foo'; 74 } 75 $a = array('foo' => new A(), 'bar' => 1); 76 $t->is(sfYaml::load(<<<EOF 77 foo: !!php/object:O:1:"A":1:{s:1:"a";s:3:"foo";} 78 bar: 1 79 EOF 80 ), $a, '::dump() is able to dump objects');

