public function testABCD2() { $a = array('a', 'b', 'c', 'd'); // Create a simple list $b = Cyps::YAMLDump($a); // Dump the list as YAML $c = Cyps::YAMLLoad($b); // Load the dumped YAML $d = Cyps::YAMLDump($c); // Re-dump the data $this->assertSame($b, $d); }
protected function setUp() { $this->Y = Cyps::YAMLLoad("indent_1.yaml"); }
public function testHashesInKeys() { $dump = Cyps::YAMLDump(array('#color' => '#ffffff')); $awaiting = "---\n\"#color\": '#ffffff'\n"; $this->assertEquals($awaiting, $dump); }
public function testMultipleArrays() { $expected = array(array(array('x'))); $this->assertSame($expected, Cyps::YAMLLoad("- - - x")); }
<?php # # S P Y C # a simple php yaml class # # Feel free to dump an array to YAML, and then to load that YAML back into an # array. This is a good way to test the limitations of the parser and maybe # learn some basic YAML. # include '../Cyps.php'; $array[] = 'Sequence item'; $array['The Key'] = 'Mapped value'; $array[] = array('A sequence', 'of a sequence'); $array[] = array('first' => 'A sequence', 'second' => 'of mapped values'); $array['Mapped'] = array('A sequence', 'which is mapped'); $array['A Note'] = 'What if your text is too long?'; $array['Another Note'] = 'If that is the case, the dumper will probably fold your text by using a block. Kinda like this.'; $array['The trick?'] = 'The trick is that we overrode the default indent, 2, to 4 and the default wordwrap, 40, to 60.'; $array['Old Dog'] = "And if you want\n to preserve line breaks, \ngo ahead!"; $array['key:withcolon'] = "Should support this to"; $yaml = Cyps::YAMLDump($array, 4, 60);
/** * Dump YAML from PHP array statically * * The dump method, when supplied with an array, will do its best * to convert the array into friendly YAML. Pretty simple. Feel free to * save the returned string as nothing.yaml and pass it around. * * Oh, and you can decide how big the indent is and what the wordwrap * for folding is. Pretty cool -- just pass in 'false' for either if * you want to use the default. * * Indent's default is 2 spaces, wordwrap's default is 40 characters. And * you can turn off wordwrap by passing in 0. * * @access public * @return string * @param array $array PHP array * @param int $indent Pass in false to use the default, which is 2 * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40) * @param int $no_opening_dashes Do not start YAML file with "---\n" */ public static function YAMLDump($array, $indent = false, $wordwrap = false, $no_opening_dashes = false) { $cyps = new Cyps(); return $cyps->dump($array, $indent, $wordwrap, $no_opening_dashes); }
<?php # # S P Y C # a simple php yaml class # # license: [MIT License, http://www.opensource.org/licenses/mit-license.php] # include '../Cyps.php'; $array = Cyps::YAMLLoad('../cyps.yaml'); echo '<pre><a href="cyps.yaml">cyps.yaml</a> loaded into PHP:<br/>'; print_r($array); echo '</pre>'; echo '<pre>YAML Data dumped back:<br/>'; echo Cyps::YAMLDump($array); echo '</pre>';