klausi / yaml_comments
YAML parser that also reads/writes comment lines
Installs: 1 340
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 1
Open Issues: 1
Requires
- php: >=5.5
Requires (Dev)
- phpunit/phpunit: >=4 <6
- squizlabs/php_codesniffer: >=2
- symfony/yaml: >=3
This package is not auto-updated.
Last update: 2022-02-01 13:06:07 UTC
README
Parses YAML and provides comments with their line numbers as well as the line number of any given key of the document structure.
The parser was copied and modified from the Symfony YAML component, MIT license Copyright (c) 2004-2017 Fabien Potencier
Usage
use Klausi\YamlComments\YamlComments; $exampleYaml = <<<'EOF' name: Node type: module # Messing up line numbers with comments, yay! description: 'Allows content to be submitted to the site and displayed on pages.' package: Core version: VERSION core: 8.x configure: entity.node_type.collection dependencies: - text - drupal:rest - views # Some comment here. - rules EOF; $parseResult = YamlComments::parse($exampleYaml);
Get the comment lines of this document:
print_r($parseResult->getComments());
Array
(
[3] => # Messing up line numbers with comments, yay!
[13] => # Some comment here.
)
Get the line number of a particular key:
print $parseResult->getLineNumber('name'); 1 print $parseResult->getLineNumber('description'); 4 print $parseResult->getLineNumber(['dependencies', 3]); 14