2017 © Pedro Peláez
 

library variator

Utils for generating arrays of data combinations

image

coshi/variator

Utils for generating arrays of data combinations

  • Wednesday, August 24, 2016
  • by kozog
  • Repository
  • 8 Watchers
  • 0 Stars
  • 2,961 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

A simple library to generate arrays of values combinations.

Usage:, (*1)

    $factory = new VariationFactory();
    $builder = new VariationsTreeBuilder($factory);

    $config = [
        'text' => [
            'type' => 'enum',
            'values' => ['first', 'second', 'third'],
        ],
    ];
    $variations = $builder->build($config);

    foreach ($variations as $values) {
        foreach($values as $value) {
            print($value); // displays first, second, third            
        }
    }

More complex:, (*2)

    $factory = new VariationFactory();
    $builder = new VariationsTreeBuilder($factory);

    $config = [
        'text' => [
            'type' => 'enum',
            'values' => ['first', 'second', 'third'],
        ],
        'number' => [
            'type' => 'int',
            'min' => 0,
            'max' => 2
        ],
    ];
    $variations = $builder->build($config);

    foreach ($variations as $values) {
        echo sprintf('text: %s, number: %d', $values['text'], $values['number']);
        echo PHP_EOL;
    }

Output will be:, (*3)

    text: first, number: 0
    text: second, number: 0
    text: third, number: 0
    text: first, number: 1
    text: second, number: 1
    text: third, number: 1
    text: first, number: 2
    text: second, number: 2
    text: third, number: 2

It can call methods and functions in order to get values:, (*4)

    class DummyClass
    {
        public function someValues()
        {
            return [0, 1, 2];
        }
    }
    $factory = new VariationFactory();
    $builder = new VariationsTreeBuilder($factory);

    $config = [
        'text' => [
            'type' => 'enum',
            'values' => ['first', 'second', 'third'],
        ],
        'number' => [
            'type' => 'callback',
            'callback' => [DummyClass::class, 'someValues']
        ],
    ];
    $variations = $builder->build($config);

    foreach ($variations as $values) {
        echo sprintf('text: %s, number: %d', $values['text'], $values['number']);
        echo PHP_EOL;
    }

Result will be exactly the same as from the previous one. Result will be the same for callback defined as '['range', [0, 2]]'., (*5)

Supports cross-referencing between variations:, (*6)

    class DummyClass
    {
        public function someValues($text)
        {
            $values = [
                'first' => [0, 1],
                'second' => [2, 3],
                'third' => [4, 5],
            ];

            return $values[$text];
        }
    }
    $factory = new VariationFactory();
    $builder = new VariationsTreeBuilder($factory);

    $config = [
        'text' => [
            'type' => 'enum',
            'values' => ['first', 'second', 'third'],
        ],
        'number' => [
            'type' => 'callback',
            'callback' => [DummyClass::class, 'someValues', ['@text']],
            'context_dependent' => true
        ],
    ];
    $variations = $builder->build($config);

    foreach ($variations as $values) {
        echo sprintf('text: %s, number: %d', $values['text'], $values['number']);
        echo PHP_EOL;
    }

Output will be:, (*7)

    text: first, number: 0
    text: first, number: 1
    text: second, number: 2
    text: second, number: 3
    text: third, number: 4
    text: third, number: 5

The Versions

24/08 2016

dev-master

9999999-dev

Utils for generating arrays of data combinations

  Sources   Download

MIT

The Requires

  • php 7.*

 

24/08 2016

v0.0.2

0.0.2.0

Utils for generating arrays of data combinations

  Sources   Download

MIT

The Requires

  • php 7.*

 

23/08 2016

v0.0.1

0.0.1.0

Utils for generating arrays of data combinations

  Sources   Download

MIT

The Requires

  • php 7.*