Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/grasmash/yaml-expander
- Owner: grasmash
- License: mit
- Created: 2017-01-12T20:14:23.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-05-05T19:19:21.000Z (8 months ago)
- Last Synced: 2024-12-22T19:13:36.210Z (8 days ago)
- Topics: php, yaml, yml
- Language: PHP
- Size: 200 KB
- Stars: 152
- Watchers: 3
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
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',
);
```