[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / yaml / inc / yaml_sfyaml.php
diff --git a/www/plugins/auto/yaml/inc/yaml_sfyaml.php b/www/plugins/auto/yaml/inc/yaml_sfyaml.php
new file mode 100644 (file)
index 0000000..775592f
--- /dev/null
@@ -0,0 +1,33 @@
+<?php\r
+if (!defined("_ECRIRE_INC_VERSION")) return;\r
+\r
+function yaml_sfyaml_encode($struct, $opt = array()) {\r
+       require_once _DIR_PLUGIN_YAML.'sfyaml/sfYaml.php';\r
+       require_once _DIR_PLUGIN_YAML.'sfyaml/sfYamlDumper.php';\r
+       $opt = array_merge(\r
+               array(\r
+                       'inline' => 2\r
+               ), $opt);\r
+       $yaml = new sfYamlDumper();\r
+       return $yaml->dump($struct, $opt['inline']);\r
+}\r
+\r
+function yaml_sfyaml_decode($input) {\r
+       require_once _DIR_PLUGIN_YAML.'sfyaml/sfYaml.php';\r
+       require_once _DIR_PLUGIN_YAML.'sfyaml/sfYamlParser.php';\r
+\r
+       $yaml = new sfYamlParser();\r
+\r
+       try\r
+       {\r
+         $ret = $yaml->parse($input);\r
+       }\r
+       catch (Exception $e)\r
+       {\r
+               throw new InvalidArgumentException(sprintf('Unable to parse string: %s', $e->getMessage()));\r
+       }\r
+\r
+       return $ret;\r
+}\r
+\r
+?>
\ No newline at end of file