Source for file with.php

Documentation is available at with.php

  1. <?php
  2.  
  3. /**
  4.  * Moves the scope down into the provided variable, allowing you to use shorter
  5.  * variable names if you repeatedly access values into a single array
  6.  *
  7.  * The with block won't display anything at all if the provided scope is empty,
  8.  * so in effect it acts as {if $var}*content*{/if}
  9.  * <pre>
  10.  *  * var : the variable name to move into
  11.  * </pre>
  12.  * Example :
  13.  *
  14.  * instead of the following :
  15.  *
  16.  * <code>
  17.  * {if $long.boring.prefix}
  18.  *   {$long.boring.prefix.val} - {$long.boring.prefix.secondVal} - {$long.boring.prefix.thirdVal}
  19.  * {/if}
  20.  * </code>
  21.  *
  22.  * you can use :
  23.  *
  24.  * <code>
  25.  * {with $long.boring.prefix}
  26.  *   {$val} - {$secondVal} - {$thirdVal}
  27.  * {/with}
  28.  * </code>
  29.  *
  30.  * This software is provided 'as-is', without any express or implied warranty.
  31.  * In no event will the authors be held liable for any damages arising from the use of this software.
  32.  *
  33.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  34.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  35.  * @license    http://dwoo.org/LICENSE   Modified BSD License
  36.  * @link       http://dwoo.org/
  37.  * @version    1.0.0
  38.  * @date       2008-10-23
  39.  * @package    Dwoo
  40.  */
  41. {
  42.     protected static $cnt=0;
  43.  
  44.     public function init($var)
  45.     {
  46.     }
  47.  
  48.     public static function preProcessing(Dwoo_Compiler $compilerarray $params$prepend$append$type)
  49.     {
  50.         return '';
  51.     }
  52.  
  53.     public static function postProcessing(Dwoo_Compiler $compilerarray $params$prepend$append$content)
  54.     {
  55.         $rparams $compiler->getRealParams($params);
  56.         $cparams $compiler->getCompiledParams($params);
  57.  
  58.         $compiler->setScope($rparams['var']);
  59.  
  60.  
  61.         $pre Dwoo_Compiler::PHP_OPEN'if ('.$cparams['var'].')'."\n{\n".
  62.             '$_with'.(self::$cnt).' = $this->setScope("'.$rparams['var'].'");'.
  63.             "\n/* -- start with output */\n".Dwoo_Compiler::PHP_CLOSE;
  64.  
  65.         $post Dwoo_Compiler::PHP_OPEN"\n/* -- end with output */\n".
  66.             '$this->setScope($_with'.(self::$cnt++).', true);'.
  67.             "\n}\n".Dwoo_Compiler::PHP_CLOSE;
  68.  
  69.         if (isset($params['hasElse'])) {
  70.             $post .= $params['hasElse'];
  71.         }
  72.  
  73.         return $pre $content $post;
  74.     }
  75. }

Documentation generated on Sun, 07 Feb 2010 17:54:00 +0000 by phpDocumentor 1.4.0