php-parser/lib/NodeAbstract.php

28 lines
659 B
PHP
Raw Normal View History

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) {
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];
}
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);
}
}