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"]
// ]
org.yaml.FileInput(io.File|string $in)
- Use file instance or a file nameorg.yaml.ReaderInput(io.streams.TextReader $in)
- Reads from a text readerorg.yaml.StringInput(string $in)
- Input from a string
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.
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);
}