Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / grasmash / yaml-expander / README.md
1 [![Build Status](https://travis-ci.org/grasmash/yaml-expander.svg?branch=master)](https://travis-ci.org/grasmash/yaml-expander) [![Packagist](https://img.shields.io/packagist/v/grasmash/yaml-expander.svg)](https://packagist.org/packages/grasmash/yaml-expander)
2 [![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)
3
4 This tool expands property references in YAML files.
5
6 ### Installation
7
8     composer require grasmash/yaml-expander
9
10 ### Example usage:
11
12 Example dune.yml:
13
14 ```yaml
15 type: book
16 book:
17   title: Dune
18   author: Frank Herbert
19   copyright: ${book.author} 1965
20   protaganist: ${characters.0.name}
21   media:
22     - hardcover
23 characters:
24   - name: Paul Atreides
25     occupation: Kwisatz Haderach
26     aliases:
27       - Usul
28       - Muad'Dib
29       - The Preacher
30   - name: Duncan Idaho
31     occupation: Swordmaster
32 summary: ${book.title} by ${book.author}
33 product-name: ${${type}.title}
34 ```
35
36 Property references use dot notation to indicate array keys, and must be wrapped in `${}`.
37
38 Expansion logic:
39
40 ```php
41 <?php
42
43 // Parse a yaml string directly, expanding internal property references.
44 $yaml_string = file_get_contents("dune.yml");
45 $expanded = \Grasmash\YamlExpander\Expander::parse($yaml_string);
46 print_r($expanded);
47
48 // Parse an array, expanding internal property references.
49 $array = \Symfony\Component\Yaml\Yaml::parse(file_get_contents("dune.yml"));
50 $expanded = \Grasmash\YamlExpander\Expander::expandArrayProperties($array);
51 print_r($expanded);
52
53 // Parse an array, expanding references using both internal and supplementary values.
54 $array = \Symfony\Component\Yaml\Yaml::parse(file_get_contents("dune.yml"));
55 $reference_properties = ['book' => ['publication-year' => 1965]];
56 $expanded = \Grasmash\YamlExpander\Expander::expandArrayProperties($array, $reference_properties);
57 print_r($expanded);
58 ````
59
60 Resultant array:
61
62 ```php
63 <?php
64
65 array (
66   'type' => 'book',
67   'book' => 
68   array (
69     'title' => 'Dune',
70     'author' => 'Frank Herbert',
71     'copyright' => 'Frank Herbert 1965',
72     'protaganist' => 'Paul Atreides',
73     'media' => 
74     array (
75       0 => 'hardcover',
76     ),
77   ),
78   'characters' => 
79   array (
80     0 => 
81     array (
82       'name' => 'Paul Atreides',
83       'occupation' => 'Kwisatz Haderach',
84       'aliases' => 
85       array (
86         0 => 'Usul',
87         1 => 'Muad\'Dib',
88         2 => 'The Preacher',
89       ),
90     ),
91     1 => 
92     array (
93       'name' => 'Duncan Idaho',
94       'occupation' => 'Swordmaster',
95     ),
96   ),
97   'summary' => 'Dune by Frank Herbert',
98   'product-name' => 'Dune',
99 );
100 ```