Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Variator Laravel Package

coshi/variator

Generate all combinations of parameter values from a simple config array. Supports enums, integer ranges, callbacks/functions, and cross-referenced variations between fields. Iterate results as arrays keyed by parameter name for easy testing or data generation.

View on GitHub
Deep Wiki
Context7

A simple library to generate arrays of values combinations.

Usage:

    $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:

    $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:

    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:

    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]]'.

Supports cross-referencing between variations:

    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:

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

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator