85 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			85 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
namespace nur\mapper\json;
 | 
						|
 | 
						|
use nur\b\params\Tparametrable;
 | 
						|
use nur\mapper\base\Consumer;
 | 
						|
use nur\mapper\base\Ttmpwriter;
 | 
						|
use Symfony\Component\Yaml\Yaml;
 | 
						|
 | 
						|
/**
 | 
						|
 * Class YamlWriter
 | 
						|
 *
 | 
						|
 * --autogen-properties-and-methods--
 | 
						|
 * @method setOutput($value)
 | 
						|
 */
 | 
						|
class YamlWriter extends Consumer {
 | 
						|
  use Tparametrable, Ttmpwriter;
 | 
						|
 | 
						|
  function __construct($output=null) {
 | 
						|
    parent::__construct();
 | 
						|
    $this->pp_setOutput($output);
 | 
						|
  }
 | 
						|
 | 
						|
  const PARAMETRABLE_PARAMS_SCHEMA = [
 | 
						|
    "output" => [null, null, "fichier en sortie"],
 | 
						|
  ];
 | 
						|
 | 
						|
  protected function setup(): void {
 | 
						|
    parent::setup();
 | 
						|
    $this->setupWriter(false);
 | 
						|
    $this->firstObject = true;
 | 
						|
  }
 | 
						|
 | 
						|
  private $firstObject;
 | 
						|
 | 
						|
  function cook($item) {
 | 
						|
    $writer = $this->getWriter();
 | 
						|
 | 
						|
    if ($this->firstObject) $this->firstObject = false;
 | 
						|
    else $writer->wnl("---");
 | 
						|
 | 
						|
    $flags = Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK;
 | 
						|
    $writer->write(Yaml::dump($item, 20, 4, $flags));
 | 
						|
  }
 | 
						|
 | 
						|
  protected function teardown(): void {
 | 
						|
    $this->teardownWriter(false);
 | 
						|
  }
 | 
						|
 | 
						|
  #############################################################################
 | 
						|
  const _AUTOGEN_CONSTS = [
 | 
						|
    "" => [self::class, "_autogen_consts"],
 | 
						|
  ];
 | 
						|
  const _AUTOGEN_LITERALS = /*autogen*/[
 | 
						|
    [
 | 
						|
      \nur\b\params\parametrable_utils::class,
 | 
						|
      '\\nur\\b\\params\\parametrable_utils::class',
 | 
						|
    ],
 | 
						|
    [
 | 
						|
      self::PARAMETRABLE_PARAMS_SCHEMA,
 | 
						|
      'self::PARAMETRABLE_PARAMS_SCHEMA',
 | 
						|
    ],
 | 
						|
  ];
 | 
						|
  const _AUTOGEN_METHODS = /*autogen*/[
 | 
						|
    [
 | 
						|
      \nur\b\params\parametrable_utils::class,
 | 
						|
      '_autogen_methods_getters',
 | 
						|
      self::PARAMETRABLE_PARAMS_SCHEMA,
 | 
						|
      null,
 | 
						|
    ],
 | 
						|
    [
 | 
						|
      \nur\b\params\parametrable_utils::class,
 | 
						|
      '_autogen_methods_setters',
 | 
						|
      self::PARAMETRABLE_PARAMS_SCHEMA,
 | 
						|
      null,
 | 
						|
    ],
 | 
						|
  ];
 | 
						|
  const _AUTO_GETTERS = /*autogen*/[
 | 
						|
    'getOutput' => 'output',
 | 
						|
  ];
 | 
						|
  const _AUTO_SETTERS = /*autogen*/[
 | 
						|
    'setOutput' => 'output',
 | 
						|
  ];
 | 
						|
  #--autogen-dynamic--
 | 
						|
}
 |