class YAML (View source)

The GenericDatabase\Helpers\Parsers\YAML class provides validation and parsing functionalities for YAML strings.

It contains two static methods: isValidYAML and parseYAML.

Example Usage:

// Validate a YAML string
$yaml = 'example.yaml';
$isValidYAML = \GenericDatabase\Helpers\YAML::isValidYAML($yaml);

$isValidYAML will be true if the YAML string is valid, false otherwise

// Parse a YAML string
$value = 'true';
$yaml = 'example.yaml';
$parsedYAML = \GenericDatabase\Helpers\YAML::parseYAML($yaml);

$parsedYAML will be an array containing the parsed YAML data

Main functionalities:

  • The isValidYAML method checks if a YAML string is valid by verifying that it is a string and ends with the extension '.yaml'. It also uses the yaml_parse_file function to further validate the YAML syntax.
  • The parseYAML method parses a valid YAML string by using the yaml_parse_file function and returns the parsed data as an array.

Methods:

  • isValidYAML(mixed $yaml): bool: Checks if a YAML string is valid.
  • parseYAML(string $yaml): array: Parses a valid YAML string and returns the parsed data as an array.

Methods

static bool
isValidYAML(mixed $yaml)

Check if yaml string is valid

static array
parseYAML(string $yaml)

Parse a valid yaml string

Details

static bool isValidYAML(mixed $yaml)

Check if yaml string is valid

Parameters

mixed $yaml

Argument to be tested

Return Value

bool

static array parseYAML(string $yaml)

Parse a valid yaml string

Parameters

string $yaml

Argument to be parsed

Return Value

array