• Stars
    star
    154
  • Rank 241,390 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Expands internal property references in a yaml file.

CI Packagist Total Downloads Coverage Status

This tool expands property references in YAML files.

Installation

composer require grasmash/yaml-expander

Example usage:

Example dune.yml:

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

// 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

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

More Repositories

1

expander

This tool expands property references in PHP arrays.
PHP
136
star
2

composerize-drupal

Convert a non-Composer-managed Drupal application (e.g., one created via tarball) to a Composer-managed Drupal application.
PHP
125
star
3

yaml-cli

A command line tool for reading and manipulating yaml files.
PHP
22
star
4

xdebug-toggle

Simple CLI tools to toggle xdebug easily.
PHP
16
star
5

drupal8to9-upgrade

PHP
12
star
6

drupal-issue-chrome

A chrome extension that renders links to Drupal.org issues based on issue status.
JavaScript
8
star
7

drupal-security-warning

PHP
7
star
8

drupal-composer-training

How to build a Drupal site with Composer AND keep all of your hair! DrupalCon Nashville 2018
6
star
9

drupal-views-itunes-rss

Drupal 8 module for providing <itunes:*> tags via Views RSS.
PHP
6
star
10

project-browser

A project browser embedded in the Drupal UI.
JavaScript
6
star
11

drupal-usasearch

The USASearch module for Drupal.
PHP
5
star
12

composer-scaffold

Allows Composer to copy files around after package installation.
PHP
5
star
13

drupal-module-evaluator

PHP
4
star
14

symfony-console-checklist

A utility for creating animated spinners via Symfony Console.
PHP
2
star
15

drupal7-starter-kit

1
star
16

drupal-table-of-contents

Fork of table_of_contents module.
1
star
17

migrate_html

Example module for migrating static HTML to Drupal
PHP
1
star
18

transcript-analyzer

PHP
1
star
19

artifice

PHP
1
star
20

Fivestar-Node-Settings-Patch

Patch for Drupal 6's Fivestar module-- will allow enabling/disabing fivestar for specific nodes
JavaScript
1
star
21

drupal-gov-features

An assortment of Drupal features for government websites.
HTML
1
star
22

drupal-og-fpp

Organic Groups Fieldable Panels Panes
PHP
1
star