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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
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
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);
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');
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();
An Parameterizable interface is provided to harmonize your code.
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>