dolibarr/htdocs/includes/odtphp/SegmentIterator.php

65 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/**
* Segments iterator
* You need PHP 5.2 at least
* You need Zip Extension or PclZip library
*
* @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
2019-09-23 21:55:30 +02:00
* @license https://www.gnu.org/copyleft/gpl.html GPL License
* @version 1.3
*/
class SegmentIterator implements RecursiveIterator
{
private $ref;
private $key;
2025-01-09 21:27:13 +01:00
private $keys;
public function __construct(array $ref)
{
$this->ref = $ref;
$this->key = 0;
$this->keys = array_keys($this->ref);
}
2025-01-09 21:38:06 +01:00
#[\ReturnTypeWillChange]
public function hasChildren()
{
return $this->valid() && $this->current() instanceof Segment;
}
2025-01-09 21:38:06 +01:00
#[\ReturnTypeWillChange]
public function current()
{
return $this->ref[$this->keys[$this->key]];
}
2025-01-09 21:38:06 +01:00
#[\ReturnTypeWillChange]
function getChildren()
{
return new self($this->current()->children);
}
2025-01-09 21:38:06 +01:00
#[\ReturnTypeWillChange]
public function key()
{
return $this->key;
}
2025-01-09 21:38:06 +01:00
#[\ReturnTypeWillChange]
public function valid()
{
return array_key_exists($this->key, $this->keys);
}
2025-01-09 21:38:06 +01:00
/**
* @return void
*/
#[\ReturnTypeWillChange]
public function rewind()
{
$this->key = 0;
}
2025-01-09 21:38:06 +01:00
/**
* @return void
*/
#[\ReturnTypeWillChange]
public function next()
{
$this->key ++;
}
}