| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\Exporter; |
| 4 |
|
| 5 |
class ExporterRecord implements \ArrayAccess, \Iterator, \Countable |
| 6 |
{ |
| 7 |
private $_data = []; |
| 8 |
private $_mapper_type; |
| 9 |
private $keys = array(); |
| 10 |
private $position; |
| 11 |
|
| 12 |
public function __construct($data, $mapper_type) |
| 13 |
{ |
| 14 |
$this->_data = $data; |
| 15 |
$this->_mapper_type = $mapper_type; |
| 16 |
|
| 17 |
$this->keys = array_keys($this->_data); |
| 18 |
} |
| 19 |
|
| 20 |
#[\ReturnTypeWillChange] |
| 21 |
public function current() |
| 22 |
{ |
| 23 |
return $this->_data[$this->keys[$this->position]]; |
| 24 |
} |
| 25 |
|
| 26 |
/** @return void */ |
| 27 |
#[\ReturnTypeWillChange] |
| 28 |
public function next() |
| 29 |
{ |
| 30 |
$this->position++; |
| 31 |
} |
| 32 |
|
| 33 |
#[\ReturnTypeWillChange] |
| 34 |
public function key() |
| 35 |
{ |
| 36 |
return $this->keys[$this->position]; |
| 37 |
} |
| 38 |
|
| 39 |
/** @return bool */ |
| 40 |
#[\ReturnTypeWillChange] |
| 41 |
public function valid() |
| 42 |
{ |
| 43 |
return isset($this->keys[$this->position]); |
| 44 |
} |
| 45 |
|
| 46 |
/** @return void */ |
| 47 |
#[\ReturnTypeWillChange] |
| 48 |
public function rewind() |
| 49 |
{ |
| 50 |
$this->position = 0; |
| 51 |
} |
| 52 |
|
| 53 |
/** @return int<0, \max> */ |
| 54 |
#[\ReturnTypeWillChange] |
| 55 |
public function count() |
| 56 |
{ |
| 57 |
return count($this->keys); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* @param mixed $offset |
| 62 |
* @return bool |
| 63 |
*/ |
| 64 |
#[\ReturnTypeWillChange] |
| 65 |
public function offsetExists($offset) |
| 66 |
{ |
| 67 |
if (!isset($this->_data[$offset])) { |
| 68 |
$value = apply_filters('iwp/exporter_record/' . $this->_mapper_type, null, $offset, $this->_data); |
| 69 |
if (!is_null($value)) { |
| 70 |
$this->_data[$offset] = $value; |
| 71 |
$this->keys = array_keys($this->_data); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
return isset($this->_data[$offset]); |
| 76 |
} |
| 77 |
|
| 78 |
#[\ReturnTypeWillChange] |
| 79 |
public function offsetGet($offset) |
| 80 |
{ |
| 81 |
return $this->offsetExists($offset) ? $this->_data[$offset] : null; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* @param mixed $offset |
| 86 |
* @param mixed $value |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
#[\ReturnTypeWillChange] |
| 90 |
public function offsetSet($offset, $value) |
| 91 |
{ |
| 92 |
if (is_null($offset)) { |
| 93 |
$this->_data[] = $value; |
| 94 |
} else { |
| 95 |
$this->_data[$offset] = $value; |
| 96 |
} |
| 97 |
|
| 98 |
$this->keys = array_keys($this->_data); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* @param mixed $offset |
| 103 |
* @return void |
| 104 |
*/ |
| 105 |
#[\ReturnTypeWillChange] |
| 106 |
public function offsetUnset($offset) |
| 107 |
{ |
| 108 |
unset($this->_data[$offset]); |
| 109 |
$this->keys = array_keys($this->_data); |
| 110 |
} |
| 111 |
} |
| 112 |
|