From: Nicolas Boisselier Date: Wed, 9 Nov 2016 11:56:48 +0000 (+0000) Subject: yaml without yaml lib X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=f07998f6838dc0bd8bb44c0b39203663bfcfba81;p=nb.git yaml without yaml lib --- diff --git a/lib/php/db.php b/lib/php/db.php index 0b9e2c82..89c772ab 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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)) { diff --git a/lib/php/nb.php b/lib/php/nb.php index 046251a9..683bd821 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -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);