3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Config\Writer
;
12 use Zend\Config\Exception
;
14 class Yaml
extends AbstractWriter
17 * YAML encoder callback
21 protected $yamlEncoder;
26 * @param callable|string|null $yamlEncoder
28 public function __construct($yamlEncoder = null)
30 if ($yamlEncoder !== null) {
31 $this->setYamlEncoder($yamlEncoder);
33 if (function_exists('yaml_emit')) {
34 $this->setYamlEncoder('yaml_emit');
40 * Get callback for decoding YAML
44 public function getYamlEncoder()
46 return $this->yamlEncoder
;
50 * Set callback for decoding YAML
52 * @param callable $yamlEncoder the decoder to set
54 * @throws Exception\InvalidArgumentException
56 public function setYamlEncoder($yamlEncoder)
58 if (!is_callable($yamlEncoder)) {
59 throw new Exception\
InvalidArgumentException('Invalid parameter to setYamlEncoder() - must be callable');
61 $this->yamlEncoder
= $yamlEncoder;
66 * processConfig(): defined by AbstractWriter.
68 * @param array $config
70 * @throws Exception\RuntimeException
72 public function processConfig(array $config)
74 if (null === $this->getYamlEncoder()) {
75 throw new Exception\
RuntimeException("You didn't specify a Yaml callback encoder");
78 $config = call_user_func($this->getYamlEncoder(), $config);
79 if (null === $config) {
80 throw new Exception\
RuntimeException("Error generating YAML data");