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.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  17.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  18.  * @license    http://dwoo.org/LICENSE   Modified BSD License
  19.  * @link       http://dwoo.org/
  20.  * @version    1.0.0
  21.  * @date       2008-10-23
  22.  * @package    Dwoo
  23.  */
  24. {
  25.     protected $counters = array();
  26.  
  27.     public function process($name 'default'$start null$skip null$direction null$print null$assign null)
  28.     {
  29.         // init counter
  30.         if (!isset($this->counters[$name])) {
  31.             $this->counters[$namearray
  32.             (
  33.                 'count'        =>    $start===null : (int) $start,
  34.                 'skip'        =>    $skip===null : (int) $skip,
  35.                 'print'        =>    $print===null true : (bool) $print,
  36.                 'assign'    =>    $assign===null null : (string) $assign,
  37.                 'direction'    =>    strtolower($direction)==='down' ? -1,
  38.             );
  39.         }
  40.         // increment
  41.         else
  42.         {
  43.             // override setting if present
  44.             if ($skip !== null{
  45.                 $this->counters[$name]['skip'= (int) $skip;
  46.             }
  47.  
  48.             if ($direction !== null{
  49.                 $this->counters[$name]['direction'strtolower($direction)==='down' ? -1;
  50.             }
  51.  
  52.             if ($print !== null{
  53.                 $this->counters[$name]['print'= (bool) $print;
  54.             }
  55.  
  56.             if ($assign !== null{
  57.                 $this->counters[$name]['assign'= (string) $assign;
  58.             }
  59.  
  60.             if ($start !== null{
  61.                 $this->counters[$name]['count'= (int) $start;
  62.             else {
  63.                 $this->counters[$name]['count'+= ($this->counters[$name]['skip'$this->counters[$name]['direction']);
  64.             }
  65.         }
  66.  
  67.         $out $this->counters[$name]['count'];
  68.  
  69.         if ($this->counters[$name]['assign'!== null{
  70.             $this->dwoo->assignInScope($out$this->counters[$name]['assign']);
  71.         elseif ($this->counters[$name]['print'=== true{
  72.             return $out;
  73.         }
  74.     }
  75. }

Documentation generated on Sat, 18 Jul 2009 21:04:47 +0200 by phpDocumentor 1.4.0