I've checked the source code of CI's Validation class now.
They allow rules to be set like
array('field' => "valid|length[5]|foo|callback_bar")
I didn't see any nested square brackets or pipes inside the square brackets. The Docs clearly say, you may have only one param. The string is set internally to $_rules
. When validating, the string will be exploded
into an array first, so the above would evaluate to four $rules
.
'field' => array('valid', 'length[5]', 'foo', 'callback_bar')
They then loop through the array, checking if the $rule
is a callback with substr()
. Then they check if there is square brackets in the $rule
with the pattern "/(.*?)\[(.*?)\]/"
and if so, take it off the $rule
and store the inner part of the brackets as $param
. And finally, they just execute the $rule
as a variable function with the detected param, e.g. $rule(POST[$field], 5)
;
As you can see, they are not splitting everything in one go. This does not answer your question, but shedding some light on CI's internal logic to get their Validator running might help you rethink your approach.
Opinion: I'd like to add that their approach is terrible. Validator Chains are prime candidates for the Command Pattern. Sure, it's nice to specify validators by small and compact strings, but you pay this by a lot of ugly string juggling, when it comes to actually running the chain. Have a look at how Zend Framework does it or look at PHPs native filter functions.