https://github.com/steevanb/php-yaml
Add some features to symfony/yaml
https://github.com/steevanb/php-yaml
php symfony
Last synced: 10 months ago
JSON representation
Add some features to symfony/yaml
- Host: GitHub
- URL: https://github.com/steevanb/php-yaml
- Owner: steevanb
- Created: 2017-03-18T20:27:03.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-13T17:58:06.000Z (over 8 years ago)
- Last Synced: 2024-11-24T16:05:55.756Z (over 1 year ago)
- Topics: php, symfony
- Language: PHP
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
Awesome Lists containing this project
README
[](https://github.com/steevanb/php-yaml/tree/1.0.2)
[](https://github.com/symfony/yaml)


[](https://insight.sensiolabs.com/projects/00a42deb-03af-40da-a61f-b8abdd3a90b3/analyses/9)
[](https://scrutinizer-ci.com/g/steevanb/php-yaml/)
php-yaml
========
Add features to [symfony/yaml](https://github.com/symfony/yaml).
As _steevanb\PhpYaml\Parser_ extends _Symfony\Component\Yaml\Parser_,
you have all Symfony YAML parser features.
[Changelog](changelog.md)
Installation
------------
Use _composer require_ :
```bash
composer require steevanb/php-yaml ^1.0
```
Or add it manually to _composer.json_ :
```yaml
{
"require": {
"steevanb/php-yaml": "^1.0"
}
}
```
How to use
----------
Instead of calling _Symfony\Component\Yaml\Yaml::parse($content)_, you have to do this :
```php
use steevanb\PhpYaml\Parser;
$parser = new Parser();
$parser->parse(file_get_contents('foo.yml'));
```
Function support
----------------
You can call registered functions in yaml value :
````yaml
foo:
call_file_get_contents:
call_new_DateTime:
call_new_DateTime2:
````
By default, no function is registered into Parser. You need to manually register every function you need.
You can register __ function. _$path_ is _$fileName_ path prefix :
```php
steevanb\PhpYaml\Parser::registerFileFunction($path = null);
```
You can register __ function :
```php
steevanb\PhpYaml\Parser::registerDateFunction();
```
You can register your own function :
```php
steevanb\PhpYaml\Parser::registerFunction('foo', function($bar, $baz) {
return $bar + $baz;
});
```
And call it in yaml :
```yaml
foo:
bar:
```