[PLUGINS] +yaml
[ptitvelo/web/www.git] / www / plugins / yaml / inc / yaml_sfyaml.php
1 <?php
2 if (!defined("_ECRIRE_INC_VERSION")) return;
3
4 function yaml_sfyaml_encode($struct, $opt = array()) {
5 require_once _DIR_PLUGIN_YAML.'sfyaml/sfYaml.php';
6 require_once _DIR_PLUGIN_YAML.'sfyaml/sfYamlDumper.php';
7 $opt = array_merge(
8 array(
9 'inline' => 2
10 ), $opt);
11 $yaml = new sfYamlDumper();
12 return $yaml->dump($struct, $opt['inline']);
13 }
14
15 function yaml_sfyaml_decode($input,$show_error=true) {
16 require_once _DIR_PLUGIN_YAML.'sfyaml/sfYaml.php';
17 require_once _DIR_PLUGIN_YAML.'sfyaml/sfYamlParser.php';
18
19 $yaml = new sfYamlParser();
20
21 try
22 {
23 $ret = $yaml->parse($input);
24 }
25 catch (Exception $e)
26 {
27 if ($show_error)
28 throw new InvalidArgumentException(sprintf('Unable to parse string: %s', $e->getMessage()));
29 else
30 return false;
31 }
32
33 return $ret;
34 }
35
36 ?>