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