Source for file counter.php

Documentation is available at counter.php

  1. <?php
  2.  
  3. /**
  4.  * Initiates a counter that is incremented every time you call it
  5.  * <pre>
  6.  *  * name : the counter name, define it if you want to have multiple concurrent counters
  7.  *  * start : the start value, if it's set, it will reset the counter to this value, defaults to 1
  8.  *  * skip : the value to add to the counter at each call, defaults to 1
  9.  *  * direction : "up" (default) or "down" to define whether the counter increments or decrements
  10.  *  * print : if false, the counter will not output the current count, defaults to true
  11.  *  * assign : if set, the counter is saved into the given variable and does not output anything, overriding the print parameter
  12.  * </pre>
  13.  * This software is provided 'as-is', without any express or implied warranty.
  14.  * In no event will the authors be held liable for any damages arising from the use of this software.
  15.  *
  16.  * This file is released under the LGPL
  17.  * "GNU Lesser General Public License"
  18.  * More information can be found here:
  19.  * {@link http://www.gnu.org/copyleft/lesser.html}
  20.  *
  21.  * @author     Jordi Boggiano <[email protected]>
  22.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  23.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  24.  * @link       http://dwoo.org/
  25.  * @version    0.9.1
  26.  * @date       2008-05-30
  27.  * @package    Dwoo
  28.  */
  29. {
  30.     protected $counters = array();
  31.  
  32.     public function process($name 'default'$start null$skip null$direction null$print null$assign null)
  33.     {
  34.         // init counter
  35.         if (!isset($this->counters[$name])) {
  36.             $this->counters[$namearray
  37.             (
  38.                 'count'        =>    $start===null : (int) $start,
  39.                 'skip'        =>    $skip===null : (int) $skip,
  40.                 'print'        =>    $print===null true : (bool) $print,
  41.                 'assign'    =>    $assign===null null : (string) $assign,
  42.                 'direction'    =>    strtolower($direction)==='down' ? -1,
  43.             );
  44.         }
  45.         // increment
  46.         else
  47.         {
  48.             // override setting if present
  49.             if ($skip !== null{
  50.                 $this->counters[$name]['skip'= (int) $skip;
  51.             }
  52.  
  53.             if ($direction !== null{
  54.                 $this->counters[$name]['direction'strtolower($direction)==='down' ? -1;
  55.             }
  56.  
  57.             if ($print !== null{
  58.                 $this->counters[$name]['print'= (bool) $print;
  59.             }
  60.  
  61.             if ($assign !== null{
  62.                 $this->counters[$name]['assign'= (string) $assign;
  63.             }
  64.  
  65.             if ($start !== null{
  66.                 $this->counters[$name]['count'= (int) $start;
  67.             else {
  68.                 $this->counters[$name]['count'+= ($this->counters[$name]['skip'$this->counters[$name]['direction']);
  69.             }
  70.         }
  71.  
  72.         $out $this->counters[$name]['count'];
  73.  
  74.         if ($this->counters[$name]['assign'!== null{
  75.             $this->dwoo->assignInScope($out$this->counters[$name]['assign']);
  76.         elseif ($this->counters[$name]['print'=== true{
  77.             return $out;
  78.         }
  79.     }
  80. }

Documentation generated on Sun, 03 Aug 2008 15:12:25 +0200 by phpDocumentor 1.4.0