On corrige la librairie sfyaml qui finalement ne supportait pas le paramétrage de l'indentation.

On copie le fonctionnement de symfony v4 et ça marche.
Donc on a plus de préfixe espaces sur chaque ligne (realet).
Reste à supprimer les open dashes de la chaine produite en YAML avec spyc et libyaml
svn/root/tags/v2.0.11
eric@smellup.net 5 years ago
parent 526ccc6326
commit 2474f6548e

@ -25,16 +25,16 @@ function sfyaml_yaml_encode($structure, $options = array()) {
// Traitement des options
if (empty($options['inline']) or (isset($options['inline']) and !is_int($options['inline']))) {
$options['inline'] = 2;
$options['inline'] = 3;
}
if (empty($options['indent']) or (isset($options['indent']) and !is_int($options['indent']))) {
$options['indent'] = 2;
}
// On crée l'objet de dump.
$yaml = new sfYamlDumper();
// On crée l'objet de dump avec le paramètre d'indentation.
$yaml = new sfYamlDumper($options['indent']);
return $yaml->dump($structure, $options['inline'], $options['indent']);
return $yaml->dump($structure, $options['inline']);
}

@ -26,7 +26,7 @@ function symfony_yaml_encode($structure, $options = array()) {
// Traitement des options du dump
if (empty($options['inline']) or (isset($options['inline']) and !is_int($options['inline']))) {
$options['inline'] = 2;
$options['inline'] = 3;
}
if (empty($options['indent']) or (isset($options['indent']) and !is_int($options['indent']))) {
$options['indent'] = 2;

@ -1,7 +1,7 @@
<paquet
prefix="yaml"
categorie="outil"
version="2.0.2"
version="2.0.3"
etat="test"
compatibilite="[3.0.0;3.2.*]"
logo="yaml.png"

@ -125,13 +125,13 @@ class sfYaml
*
* @return string A YAML string representing the original PHP array
*/
public static function dump($array, $inline = 2)
public static function dump($array, $inline = 2, $indent = 2)
{
require_once dirname(__FILE__).'/sfYamlDumper.php';
$yaml = new sfYamlDumper();
$yaml = new sfYamlDumper($indent);
return $yaml->dump($array, $inline);
return $yaml->dump($array, $inline, 0);
}
}

@ -20,12 +20,31 @@ require_once(dirname(__FILE__).'/sfYamlInline.php');
*/
class sfYamlDumper
{
protected $indentation;
/**
* Set indentation on creation.
* @fork correction pour coincider avec le fonctionnement de symfony v4
* pas de risque car cette librairie n'évoluera plus
*
* @param integer $indent The amount of spaces to use for indentation of nested nodes.
*/
public function __construct($indentation = 2)
{
if ($indentation < 1) {
$this->indentation = 2;
} else {
$this->indentation = $indentation;
}
}
/**
* Dumps a PHP value to YAML.
*
* @param mixed $input The PHP value
* @param integer $inline The level where you switch to inline YAML
* @param integer $indent The level o indentation indentation (used internally)
* @param integer $indent The level o indentation (used internally)
*
* @return string The YAML representation of the PHP value
*/
@ -50,7 +69,7 @@ class sfYamlDumper
$prefix,
$isAHash ? sfYamlInline::dump($key).':' : '-',
$willBeInlined ? ' ' : "\n",
$this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)
$this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation)
).($willBeInlined ? "\n" : '');
}
}

Loading…
Cancel
Save