openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

YAML.class.php (1538B)


      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 }