Elao/ElaoParameterizer

Name: ElaoParameterizer

Owner: Elao

Description: null

Created: 2014-07-01 14:30:41.0

Updated: 2014-07-01 14:35:00.0

Pushed: 2014-07-03 09:07:50.0

Homepage: null

Size: 220

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ElaoParameterizer

Latest Stable Version Total Downloads Latest Unstable Version License

Build Status Scrutinizer Code Quality Code Coverage

Description:

This component provides a set of classes to handle some service parameters in a structured way, and a twig dat.GUI extension to set them with style.

A symfony ElaoParameterizerBundle also exists to simplify integration in your project.

Installation:

Add ElaoParameterizer in your composer.json:


"require": {
    "elao/elao/parameterizer": "1.0.*"
}

Now tell composer to download the library by running the command:

p composer.phar update elao/parameterizer
How to use it:

Classes are structured in a hierarchical manner, where a single Parameterizer contains n Patterns, each one containing n Parameters.

Parameterizer
    Pattern
        Parameter
        Parameter
        Parameter
    Pattern
        Parameter
        Parameter

All classes takes a name as argument, and Parameter an initial value.

A factory is provided to simplify the parameterizer creation, and each class provides a convenient method to simplify its children creation.

tory = new ParameterizerFactory(new Inflector());

reate a "foo" named parameterizer
ameterizer = $factory->create('foo');

ameterizer
// Create a "foo" named pattern
->create('foo')
    // Create a "bar" named parameter with a "baz" value
    ->create('bar', 'baz')
    // Create a "dinosaur" named parameter with a 42 value
    ->create('dinosaur', 42);
Options

A pattern can takes an array of options. One of them is “label”, which, if not provided, is automatically set as a human readable version of the pattern name, via an inflector.

tern->setOptions(array('foo' => 'bar'));

ar
tern->getOption('foo');
23 (default value, as "bar" options does not exists)
tern->getOption('bar', 123);
abel
tern->getOption('label');

A parameter can also takes an array of options. Same rule applies for the label, and some extra options, such as “choices”, “min”, “max” and “set”, are specific for dat.GUI integration.

ameter->setOptions(array('min' => 1, 'max' => 2));


ameter->getOption('min');
ull (default value, as "step" options does not exists)
ameter->getOption('step');
abel
ameter->getOption('label');
Values

At each level, you can get and merge values to communicate and synchronize with the real world.

ives a pattern indexed array of indexed parameter values array
ameterizer->getValues();
erge
ameterizer->mergeValues(array('foo' => array('bar' => 'baz')));

et indexed parameter values array
tern->getValues();
erge
tern->mergeValues(array('bar' => 'baz'));
et foo parameter value
tern->getValue('bar');
et foo parameter value
tern->setValue('bar', 'baz');

et value
ameter->getValue();
et value
ameter->setValue();
Interface

An Parameterizable interface is provided to harmonize your code.

dat.GUI twig extension

This extension provides a elao_parameterizer_dat_gui_render_javascript method, which render the javascript part of dat.GUI integration. It accepting an array of options, one of them, “gui” being a string of the name of the dat.GUI instance to use.

ipt src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js"></script>
ipt>
var gui = new dat.GUI();
{{ elao_parameterizer_dat_gui_render_javascript({'gui': 'gui'}) }}
ript>

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.