The first step: spyc.php: (Special note: This is an extension of the file, do not move any of the code, copy the past to reference it on it.) ) <?php/** * SPYC--A simple php YAML Class * @version 0.4.5 * @author Vlad Dersen <vlad.andersen@gmail.com> * @author Chris wanstrath <chris@ozmm.org> * @ Link http://code.google.com/p/spyc/ * @copyright copyright 2005-2006 Chris wanstrath 2006-2009 Vlad N * @license http://www.opensource.org/licenses/mit-license.php mit license * @package SPYC &NB Sp */if (!function_exists (' spyc_load ')) { /** * parses YAML to array. * @param string $string YAML String. * @return Array */ function spyc_load ($string) { return Spyc::yamlloadstri Ng ($string); } if (!function_exists (' Spyc_load_file ')) { /** * parses YAML to array. * @param String $file Path to YAML file. * @return Array */ function Spyc_load_file ($file) { return spyc::yamlload ($file); }}/**   ; * the simple PHP YAML Class. * * This class can is used to read a YAML file and convert it contents * into a PH P Array. It currently supports a very limited subsection of * the YAML spec. * * Usage: &nbs P * <code> * $Spyc = new Spyc; * $array = $Spyc->load ($file); * </code> * or: * <code> * $array = Spyc::yamlload ($file); * </code> * or: * <code> * $array = Spyc_load_file ($file) ; * </code> * @package spyc */class Spyc { //SETTINGS /**   ; * Setting this to true would force yamldump to enclose any string value in * quotes. False by deFault. * * @var bool */ public $setting _dump_force_quotes = false; /** * Setting this to true would forse yamlload to use Syck_load function when * possible. False by default. * @var bool */ public $setting _use_syck_is_possible = false; /**#@+ * @access private * @var mixed */ private $_dumpindent; Private $_dumpwordwrap; Private $_containsgroupanchor = false; Private $_containsgroupalias = false; Private $path; Private $result; Private $LiteralPlaceHolder = ' ___yaml_literal_block___ '; Private $SavedGroups = Array (); Private $indent; /** * Path modifier that should is applied after adding the current element. * @var array */ Private $delayedPath = Array (); /**#@+ * @access public * @var mixed */ public $_NodeId; /** * Load A valid YAML string to SPYC. * @param string $input * @return Array */ Public function load ($input) { return $t His->__loadstring ($input); } /** * Load A valid YAML file to SPYC. * @param string $file * @return Array */ Public function loadfile ($file) { return $this->__load ($file); /** * Load YAML into a PHP array statically * * The Load method, where supplied with a YAML stream (string or file), * 'll do it best to convert YA ML in a file into a PHP array. Pretty * simple. * Usage: * <code> * $array = spyc::yamlload (' Lucky.yaml ' ); * Print_r ($array); * </code> * @access public * @return Array &nbSp * @param string $input Path of YAML file or string containing YAML */ public Stati C function Yamlload ($input) { $SPYC = new SPYC return $SPYC->__load ($input); } &nbs P /** * Load A string of YAML into a PHP array statically * * Th E load method, where supplied with a YAML string, would do it best * to convert YAML in a string into a PHP Array. Pretty simple. * * Note:use This function if you don ' t want files from the file system &N Bsp * loaded and processed as YAML. This is in interest to people concerned * about security whose input are from a string. * * Usage: * <code> * $array = Spyc: : Yamlloadstring ("---\n0:hello world\n"); * Print_r ($array); &nbSp * </code> * @access public * @return array * @param string $input string containing YAML */ public static function yamlloadstring ($input) { $SPYC = new SPYC return $SPYC->__loadstring ($input); } /** & nbsp;* dump YAML from PHP array statically * * "Dump method" when supplied with An array, would do it best * to convert the array into friendly YAML. Pretty simple. Feel * Save the returned string as Nothing.yaml and pass it around. * * Oh, and can decide how to the indent is and what the WordWrap &nbs P * for folding is. Pretty cool--just pass in ' false ' for either if * your want to use the default. * * Indent ' s defAult is 2 spaces, WordWrap ' s default is characters. and * can turn off WordWrap by passing in 0. * * @access public * @return string * @par Am array $array PHP array * @param int $indent pass on false to use the default, which is 2 &NB Sp * @param int $wordwrap Pass in 0 for no wordwrap, false for default */ public static function Yamldump ($array, $indent = False, $wordwrap = False) { $SPYC = new SPYC return $SPYC- >dump ($array, $indent, $wordwrap); /** * dump PHP array to YAML * * the dump meth OD, when supplied with an array, would do it best * to convert the array into friendly YAML. Pretty simple. Feel * Save the returned string as Tasteful.yaml and pass it around.   * * Oh, and can decide how to the indent is and what the WordWrap &NBS p;* for folding is. Pretty cool--just pass in ' false ' for either if * your want to use the default. * * Indent ' s default is 2 spaces, WordWrap ' s default is characters. and * can turn off WordWrap by passing in 0. * * @access public * @return string * @par Am array $array PHP array * @param int $indent pass on false to use the default, which is 2 &NB Sp * @param int $wordwrap Pass in 0 for no wordwrap, false for default */ public functi On dump ($array, $indent = False, $wordwrap = False) { //dumps to some very clean YAML. We'll have to add some features /and options soon. and better support for FoldinG. //New features and options. if ($indent = = False or!is_numeric ($indent)) { $this->_dumpindent = 2; &nbs P else { $this->_dumpindent = $indent } if ($wordwrap = = False or!i S_numeric ($wordwrap)) { $this->_dumpwordwrap = + } else { $th Is->_dumpwordwrap = $wordwrap; } //New YAML document $string = "---\ n"; //Start at the base's the array and move through it. if ($array) { $array = (array) $array; $previous _key =-1; & nbsp foreach ($array as $key => $value) { if (!isset ($first _key)) $first _key = $key; &nbs P $string. = $this->_yamlize ($key, $value, 0, $previous _key, $first _key, $array); $previous _key =$key; } } return $string; /** * attempts to convert a Key/value array item to YAML * @acce SS Private * @return string * @param $key The name of the key * @param $value The value of the item * @param $indent The indent of the current node
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.