]> git.nbdom.net Git - nb.git/commitdiff
yaml without yaml lib
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 9 Nov 2016 11:56:48 +0000 (11:56 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 9 Nov 2016 11:56:48 +0000 (11:56 +0000)
lib/php/db.php
lib/php/nb.php

index 0b9e2c8267d6a19c9c24bd2f67231464a424b853..89c772ab9705b4992a68825a2ed25f9eef7541c2 100644 (file)
@@ -630,7 +630,7 @@ class Db extends nb {
 
       if (!is_readable($file)) continue;
 
-      if (preg_match('/\.(yaml|yml)$/i',$file) and ($yaml = yaml_parse_file($file))) {
+      if (preg_match('/\.(yaml|yml)$/i',$file) and ($yaml = self::yaml_parse_file($file))) {
         $dbs = array_replace_recursive($dbs,$yaml);
 
       } elseif (preg_match('/\.php$/i',$file)) {
index 046251a9c6f40100d65ad64cd9fead647268e1b4..683bd82139dfeb0db185d994a7e8447f4089eaa8 100644 (file)
@@ -311,10 +311,7 @@ class NB {
    */
   public static function object2array($o) { return $array = json_decode(json_encode($o), true); }
 
-  /*
-   * Function: yaml_encode
-   */
-  public static function yaml_encode($row) {
+  private static function yaml_init() {
     static $Spyc;
     if (empty($Spyc) and !function_exists('yaml_emit')) {
       require_once(realpath(dirname(__FILE__).'/Spyc.php'));
@@ -322,7 +319,18 @@ class NB {
       function yaml_parse_file($file) { return Spyc::YAMLLoad($file); }
       $Spyc = true;
     }
+  }
 
+  public static function yaml_parse_file($file) {
+    self::yaml_init();
+    return yaml_parse_file($file);
+  }
+
+  /*
+   * Function: yaml_encode
+   */
+  public static function yaml_encode($row) {
+    self::yaml_init();
     $yaml = yaml_emit($row);
     $yaml = preg_replace('/^---\s*/','',$yaml);
     $yaml = preg_replace('/\n\.\.\.$/','',$yaml);