dump() public méthode

The dump method, when supplied with an array, will do its best to convert the array into friendly YAML. Pretty simple. Feel free to save the returned string as tasteful.yaml and pass it around. Oh, and you can decide how big the indent is and what the wordwrap for folding is. Pretty cool -- just pass in 'false' for either if you want to use the default. Indent's default is 2 spaces, wordwrap's default is 40 characters. And you can turn off wordwrap by passing in 0.
public dump ( array $array, integer $indent = false, integer $wordwrap = false, $no_opening_dashes = false ) : string
$array array PHP array
$indent integer Pass in false to use the default, which is 2
$wordwrap integer Pass in 0 for no wordwrap, false for default (40)
Résultat string
 public function testDumpWithQuotes()
 {
     $Spyc = new Spyc();
     $Spyc->setting_dump_force_quotes = true;
     $yaml = $Spyc->load(file_get_contents('../spyc.yaml'));
     $dump = $Spyc->dump($yaml);
     $yaml_after_dump = Spyc::YAMLLoad($dump);
     $this->assertEquals($yaml, $yaml_after_dump);
 }
Exemple #2
0
 public function testDumpWithQuotes()
 {
     $Spyc = new Spyc();
     $Spyc->setting_dump_force_quotes = true;
     foreach ($this->files_to_test as $file) {
         $yaml = $Spyc->load(file_get_contents($file));
         $dump = $Spyc->dump($yaml);
         $yaml_after_dump = Spyc::YAMLLoad($dump);
         $this->assertEquals($yaml, $yaml_after_dump);
     }
 }
Exemple #3
0
Fichier : YAML.php Projet : ksst/kf
 /**
  * Write the config array to a yaml file.
  *
  * @param   string The yaml file.
  *
  * @return bool True, if successfully written, else False.
  */
 public static function write($file, array $array)
 {
     // prefer yaml, then syck, else use Spyc - faster one first
     if (extension_loaded('yaml')) {
         return yaml_emit_file($file, $array);
     } elseif (extension_loaded('syck')) {
         $yaml = syck_dump($array);
     } elseif (class_exists('Spyc')) {
         $spyc = new Spyc();
         $yaml = $spyc->dump($array);
     } else {
         throw new \Koch\Exception\Exception('No YAML Parser available. Get Spyc or Syck!');
     }
     return (bool) file_put_contents($file, $yaml, LOCK_EX);
 }
Exemple #4
0
 /**
  * Dump YAML from PHP array statically
  *
  * The dump method, when supplied with an array, will do its best
  * to convert the array into friendly YAML.  Pretty simple.  Feel free to
  * save the returned string as nothing.yaml and pass it around.
  *
  * Oh, and you can decide how big the indent is and what the wordwrap
  * for folding is.  Pretty cool -- just pass in 'false' for either if
  * you want to use the default.
  *
  * Indent's default is 2 spaces, wordwrap's default is 40 characters.  And
  * you can turn off wordwrap by passing in 0.
  *
  * @access public
  * @return string
  * @param array $array PHP array
  * @param int $indent Pass in false to use the default, which is 2
  * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
  * @param int $no_opening_dashes Do not start YAML file with "---\n"
  */
 public static function YAMLDump($array, $indent = false, $wordwrap = false, $no_opening_dashes = false)
 {
     $spyc = new Spyc();
     return $spyc->dump($array, $indent, $wordwrap, $no_opening_dashes);
 }
 /**
  * Dump YAML from PHP array statically
  *
  * The dump method, when supplied with an array, will do its best
  * to convert the array into friendly YAML.  Pretty simple.  Feel free to
  * save the returned string as nothing.yaml and pass it around.
  *
  * Oh, and you can decide how big the indent is and what the wordwrap
  * for folding is.  Pretty cool -- just pass in 'false' for either if
  * you want to use the default.
  *
  * Indent's default is 2 spaces, wordwrap's default is 40 characters.  And
  * you can turn off wordwrap by passing in 0.
  *
  * @access public
  * @return string
  * @param array $array PHP array
  * @param int $indent Pass in false to use the default, which is 2
  * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
  */
 function YAMLDump($array, $indent = false, $wordwrap = false)
 {
     $spyc = new Spyc();
     return $spyc->dump($array, $indent, $wordwrap);
 }
