Exemplo n.º 1
0
 public static function YAMLSave($array, $path, $keep = 10)
 {
     $yml = Spyc::YAMLDump($array);
     // get the highest number for the current backup
     $files = glob($path . ".*");
     $max = Spyc::max_filenumber($files);
     $max = $max + 1;
     // increment the current version
     foreach (array_reverse($files) as $file) {
         $num = Spyc::get_number_from_filename($file);
         $newfile = substr_replace($file, $num + 1, strlen($path) + 1);
         rename($file, $newfile);
     }
     // copy the current file to a new backup
     if (file_exists($path)) {
         copy($path, $path . ".1");
     }
     // remove the older backups
     $files = glob($path . ".*");
     foreach ($files as $file) {
         $num = Spyc::get_number_from_filename($file);
         if ($num > $keep) {
             unlink($file);
         }
     }
     // save the file
     file_put_contents($path, $yml);
 }