Source for file tif.php
Documentation is available at tif.php
* It evaluates the first argument and returns the second if it's true, or the third if it's false
* * rest : you can not use named parameters to call this, use it either with three arguments in the correct order (expression, true result, false result) or write it as in php (expression ? true result : false result)
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
if (!class_exists('Dwoo_Plugin_if', false)) {
$compiler->getDwoo()->getLoader()->loadPlugin('if');
// fetch false result and remove the ":" if it was present
if (trim(end($rest), '"\'') ===
':') {
// remove the ':' if present
} elseif (trim(end($rest), '"\'') ===
'?' ||
count($rest) ===
1) {
if ($falseResult ===
'?' ||
$falseResult ===
':') {
// there was in fact no false result provided, so we move it to be the true result instead
$trueResult =
$falseResult;
// fetch true result if needed
if (!isset
($trueResult)) {
// no true result provided so we use the expression arg
if ($trueResult ===
'?') {
// remove the '?' if present
if (trim(end($rest), '"\'') ===
'?') {
// check params were correctly provided
if (empty($rest) ||
$trueResult ===
null ||
$falseResult ===
null) {
throw
new Dwoo_Compilation_Exception($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>');
return '(('.
implode(' ', $condition).
') ? '.
($trueResult===
true ?
implode(' ', $condition) :
$trueResult).
' : '.
$falseResult.
')';
Documentation generated on Sun, 07 Feb 2010 17:54:00 +0000 by phpDocumentor 1.4.0