Exemple #6
0
 /**
  * Dump YAML from PHP array statically
  *
  * The dump method, when supplied with an array, will do its best
  * to convert the array into friendly YAML.  Pretty simple.  Feel free to
  * save the returned string as nothing.yml and pass it around.
  * @access public
  * @return string
  * @param array $array PHP array
  */
 function YAMLDump($array)
 {
     $spyc = new Spyc();
     return $spyc->dump($array);
 }
 /**
  * Dump YAML from PHP array statically
  *
  * The dump method, when supplied with an array, will do its best
  * to convert the array into friendly YAML.
  *
  * @return string
  * @param array $array PHP array
  */
 public static function dump($array)
 {
     require_once dirname(__FILE__) . '/Spyc.class.php';
     $spyc = new Spyc();
     return $spyc->dump($array, false, 0);
 }
Exemple #8
0
 /**
  * Dump YAML from PHP array statically
  *
  * The dump method, when supplied with an array, will do its best
  * to convert the array into friendly YAML.  Pretty simple.  Feel free to
  * save the returned string as nothing.yaml and pass it around.
  *
  * Oh, and you can decide how big the indent is and what the wordwrap
  * for folding is.  Pretty cool -- just pass in 'false' for either if
  * you want to use the default.
  *
  * Indent's default is 2 spaces, wordwrap's default is 40 characters.  And
  * you can turn off wordwrap by passing in 0.
  *
  * @access public
  * @return string
  * @param array $array PHP array
  * @param int $indent Pass in false to use the default, which is 2
  * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
  */
 function YAMLDump($array, $indent = false, $wordwrap = false, $ignore_private = false)
 {
     $spyc = new Spyc();
     return $spyc->dump($array, $indent, $wordwrap, $ignore_private);
 }
 /**
  * Write a state object to a file
  * 
  * @param object $state_obj
  * @param string $file
  */
 private function write_state_file($state_data, $file)
 {
     $spyc = new Spyc();
     $file_data = $spyc->dump($state_data, 2, 0);
     // $spyc->dump() prepends "---\n" :(
     $file_data = substr($file_data, 4);
     file_put_contents($file, $file_data);
 }
Exemple #10
0
 /**
  * write yaml from an array using the Spyc class
  * @param array $array array to YAMLize
  * @return string
  */
 public function dump($array)
 {
     return Spyc::dump($array);
 }
Exemple #11
0
 /**
  * Dump YAML from PHP array statically
  *
  * The dump method, when supplied with an array, will do its best
  * to convert the array into friendly YAML.  Pretty simple.  Feel free to
  * save the returned string as nothing.yaml and pass it around.
  *
  * Oh, and you can decide how big the indent is and what the wordwrap
  * for folding is.  Pretty cool -- just pass in 'false' for either if
  * you want to use the default.
  *
  * Indent's default is 2 spaces, wordwrap's default is 40 characters.  And
  * you can turn off wordwrap by passing in 0.
  *
  * @param [array]   $array    PHP array
  * @param [integer] $indent   Pass in false to use the default, which is 2
  * @param [integer] $wordwrap 0 for no wordwrap, false for default (40)
  * @return [string] $string
  */
 public static function yamlDump($array, $indent = false, $wordwrap = false)
 {
     $spyc = new Spyc();
     $string = $spyc->dump($array, $indent, $wordwrap);
     return $string;
 }
Exemple #12
0
 /**
  * Write the config array to a yaml file
  *
  * @param   string  The filename
  * @return array | boolean false
  * @todo fix this return true/false thingy
  */
 public static function writeConfig($file, array $array)
 {
     /**
      * transform PHP Array into YAML Format
      */
     // take syck, as the faster one first
     if (extension_loaded('syck')) {
         // convert to YAML via SYCK
         $yaml = syck_dump($data);
     } elseif (is_file(ROOT_LIBRARIES . '/spyc/Spyc.class.php') === true) {
         // ok, load spyc
         if (false === class_exists('Spyc', false)) {
             include ROOT_LIBRARIES . '/spyc/Spyc.class.php';
         }
         $spyc = new Spyc();
         // convert to YAML via SPYC
         $yaml = $spyc->dump($array);
     } else {
         // we have no YAML Parser - too bad :(
         throw new Koch_Exception('No YAML Parser available. Get Spyc or Syck!');
     }
     /**
      * write array
      */
     // write YAML content to file
     file_put_contents($file, $yaml);
 }