Hi guys,

Wrote this modifier to solve a small inconvenience with conditional
blocks; this time I had five different blocks and I didn't feel like
passing five variables to control them.

Hope it's useful to you guys ;-)

The syntax:
"eq:" [ " " expr ]*

These are some examples:

eq: data/value string:3
    Compares data/value with "3"

eq: data/value string:3 data/value2 string:5
    Compares data/value with "3" and data/value2 with "5"

eq: data/value data/value2 string:6
    Compares both data/value and data/value2 with "6"

One caveat: due to the simplistic parsing I'm doing you can't have
spaces in the string: literals.
Another one: it uses closures, so it would break in < 5.3.0

Here's the function:
function phptal_tales_eq($src, $nothrow)
{
        return join('&&', array_map(function($chunk) {
                static $last = false;

                if (!isset($chunk[1])) {
                        $chunk[1] = $last;
                } elseif ($last === false) {
                        $last = $chunk[1];
                }

                return join('==', $chunk);
        }, array_chunk(array_map(function($path) use ($nothrow) {
                return phptal_tales($path, $nothrow);
        }, explode(' ', trim($src))), 2)));
}


-- 
--
Tjerk

_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to