Source for file if.php
Documentation is available at if.php
* Conditional block, the syntax is very similar to the php one, allowing () || && and
* other php operators. Additional operators and their equivalent php syntax are as follow :
* X is [not] div by Y -> (X % Y) == 0
* X is [not] even [by Y] -> (X % 2) == 0 or ((X/Y) % 2) == 0
* X is [not] odd [by Y] -> (X % 2) != 0 or ((X/Y) % 2) != 0
* 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
public function init(array $rest)
public static function replaceKeywords(array $params, Dwoo_Compiler $compiler)
while (list
($k,$v) =
each($params)) {
if(substr($v, 0, 1) ===
'"' ||
substr($v, 0, 1) ===
'\'') {
$vmod =
strtolower(substr($v, 1, -
1));
if (isset
($params[$k+
1]) &&
strtolower(trim($params[$k+
1], '"\'')) ===
'not') {
if (!isset
($params[$k+
$ptr])) {
$params[$k+
$ptr] =
trim($params[$k+
$ptr], '"\'');
switch($params[$k+
$ptr]) {
if (isset
($params[$k+
$ptr+
1]) &&
strtolower(trim($params[$k+
$ptr+
1], '"\'')) ===
'by') {
$p[] =
' % '.
$params[$k+
$ptr+
2].
' '.
($negate?
'!':
'=').
'== 0';
throw
new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found '.
$params[$k-
1].
' is '.
($negate?
'not ':
'').
'div '.
$params[$k+
$ptr+
1].
' '.
$params[$k+
$ptr+
2]);
if (isset
($params[$k+
$ptr+
1]) &&
strtolower(trim($params[$k+
$ptr+
1], '"\'')) ===
'by') {
$p[] =
'('.
$a .
' / '.
$b.
') % 2 '.
($negate?
'!':
'=').
'== 0';
$p[] =
$a.
' % 2 '.
($negate?
'!':
'=').
'== 0';
if (isset
($params[$k+
$ptr+
1]) &&
strtolower(trim($params[$k+
$ptr+
1], '"\'')) ===
'by') {
$p[] =
'('.
$a .
' / '.
$b.
') % 2 '.
($negate?
'=':
'!').
'== 0';
$p[] =
$a.
' % 2 '.
($negate?
'=':
'!').
'== 0';
throw
new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.
$params[$k-
1].
' is '.
$params[$k+
$ptr+
1]);
public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
$params =
$compiler->getCompiledParams($params);
if (isset
($params['hasElse'])) {
$post .=
$params['hasElse'];
return $pre .
$content .
$post;
Documentation generated on Sat, 18 Jul 2009 21:05:08 +0200 by phpDocumentor 1.4.0