powered by nequal
Home » CyclicValueProducer » Timeline » 1347

Changeset 1347 -- 2009-10-17 10:03:04

Comment
[Package Release] CyclicValueProducer

Diffs

CyclicValueProducer/tags/release-1.0.0-20091017100304/CyclicValueProducer.php

@@ -0,0 +1,39 @@
+<?php
+
+  /**
+   * CyclicValueProducer - 循環的に値を出力するイテレータ
+   *
+   * @package  CyclicValueProducer
+   * @author  Yoshio HANAWA <y@hnw.jp>
+   * @copyright  2009 Yoshio HANAWA
+   * @license  http://creativecommons.org/licenses/BSD/    New BSD Licence
+   * @link  http://openpear.org/package/CyclicValueProducer
+   */
+
+class CyclicValueProducer implements IteratorAggregate
+{
+  protected $cyclic_values;
+
+  public function __construct($cyclic_values, $limit = 0)
+  {
+    if (!is_array($cyclic_values)) {
+      throw new InvalidArgumentException(sprintf('%s expects parameter 1 to be %s, %s given',
+                                                 __METHOD__,
+                                                 'array',
+                                                 gettype($cyclic_values)
+                                                 ));
+    }
+    $this->cyclic_values = $cyclic_values;
+    $this->limit = $limit;
+  }
+
+  public function getIterator()
+  {
+
+    $it = new InfiniteIterator(new ArrayIterator($this->cyclic_values));
+    if ($this->limit > 0) {
+      $it = new LimitIterator($it, 0, $this->limit);
+    }
+    return $it;
+  }
+}
属性に変更があったパス: CyclicValueProducer/tags/release-1.0.0-20091017100304/CyclicValueProducer.php
___________________________________________________________________
名前: svn:mime-type
+ text/x-php
名前: svn:keywords
+ Id Rev Date
名前: svn:eol-style
+ native