steevanb/php-yaml

Add some features to symfony/yaml

Installs: 1 509

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 2

Open Issues: 0

Type:lib

1.0.2 2018-02-13 17:57 UTC

This package is auto-updated.

Last update: 2024-10-28 12:03:56 UTC


README

version symfony Lines Total Downloads SensionLabsInsight Scrutinizer

php-yaml

Add features to symfony/yaml.

As steevanb\PhpYaml\Parser extends Symfony\Component\Yaml\Parser, you have all Symfony YAML parser features.

Changelog

Installation

Use composer require :

composer require steevanb/php-yaml ^1.0

Or add it manually to composer.json :

{
    "require": {
        "steevanb/php-yaml": "^1.0"
    }
}

How to use

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'));

Function support

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)>