2017 © Pedro Peláez
 

library yamlarh

Inject data and import other formatted file into your formatted file.

image

arhframe/yamlarh

Inject data and import other formatted file into your formatted file.

  • Saturday, September 19, 2015
  • by arhframe
  • Repository
  • 1 Watchers
  • 2 Stars
  • 20,355 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 17 Versions
  • 6 % Grown

The README.md

Yamlarh

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight, (*1)

Yamlarh is now just a name, with this tool you can inject complex data or other formatted files in a formatted file (as json, xml or yaml)., (*2)

You can inject into your formatted file: * object * constant from scope * Variable from global scope * Variable from formatted file, (*3)

You can also import other formatted file inside a formatted file file for overriding, (*4)

Installation

Through Composer, obviously:, (*5)

{
    "require": {
        "arhframe/yamlarh": "1.*"
    }
}

Usage

use Arhframe\Yamlarh\Yamlarh;

$yamlarh = new Yamlarh(__DIR__.'/path/to/formatted/file');
$array = $yamlarh->parse();

Exemple

Variable injection

Variable injection is hierarchical, it will find in this order: 1. In the yaml file with import 2. In your global scope 3. In your constants 4. In accessible variables set in yamlarh, (*6)

Yaml file:, (*7)

arhframe:
  myvar1: test
  myvar2: %arhframe.myvar1%
  myvar3: %var3%
  myvar4: %VARCONSTANT%
  myvar5: %addedInYamlarh%

Or in xml:, (*8)

<?xml version="1.0" encoding="UTF-8" ?>
<yamlarh>
    <arhframe>
        <myvar1>test</myvar1>
        <myvar2>%arhframe.myvar1%</myvar2>
        <myvar3>%var3%</myvar3>
        <myvar4>%VARCONSTANT%</myvar4>
        <myvar5>%addedInYamlarh%</myvar5>
    </arhframe>
</yamlarh>

Or in json:, (*9)

{
  "arhframe": {
    "myvar1": "test",
    "myvar2": "%arhframe.myvar1%",
    "myvar3": "%var3%",
    "myvar4": "%VARCONSTANT%",
    "myvar5": "%addedInYamlarh%"
  }
}

Php file:, (*10)

use Arhframe\Yamlarh\Yamlarh;
$var3 = 'testvar';
define('VARCONSTANT', 'testconstant');
$yamlarh = new Yamlarh(__DIR__.'/test.yml');
$yamlarh->addAccessibleVariable("addedInYamlarh", "var added");
$array = $yamlarh->parse();
echo print_r($array);

Output:, (*11)

  Array
  (
      [arhframe] => Array
          (
              [myvar1] => test
              [myvar2] => test
              [myvar3] => testvar
              [myvar4] => testconstant
              [myvar5] => var added
          )
  )

Object injection

It use snakeyml (yaml parser for java) style:, (*12)

arhframe:
  file: !! Arhframe.Util.File(test.php) #will instanciate this: Arhframe\Util\File('test.php') in file var after parsing

Import

Import are also hierarchical the last one imported will override the others., (*13)

Use yar-import by default in your file:, (*14)

file1.xml, (*15)

<?xml version="1.0" encoding="UTF-8" ?>
<yamlarh>
    <arhframe>
        <var1>var</var1>
    </arhframe>
    <test>arhframe</test>
    <yar-import>file2.yml</yar-import> <!-- you can use a relative path to your yaml file or an absolute -->
</yamlarh>

file2.yml, (*16)

arhframe:
  var1: varoverride
test2: var3

After parsing file1.xml, output will look like (just to have a better format it's show yml):, (*17)

arhframe:
  var1: varoverride
test: arhframe
test2: var3

Include

You can include a yaml file into another:, (*18)

file1.yml, (*19)

arhframe:
  var1: var
test:
  yar-include:
    - file2.yml #you can use a relative path to your yaml file or an absolute

file2.yml, (*20)

test2: var3

After parsing file1.yml, output will look like:, (*21)

arhframe:
  var1: var
test:
  test2: var3

Note: You can look at these tests to know what you can also do., (*22)

Extensible

Add a node

After parsing and importing but before injecting yamlarh can run your extension., (*23)

You have to create a new class which extends Arhframe\Yamlarh\YamlarhNode and add it to your yamlarh instance like this:, (*24)

//create your yamalarh instance before
$yamlarh->addNode("myNodeName", new MyYamlarhNode());

Now you can use (for this example) yar-myNodeName in your formated file., (*25)

Note: the yar-include is a node take look at IncludeYamlarhNode to have a good example., (*26)

The Versions

19/09 2015

dev-master

9999999-dev https://github.com/arhframe/yamlarh

Inject data and import other formatted file into your formatted file.

  Sources   Download

MIT

The Requires

 

The Development Requires

framework yaml injector arhframe inject

19/09 2015

1.1.19

1.1.19.0 https://github.com/arhframe/yamlarh

Inject data and import other formatted file into your formatted file.

  Sources   Download

MIT

The Requires

 

The Development Requires

framework yaml injector arhframe inject

01/06 2015

1.1.18

1.1.18.0 https://github.com/arhframe/yamlarh

Inject data and import other formatted file into your formatted file.

  Sources   Download

MIT

The Requires

 

The Development Requires

framework yaml injector arhframe inject

21/03 2015

1.1.17

1.1.17.0 https://github.com/arhframe/yamlarh

Inject data and import other formatted file into your formatted file.

  Sources   Download

MIT

The Requires

 

The Development Requires

framework yaml injector arhframe inject

18/03 2015

1.1.16

1.1.16.0 https://github.com/arhframe/yamlarh

Inject data and import other formatted file into your formatted file.

  Sources   Download

MIT

The Requires

 

The Development Requires

framework yaml injector arhframe inject

17/03 2015

1.1.15

1.1.15.0 https://github.com/arhframe/yamlarh

Inject data and import other formatted file into your formatted file.

  Sources   Download

MIT

The Requires

 

The Development Requires

framework yaml injector arhframe inject

14/03 2015

1.1.9

1.1.9.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

14/03 2015

1.1.8

1.1.8.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

14/03 2015

1.1.7

1.1.7.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

08/03 2015

1.1.5

1.1.5.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

06/09 2014

1.1.4

1.1.4.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

09/07 2014

1.1.3

1.1.3.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

29/06 2014

1.1.2

1.1.2.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

29/06 2014

1.1.1

1.1.1.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

11/04 2014

1.1.0

1.1.0.0 https://github.com/arhframe/yamlarh

Inject data and import other yaml file into your yaml file.

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

27/01 2014

1.0.1

1.0.1.0 https://github.com/arhframe/yamlarh

Yml injector for arhframe in standalone

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject

27/01 2014

1.0

1.0.0.0 https://github.com/arhframe/yamlarh

Yml injector for arhframe in standalone

  Sources   Download

MIT

The Requires

 

framework yaml injector arhframe inject