my_bundle:
algorithm: blowfish # One of 'md5', 'blowfish', 'sha256', 'sha512'
This configuration is done by this configuration tree:
// Algorithms and constants to check
$algorithms = array(
'md5' => 'CRYPT_MD5',
'blowfish' => 'CRYPT_BLOWFISH',
'sha256' => 'CRYPT_SHA256',
'sha512' => 'CRYPT_SHA512',
);
$rootNode
->children()
->scalarNode('algorithm')
->isRequired()
->beforeNormalization()
->ifString()
->then(function($v) { return strtolower($v); })
->end()
->validate()
->ifNotInArray(array_keys($algorithms))
->thenInvalid('invalid algorithm.')
->end()
->validate()
->ifTrue(function($v) use($algorithms) {
return 1 != @constant($algorithms[$v]);
})
->thenInvalid('algorithm %s is not supported by this system.')
->end()
->end()
->end();
Since each algorithm requires different parameters, how can I dynamically add them as children of the root node, base on the selected algorithm?
For example, if algorithm is "blowfish" there should be a scalar node named "cost", while if "sha512" a scalar node "rounds", each with different validation rules.
EDIT: what I really need is figure out the current algorithm (how to do with $rootNode?) and than call on of:
$rootNode->append($this->getBlowfishParamsNode());
$rootNode->append($this->getSha256ParamsNode());
$rootNode->append($this->getSha512ParamsNode());
EDIT: possible configurations I'd like to accomplish:
my_bundle:
algorithm: blowfish
cost: 15
Another:
my_bundle:
algorithm: sha512
rounds: 50000
And another:
my_bundle:
algorithm: md5