Documentation

Yaml
in package

Yaml offers convenience methods to load and dump YAML.

Tags
author

Fabien Potencier fabien@symfony.com

final

Table of Contents

Constants

DUMP_COMPACT_NESTED_MAPPING  : mixed = 16384
DUMP_EMPTY_ARRAY_AS_SEQUENCE  : mixed = 1024
DUMP_EXCEPTION_ON_INVALID_TYPE  : mixed = 16
DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES  : mixed = 32768
DUMP_MULTI_LINE_LITERAL_BLOCK  : mixed = 128
DUMP_NULL_AS_EMPTY  : mixed = 8192
DUMP_NULL_AS_TILDE  : mixed = 2048
DUMP_NUMERIC_KEY_AS_STRING  : mixed = 4096
DUMP_OBJECT  : mixed = 1
DUMP_OBJECT_AS_MAP  : mixed = 64
PARSE_CONSTANT  : mixed = 256
PARSE_CUSTOM_TAGS  : mixed = 512
PARSE_DATETIME  : mixed = 32
PARSE_EXCEPTION_ON_ALIAS  : mixed = 65536
PARSE_EXCEPTION_ON_INVALID_TYPE  : mixed = 2
PARSE_OBJECT  : mixed = 4
PARSE_OBJECT_FOR_MAP  : mixed = 8

Methods

dump()  : string
Dumps a PHP value to a YAML string.
parse()  : mixed
Parses YAML into a PHP value.
parseFile()  : mixed
Parses a YAML file into a PHP value.

Constants

DUMP_COMPACT_NESTED_MAPPING

public mixed DUMP_COMPACT_NESTED_MAPPING = 16384

DUMP_EMPTY_ARRAY_AS_SEQUENCE

public mixed DUMP_EMPTY_ARRAY_AS_SEQUENCE = 1024

DUMP_EXCEPTION_ON_INVALID_TYPE

public mixed DUMP_EXCEPTION_ON_INVALID_TYPE = 16

DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES

public mixed DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES = 32768

DUMP_MULTI_LINE_LITERAL_BLOCK

public mixed DUMP_MULTI_LINE_LITERAL_BLOCK = 128

DUMP_NULL_AS_EMPTY

public mixed DUMP_NULL_AS_EMPTY = 8192

DUMP_NULL_AS_TILDE

public mixed DUMP_NULL_AS_TILDE = 2048

DUMP_NUMERIC_KEY_AS_STRING

public mixed DUMP_NUMERIC_KEY_AS_STRING = 4096

DUMP_OBJECT

public mixed DUMP_OBJECT = 1

DUMP_OBJECT_AS_MAP

public mixed DUMP_OBJECT_AS_MAP = 64

PARSE_CONSTANT

public mixed PARSE_CONSTANT = 256

PARSE_CUSTOM_TAGS

public mixed PARSE_CUSTOM_TAGS = 512

PARSE_DATETIME

public mixed PARSE_DATETIME = 32

PARSE_EXCEPTION_ON_ALIAS

public mixed PARSE_EXCEPTION_ON_ALIAS = 65536

PARSE_EXCEPTION_ON_INVALID_TYPE

public mixed PARSE_EXCEPTION_ON_INVALID_TYPE = 2

PARSE_OBJECT

public mixed PARSE_OBJECT = 4

PARSE_OBJECT_FOR_MAP

public mixed PARSE_OBJECT_FOR_MAP = 8

Methods

dump()

Dumps a PHP value to a YAML string.

public static dump(mixed $input[, int $inline = 2 ][, int $indent = 4 ][, int-mask-of $flags = 0 ]) : string

The dump method, when supplied with an array, will do its best to convert the array into friendly YAML.

Parameters
$input : mixed

The PHP value

$inline : int = 2

The level where you switch to inline YAML

$indent : int = 4

The amount of spaces to use for indentation of nested nodes

$flags : int-mask-of = 0

A bit field of DUMP_* constants to customize the dumped YAML string

Return values
string

parse()

Parses YAML into a PHP value.

public static parse(string $input[, int-mask-of $flags = 0 ][, int $maxNestingLevel = Parser::DEFAULT_MAX_NESTING_LEVEL ][, int $maxAliasesForCollections = Parser::DEFAULT_MAX_ALIASES_FOR_COLLECTIONS ]) : mixed

Usage: $array = Yaml::parse(file_get_contents('config.yml')); print_r($array);

Parameters
$input : string

A string containing YAML

$flags : int-mask-of = 0

A bit field of PARSE_* constants to customize the YAML parser behavior

$maxNestingLevel : int = Parser::DEFAULT_MAX_NESTING_LEVEL

The maximum nesting depth for nested YAML blocks

$maxAliasesForCollections : int = Parser::DEFAULT_MAX_ALIASES_FOR_COLLECTIONS

The maximum number of collection aliases to resolve

Tags
throws
ParseException

If the YAML is not valid

parseFile()

Parses a YAML file into a PHP value.

public static parseFile(string $filename[, int-mask-of $flags = 0 ][, int $maxNestingLevel = Parser::DEFAULT_MAX_NESTING_LEVEL ][, int $maxAliasesForCollections = Parser::DEFAULT_MAX_ALIASES_FOR_COLLECTIONS ]) : mixed

Usage:

$array = Yaml::parseFile('config.yml'); print_r($array);

Parameters
$filename : string

The path to the YAML file to be parsed

$flags : int-mask-of = 0

A bit field of PARSE_* constants to customize the YAML parser behavior

$maxNestingLevel : int = Parser::DEFAULT_MAX_NESTING_LEVEL

The maximum nesting depth for nested YAML blocks

$maxAliasesForCollections : int = Parser::DEFAULT_MAX_ALIASES_FOR_COLLECTIONS

The maximum number of collection aliases to resolve

Tags
throws
ParseException

If the file could not be read or the YAML is not valid

On this page

Search results