Add features to symfony/yaml.
As steevanb\PhpYaml\Parser extends Symfony\Component\Yaml\Parser, you have all Symfony YAML parser features.
Use composer require :
composer require steevanb/php-yaml ^1.0
Or add it manually to composer.json :
{
"require": {
"steevanb/php-yaml": "^1.0"
}
}
Instead of calling Symfony\Component\Yaml\Yaml::parse($content), you have to do this :
use steevanb\PhpYaml\Parser;
$parser = new Parser();
$parser->parse(file_get_contents('foo.yml'));
You can call registered functions in yaml value :
foo:
call_file_get_contents: <file('baz.txt')>
call_new_DateTime: <date()>
call_new_DateTime2: <date('2017-12-31')>
By default, no function is registered into Parser. You need to manually register every function you need.
You can register <file($fileName)> function. $path is $fileName path prefix :
steevanb\PhpYaml\Parser::registerFileFunction($path = null);
You can register <date($format = null)> function :
steevanb\PhpYaml\Parser::registerDateFunction();
You can register your own function :
steevanb\PhpYaml\Parser::registerFunction('foo', function($bar, $baz) {
return $bar + $baz;
});
And call it in yaml :
foo:
bar: <foo(41, 1)>