Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/grasmash/yaml-expander

Expands internal property references in a yaml file.
https://github.com/grasmash/yaml-expander

php yaml yml

Last synced: about 24 hours ago
JSON representation

Expands internal property references in a yaml file.

Awesome Lists containing this project

README

        

[![CI](https://github.com/grasmash/yaml-expander/actions/workflows/php.yml/badge.svg)](https://github.com/grasmash/yaml-expander/actions/workflows/php.yml) [![Packagist](https://img.shields.io/packagist/v/grasmash/yaml-expander.svg)](https://packagist.org/packages/grasmash/yaml-expander)
[![Total Downloads](https://poser.pugx.org/grasmash/yaml-expander/downloads)](https://packagist.org/packages/grasmash/yaml-expander) [![Coverage Status](https://coveralls.io/repos/github/grasmash/yaml-expander/badge.svg?branch=master)](https://coveralls.io/github/grasmash/yaml-expander?branch=master)

This tool expands property references in YAML files.

### Installation

composer require grasmash/yaml-expander

### Example usage:

Example dune.yml:

```yaml
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 `${}`.

Expansion logic:

```php
['publication-year' => 1965]];
$expanded = \Grasmash\YamlExpander\YamlExpander::expandArrayProperties($array, $reference_properties);
print_r($expanded);
````

Resultant array:

```php
'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',
);
```