[PLUGINS] +yaml
[ptitvelo/web/www.git] / www / plugins / yaml / inc / yaml_sfyaml.php
diff --git a/www/plugins/yaml/inc/yaml_sfyaml.php b/www/plugins/yaml/inc/yaml_sfyaml.php
new file mode 100644 (file)
index 0000000..1d94844
--- /dev/null
@@ -0,0 +1,36 @@
+<?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,$show_error=true) {\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
+               if ($show_error) \r
+              throw new InvalidArgumentException(sprintf('Unable to parse string: %s', $e->getMessage()));\r
+          else\r
+              return false;       \r
+       }\r
+\r
+       return $ret;\r
+}\r
+\r
+?>
\ No newline at end of file