File modules/util/YAML.class.php

Last commit: Sun Feb 23 04:49:34 2020 +0100	Jan Dankert	Refactoring with Namespaces for the cms modules, part 2.
1 <?php 2 3 4 namespace util; 5 use Spyc; 6 7 require_once (__DIR__.'/Spyc.class.php'); 8 9 /** 10 * YAML Wrapper for the Spyc implementation of a YAML-Parser. 11 */ 12 class YAML 13 { 14 /** 15 * Load a string of YAML into a PHP array statically. 16 * 17 * The load method, when supplied with a YAML string, will do its best 18 * to convert YAML in a string into a PHP array. Pretty simple. 19 * @param $string 20 * @return array 21 */ 22 public static function parse($string) 23 { 24 return Spyc::YAMLLoadString($string); 25 } 26 27 /** 28 * Dump YAML from PHP array statically 29 * 30 * The dump method, when supplied with an array, will do its best 31 * to convert the array into friendly YAML. Pretty simple. Feel free to 32 * save the returned string as nothing.yaml and pass it around. 33 * 34 * Oh, and you can decide how big the indent is and what the wordwrap 35 * for folding is. Pretty cool -- just pass in 'false' for either if 36 * you want to use the default. 37 * 38 * Indent's default is 2 spaces, wordwrap's default is 40 characters. And 39 * you can turn off wordwrap by passing in 0. 40 * 41 * @access public 42 * @param array|\stdClass $array PHP array 43 * @param int $indent Pass in false to use the default, which is 2 44 * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40) 45 * @param bool $no_opening_dashes Do not start YAML file with "---\n" 46 * @return string 47 */ 48 public static function dump($array, $indent = false, $wordwrap = false, $no_opening_dashes = true) 49 { 50 return Spyc::YAMLDump($array, $indent, $wordwrap, $no_opening_dashes); 51 } 52 }
Download modules/util/YAML.class.php
History Sun, 23 Feb 2020 04:49:34 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 2. Sat, 22 Feb 2020 23:58:02 +0100 Jan Dankert Refactoring: Namespacing for module 'util'. Sat, 16 Nov 2019 00:46:46 +0100 Jan Dankert Fix: YAML-Parser should not load files. Fri, 15 Nov 2019 23:01:20 +0100 Jan Dankert Fix: No need for opening dashes in YAML documents. Fri, 15 Nov 2019 22:57:50 +0100 Jan Dankert Refactoring: Wrapping the Spyc YAML implementation.