2017 © Pedro Peláez
 

library yaml-expander

Expands internal property references in a yaml file.

image

grasmash/yaml-expander

Expands internal property references in a yaml file.

  • Friday, December 22, 2017
  • by grasmash
  • Repository
  • 0 Watchers
  • 69 Stars
  • 1,368,487 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 20 Versions
  • 26 % Grown

The README.md

Build Status Packagist Total Downloads Coverage Status, (*1)

This tool expands property references in YAML files., (*2)

Installation

composer require grasmash/yaml-expander

Example usage:

Example dune.yml:, (*3)

type: book
book:
  title: Dune
  author: Frank Herbert
  copyright: ${book.author} 1965
  protaganist: ${characters.0.name}
  media:
    - hardcover
characters:
  - name: Paul Atreides
    occupation: Kwisatz Haderach
    aliases:
      - Usul
      - Muad'Dib
      - The Preacher
  - name: Duncan Idaho
    occupation: Swordmaster
summary: ${book.title} by ${book.author}
product-name: ${${type}.title}
timezone: ${env.TZ}

Property references use dot notation to indicate array keys, and must be wrapped in ${}., (*4)

Expansion logic:, (*5)

<?php

// Set an environmental variable, accessible via ${env.TZ}.
putenv("TZ=ES");

// Parse a yaml string directly, expanding internal property references.
$yaml_string = file_get_contents("dune.yml");
$expanded = \Grasmash\YamlExpander\YamlExpander::parse($yaml_string);
print_r($expanded);

// Parse an array, expanding internal property references.
$array = \Symfony\Component\Yaml\Yaml::parse(file_get_contents("dune.yml"));
$expanded = \Grasmash\YamlExpander\YamlExpander::expandArrayProperties($array);
print_r($expanded);

// Parse an array, expanding references using both internal and supplementary values.
$array = \Symfony\Component\Yaml\Yaml::parse(file_get_contents("dune.yml"));
$reference_properties = ['book' => ['publication-year' => 1965]];
$expanded = \Grasmash\YamlExpander\YamlExpander::expandArrayProperties($array, $reference_properties);
print_r($expanded);
````

Resultant array:

```php
<?php

array (
  'type' => 'book',
  'book' => 
  array (
    'title' => 'Dune',
    'author' => 'Frank Herbert',
    'copyright' => 'Frank Herbert 1965',
    'protaganist' => 'Paul Atreides',
    'media' => 
    array (
      0 => 'hardcover',
    ),
  ),
  'characters' => 
  array (
    0 => 
    array (
      'name' => 'Paul Atreides',
      'occupation' => 'Kwisatz Haderach',
      'aliases' => 
      array (
        0 => 'Usul',
        1 => 'Muad\'Dib',
        2 => 'The Preacher',
      ),
    ),
    1 => 
    array (
      'name' => 'Duncan Idaho',
      'occupation' => 'Swordmaster',
    ),
  ),
  'summary' => 'Dune by Frank Herbert',
  'product-name' => 'Dune',
  'timezone' => 'ES',
);

The Versions

22/12 2017

dev-abstract-expander-logic

dev-abstract-expander-logic

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

16/12 2017

dev-master

9999999-dev

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

16/12 2017
16/12 2017

dev-issue-9-env-vars

dev-issue-9-env-vars

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

11/12 2017

dev-issue-8-key-expand

dev-issue-8-key-expand

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

08/12 2017
26/09 2017

1.2.0

1.2.0.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

26/09 2017

dev-expand-arrays

dev-expand-arrays

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

01/08 2017

dev-placeholders

dev-placeholders

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

01/08 2017

1.1.1

1.1.1.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

24/03 2017

1.x-dev

1.9999999.9999999.9999999-dev

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

24/03 2017

1.1.0

1.1.0.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

24/03 2017

2.0.0

2.0.0.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

21/03 2017

1.0.5

1.0.5.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

17/01 2017

1.0.4

1.0.4.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

16/01 2017

1.0.3

1.0.3.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

16/01 2017

1.0.2

1.0.2.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

16/01 2017

1.0.1

1.0.1.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

13/01 2017

1.0.0

1.0.0.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick

13/01 2017

0.1.0

0.1.0.0

Expands internal property references in a yaml file.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matthew Grasmick