2011-04-18 19:02:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class NodeAbstract implements IteratorAggregate
|
|
|
|
{
|
|
|
|
protected $subNodes = array();
|
|
|
|
|
|
|
|
public function __construct(array $subNodes) {
|
|
|
|
$this->subNodes = $subNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __get($name) {
|
2011-05-27 18:20:44 +02:00
|
|
|
if (!array_key_exists($name, $this->subNodes)) {
|
|
|
|
throw new OutOfBoundsException(
|
|
|
|
sprintf('"%s" has no subnode "%s"', $this->getType(), $name)
|
|
|
|
);
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->subNodes[$name];
|
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:44 +02:00
|
|
|
public function getType() {
|
|
|
|
return substr(get_class($this), 5);
|
|
|
|
}
|
|
|
|
|
2011-04-18 19:02:30 +02:00
|
|
|
public function getIterator() {
|
|
|
|
return new ArrayIterator($this->subNodes);
|
|
|
|
}
|
|
|
|
}
|