Source for file cycle.php

Documentation is available at cycle.php

  1. <?php
  2.  
  3. /**
  4.  * Cycles between several values and returns one of them on each call
  5.  * <pre>
  6.  *  * name : the cycler name, specify if you need to have multiple concurrent cycles running
  7.  *  * values : an array of values or a string of values delimited by $delimiter
  8.  *  * print : if false, the pointer will go to the next one but not print anything
  9.  *  * advance : if false, the pointer will not advance to the next value
  10.  *  * delimiter : the delimiter used to split values if they are provided as a string
  11.  *  * assign : if set, the value is saved in that variable instead of being output
  12.  *  * reset : if true, the pointer is reset to the first value
  13.  * </pre>
  14.  * This software is provided 'as-is', without any express or implied warranty.
  15.  * In no event will the authors be held liable for any damages arising from the use of this software.
  16.  *
  17.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  18.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  19.  * @license    http://dwoo.org/LICENSE   Modified BSD License
  20.  * @link       http://dwoo.org/
  21.  * @version    1.1.0
  22.  * @date       2009-07-18
  23.  * @package    Dwoo
  24.  */
  25. {
  26.     protected $cycles = array();
  27.  
  28.     public function process($name 'default'$values null$print true$advance true$delimiter ','$assign null$reset false)
  29.     {
  30.         if ($values !== null{
  31.             if (is_string($values)) {
  32.                 $values explode($delimiter$values);
  33.             }
  34.  
  35.             if (!isset($this->cycles[$name]|| $this->cycles[$name]['values'!== $values{
  36.                 $this->cycles[$name]['index'0;
  37.             }
  38.  
  39.             $this->cycles[$name]['values'array_values($values);
  40.         elseif (isset($this->cycles[$name])) {
  41.             $values $this->cycles[$name]['values'];
  42.         }
  43.  
  44.         if ($reset{
  45.             $this->cycles[$name]['index'0;
  46.         }
  47.  
  48.         if ($print{
  49.             $out $values[$this->cycles[$name]['index']];
  50.         else {
  51.             $out null;
  52.         }
  53.  
  54.         if ($advance{
  55.             if ($this->cycles[$name]['index'>= count($values)-1{
  56.                 $this->cycles[$name]['index'0;
  57.             else {
  58.                 $this->cycles[$name]['index']++;
  59.             }
  60.         }
  61.  
  62.         if ($assign === null{
  63.             return $out;
  64.         }
  65.         $this->dwoo->assignInScope($out$assign);
  66.     }
  67. }

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