wpml-tf-collection.php
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Class WPML_TF_Collection
*
* @author OnTheGoSystems
*/
class WPML_TF_Collection implements Iterator, Countable {
/** @var array<\IWPML_TF_Data_Object> */
protected $collection = array();
/**
* @param \IWPML_TF_Data_Object $data_object
*/
public function add( IWPML_TF_Data_Object $data_object ) {
$this->collection[ $data_object->get_id() ] = $data_object;
}
/**
* @return array
*/
public function get_ids() {
return array_keys( $this->collection );
}
/**
* @param int $id
*
* @return IWPML_TF_Data_Object|null
*/
public function get( $id ) {
return array_key_exists( $id, $this->collection ) ? $this->collection[ $id ] : null;
}
/**
* @return int
*/
public function count() {
return count( $this->collection );
}
public function rewind() {
reset( $this->collection );
}
/**
* @return mixed
*/
public function current() {
return current( $this->collection );
}
/**
* @return mixed
*/
public function key() {
return key( $this->collection );
}
public function next() {
next( $this->collection );
}
/**
* @return bool
*/
public function valid() {
return key( $this->collection ) !== null;
}
}