PluginProbe
Boxzilla – WordPress Popup Builder / 3.0
Boxzilla – WordPress Popup Builder v3.0
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
boxzilla / src / class-collection.php

class-collection.php in Boxzilla – WordPress Popup Builder 3.0, at src/class-collection.php

81 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Boxzilla;
4
5 use Iterator;
6 use Countable;
7
8 class Collection implements Iterator, Countable {
9
10 protected $elements = array();
11 private $position = 0;
12
13 public function __construct( array $elements ) {
14 $this->elements = $elements;
15 $this->position = 0;
16 }
17
18 function rewind() {
19 $this->position = 0;
20 }
21
22 function current() {
23 return $this->elements[ $this->position ];
24 }
25
26 function key() {
27 return $this->position;
28 }
29
30 function next() {
31 ++$this->position;
32 }
33
34 function valid() {
35 return isset( $this->elements[ $this->position ] );
36 }
37
38 /**
39 * @param $callback
40 *
41 * @return array
42 */
43 function map($callback) {
44 $result = array();
45
46 foreach( $this->elements as $element ) {
47 $result[] = $callback( $element );
48 }
49
50 return $result;
51 }
52
53 /**
54 * @param $callback
55 *
56 * @return null
57 */
58 function find($callback) {
59
60 foreach( $this->elements as $element ) {
61 if( $callback( $element ) ) {
62 return $element;
63 }
64 }
65
66 return null;
67 }
68
69 /**
70 * (PHP 5 &gt;= 5.1.0)<br/>
71 * Count elements of an object
72 * @link http://php.net/manual/en/countable.count.php
73 * @return int The custom count as an integer.
74 * </p>
75 * <p>
76 * The return value is cast to an integer.
77 */
78 public function count() {
79 return count( $this->elements );
80 }
81 }