2016-08-19 00:51:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Core\Config;
|
|
|
|
|
|
|
|
use Iterator;
|
|
|
|
|
2016-09-09 08:43:05 +02:00
|
|
|
class DAG_Iterator implements Iterator
|
2016-08-19 00:51:35 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
protected $data;
|
|
|
|
protected $dag;
|
|
|
|
|
|
|
|
protected $dagkeys;
|
|
|
|
protected $i;
|
|
|
|
|
|
|
|
public function __construct($data, $dag)
|
|
|
|
{
|
|
|
|
$this->data = $data;
|
|
|
|
$this->dag = $dag;
|
|
|
|
$this->rewind();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function key()
|
|
|
|
{
|
|
|
|
return $this->i;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function current()
|
|
|
|
{
|
|
|
|
$res = array();
|
|
|
|
|
|
|
|
$res['from'] = $this->data[$this->i];
|
|
|
|
|
|
|
|
$res['to'] = array();
|
|
|
|
foreach ($this->dag[$this->i] as $to) {
|
|
|
|
$res['to'][] = $this->data[$to];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function next()
|
|
|
|
{
|
|
|
|
$this->i = array_shift($this->dagkeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rewind()
|
|
|
|
{
|
|
|
|
$this->dagkeys = array_keys($this->dag);
|
|
|
|
$this->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function valid()
|
|
|
|
{
|
|
|
|
return $this->i !== null;
|
|
|
|
}
|
|
|
|
}
|