symplely/yaml

A Async simple YAML loader/dumper class for PHP

1.0.1 2019-09-19 21:31 UTC

This package is auto-updated.

Last update: 2024-10-29 05:34:43 UTC


README

Build StatusBuild statuscodecovCodacy BadgeMaintainability

An pure PHP implementation base YAML loader/dumper.

  • Given a YAML document, will return an array that you can use however you see fit.

  • Given an array, will return a string which contains a YAML document built from your data.

YAML is an amazingly human friendly and strikingly versatile data serialization language which can be used for log files, config files, custom protocols, the works. For more information, see http://www.yaml.org.

Supporting YAML 1.1 specification.

Installation

composer require symplely/yaml

Usage

Using Yaml is trivial:

The parse() or loader() method parses a YAML string and converts it to a PHP array:

require 'vendor/autoload.php';

use Async\Yaml;

 // Reading YAML Contents
$Data = Yaml::loader('config.yaml');
// Or
$Data = Yaml::parse("foo: bar");
// Or
$Data = yaml_load("foo: bar");
// $Data = ['foo' => 'bar']

or (if you prefer functional syntax)

require 'vendor/autoload.php';

$Data = yaml_load_file('config.yaml');

The dumper() method dumps any PHP array to its YAML representation:

require 'vendor/autoload.php';

use Async\Yaml;

$array = [
    'foo' => 'bar',
    'bar' => ['foo' => 'bar','bar' => 'baz'],
];

$yaml = Yaml::dumper($array);
// Or
$yaml = yaml_dump($array);

// Writing YAML Files
file_put_contents('/path/to/file.yaml', $yaml);