Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to forms and YAML parsing.
- Loading branch information
Piotr Gabryjeluk
committed
Jul 30, 2009
1 parent
17fff1e
commit 2665aba
Showing
6 changed files
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule sfyaml
added at
f3abfa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
<?php | ||
|
||
require_once(WIKIDOT_ROOT . '/lib/spyc/spyc.php'); | ||
require_once(WIKIDOT_ROOT . "/lib/sfyaml/lib/sfYamlParser.php"); | ||
require_once(WIKIDOT_ROOT . "/lib/sfyaml/lib/sfYaml.php"); | ||
require_once(WIKIDOT_ROOT . "/lib/spyc/spyc.php"); | ||
|
||
class Wikidot_Yaml { | ||
public static function load($string) { | ||
return Spyc::YAMLLoadString($string); | ||
public static function load($string, $forgiving = false) { | ||
if (substr($string, 0, 3) != '---') { | ||
$string = "---\n$string"; | ||
} | ||
try { | ||
// if syck is available use it | ||
if (extension_loaded('syck')) { | ||
return syck_load($string); | ||
} | ||
// if not, use the symfony YAML parser | ||
$yaml = new sfYamlParser(); | ||
return $yaml->parse($string); | ||
} catch (Exception $e) { | ||
if ($forgiving) { | ||
// if YAML document is not correct, | ||
// but we're forgiving, use the Spyc parser | ||
return Spyc::YAMLLoadString($string); | ||
} | ||
throw new Wikidot_Yaml_Exception("Can't parse the YAML string." . $e->getMessage()); | ||
} | ||
} | ||
public static function dump($object) { | ||
return Spyc::YAMLDump($object); | ||
// using the slow (but very compatible) symfony YAML dumper | ||
$ret = sfYaml::dump($object, 999); | ||
if (substr($string, 0, 3) == '---') { | ||
return substr($ret, 4); | ||
} | ||
return $ret; | ||
} | ||
} |