function yaml2dbforge() { $vars = array(); $yaml = $this->EE->input->post('yaml'); $vars['yaml'] = $yaml; if ($yaml) { $this->EE->load->helper('yayparser_helper'); $this->EE->load->helper('devkit_helper'); $parsed_arr = YAYPARSER_parse($yaml); $vars['parsed_arr'] = $parsed_arr; } return $this->content_wrapper('yaml2dbforge', 'yaml2dbforge', $vars); }
/** * YAYParser - Yet Anoter Yaml Parser. * * @param $str The string to be processed * * @return An array which contains data built from the string */ function yayparser($str) { if (!strlen($str)) { return array(); } $ret = array(); // split the string into many documents according to the YAML standard preg_match_all('@(?:(?:^|\\n)-{3}([\\w\\W]*?)(?:\\n\\.{3}(?:[\\w\\W]*?)(?=(?:\\n-{3})|$))?(?=(?:\\n-{3})|(?:$)))@', "---\n" . $str, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $GLOBALS['YAYPARSER_anchors'] = array(); if (isset($match[1]) && strlen(trim($match[1]))) { if (count($data = YAYPARSER_parse($match[1]))) { $ret[] = $data; } } } if (count($ret) == 1) { $ret = $ret[0]; } return $ret; }