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.  * This file is released under the LGPL
  18.  * "GNU Lesser General Public License"
  19.  * More information can be found here:
  20.  * {@link http://www.gnu.org/copyleft/lesser.html}
  21.  *
  22.  * @author     Jordi Boggiano <[email protected]>
  23.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  24.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  25.  * @link       http://dwoo.org/
  26.  * @version    0.9.1
  27.  * @date       2008-05-30
  28.  * @package    Dwoo
  29.  */
  30. {
  31.     protected $cycles = array();
  32.  
  33.     public function process($name 'default'$values null$print true$advance true$delimiter ','$assign null$reset false)
  34.     {
  35.         if ($values !== null{
  36.             if (is_string($values)) {
  37.                 $values explode($delimiter$values);
  38.             }
  39.  
  40.             if (!isset($this->cycles[$name]|| $this->cycles[$name]['values'!== $values{
  41.                 $this->cycles[$name]['index'0;
  42.             }
  43.  
  44.             $this->cycles[$name]['values'array_values($values);
  45.         elseif (isset($this->cycles[$name])) {
  46.             $values $this->cycles[$name]['values'];
  47.         }
  48.  
  49.         if ($reset{
  50.             $this->cycles[$name]['index'0;
  51.         }
  52.  
  53.         if ($print{
  54.             $out $values[$this->cycles[$name]['index']];
  55.         else {
  56.             $out null;
  57.         }
  58.  
  59.         if ($advance{
  60.             if ($this->cycles[$name]['index'>= count($values)-1{
  61.                 $this->cycles[$name]['index'0;
  62.             else {
  63.                 $this->cycles[$name]['index']++;
  64.             }
  65.         }
  66.  
  67.         if ($assign !== null{
  68.             $this->dwoo->assignInScope($assign$out);
  69.         else {
  70.             return $out;
  71.         }
  72.     }
  73. }

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