https://github.com/xp-forge/yaml
YAML
https://github.com/xp-forge/yaml
parser xp-framework yaml
Last synced: 3 months ago
JSON representation
YAML
- Host: GitHub
- URL: https://github.com/xp-forge/yaml
- Owner: xp-forge
- Created: 2013-08-22T19:57:16.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2025-05-10T08:31:40.000Z (about 1 year ago)
- Last Synced: 2025-11-13T06:07:24.603Z (7 months ago)
- Topics: parser, xp-framework, yaml
- Language: PHP
- Size: 188 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
YAML parser
===========
[](https://github.com/xp-forge/yaml/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](https://packagist.org/packages/xp-forge/yaml)
* See https://yaml.org/
* See https://yaml.org/spec/1.2.2/
* See https://yaml.org/type/merge.html
Usage example
-------------
```php
use org\yaml\{YamlParser, FileInput};
$result= (new YamlParser())->parse(new FileInput('.travis.yml'));
// [
// language => "php"
// php => [7, 7.1, 7.2, 7.3, 7.4, "nightly"]
// matrix => [
// allow_failures => [[
// php => "nightly"
// ]]
// ]
// before_script => ["curl ...", ...]
// script => ["sh xp-run xp.unittest.TestRunner src/test/php"]
// ]
```
Inputs
------
* `org.yaml.FileInput(io.File|string $in)` - Use file instance or a file name
* `org.yaml.ReaderInput(io.streams.TextReader $in)` - Reads from a text reader
* `org.yaml.StringInput(string $in)` - Input from a string
Multiple documents
------------------
YAML sources can contain more than one document. The `parse()` method will only parse the first (or only) document. To retrieve all documents in a given input, use the iterator returned by `documents()` instead.
```php
use org\yaml\{YamlParser, FileInput};
use util\cmd\Console;
$parser= new YamlParser();
foreach ($parser->documents(new FileInput('objects.yml')) as $i => $document) {
Console::writeLine('Document #', $i, ': ', $document);
}
```