Download the PHP package purrphp/yaml without Composer
On this page you can find all versions of the php package purrphp/yaml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package yaml
Short Description YAML utilities for PHP
License MIT
Homepage https://github.com/PurrPHP/yaml
Informations about the package yaml
PurrPHP/Yaml
An object oriented YAML 1.2 parser for PHP 8.3+.
Every part of a YAML source is a class: the stream, its documents and each node
(scalar, sequence, mapping, alias) keeps its style, tag, anchor and source line.
Anchors and references (&anchor, *alias, <<:) are first class citizens — an
alias node links to the very node it points at instead of a copy of its value.
Installation
Entry points
YamlStream works with any number of documents in a source. YamlStreamSingle
expects exactly one document and throws InvalidDocumentsCountException otherwise.
Parsing to PHP values
With a single-document source, YamlStreamSingle is a shorter alternative:
Working with the model
fromString() returns a DocumentList — the parsed model instead of plain arrays:
| Class | Represents |
|---|---|
DocumentList |
all documents of one source |
Document |
one document plus its anchors |
ScalarNode |
a scalar, with its ScalarStyle |
SequenceNode |
a block or flow sequence |
MappingNode / MappingEntry |
a block or flow mapping and its pairs |
AliasNode |
a *reference linked to its anchored node |
Tag |
!!str, !custom, … |
Dumping back to YAML
The dumper turns the document model back into YAML text, preserving styles, tags and anchors:
References
Merge keys behave as the YAML spec describes: the merging mapping wins over the
merged one, and when several sources are merged (<<: [*a, *b]) the first one wins.
The links themselves stay visible in the model:
Visiting nodes
Nodes accept any NodeVisitor, which makes it easy to build your own
transformation instead of going through arrays:
Scalar typing is driven by a Schema. CoreSchema implements the YAML 1.2 core
schema; pass your own to the YamlStream constructor (or straight to Document::getValue())
to change how scalars become PHP values:
Supported syntax
YAML 1.2 only. Sources with a %YAML directive must declare version 1.2;
other versions (such as 1.1) are rejected. Scalar typing follows the YAML 1.2 core
schema (true/false, not yes/no).
Block and flow collections, plain, single and double quoted scalars (with escape
sequences), literal | and folded > block scalars with indentation and chomping
indicators, multi line plain scalars, comments, multiple documents (---, ...),
directives, anchors, aliases, merge keys and tags (!!str, !!int, !!float,
!!bool, !!null, !!binary, plus custom tags kept on the node).
Not supported: explicit keys (? key), verbose tag resolution against %TAG
directives, and recursive anchors.
Errors
Every failure implements Purr\Yaml\Exception\YamlException:
ParseException (with the offending line), ReferenceException (undefined anchor
or unmergeable value), ValueException (a collection used as a mapping key),
InvalidDocumentsCountException (when YamlStreamSingle sees other than one document),
and IoException.
Development
With Docker / Make
License
MIT — see LICENSE.