1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-30 04:19:30 +01:00

Use ArrayObject for Nodes to abstract away array access implementation details

This commit is contained in:
nikic 2011-06-25 17:51:17 +02:00
parent dfa59332ed
commit 1478ae9c54

View File

@ -1,8 +1,7 @@
<?php
abstract class PHPParser_NodeAbstract implements IteratorAggregate
abstract class PHPParser_NodeAbstract extends ArrayObject
{
protected $subNodes;
protected $line;
/**
@ -12,46 +11,9 @@ abstract class PHPParser_NodeAbstract implements IteratorAggregate
* @param int $line Line
*/
public function __construct(array $subNodes, $line = -1) {
$this->subNodes = $subNodes;
$this->line = $line;
}
parent::__construct($subNodes, ArrayObject::ARRAY_AS_PROPS);
/**
* Gets a sub node.
*
* @param string $name Name of sub node
*
* @return mixed Sub node
*/
public function __get($name) {
if (!array_key_exists($name, $this->subNodes)) {
throw new InvalidArgumentException(
sprintf('"%s" has no subnode "%s"', $this->getType(), $name)
);
}
return $this->subNodes[$name];
}
/**
* Sets a sub node.
*
* @param string $name Name of sub node
* @param mixed $value Value to set sub node to
*/
public function __set($name, $value) {
$this->subNodes[$name] = $value;
}
/**
* Checks whether a subnode exists.
*
* @param string $name Name of sub node
*
* @return bool Whether the sub node exists
*/
public function __isset($name) {
return isset($this->subNodes[$name]);
$this->line = $line;
}
/**
@ -76,13 +38,4 @@ abstract class PHPParser_NodeAbstract implements IteratorAggregate
public function getLine() {
return $this->line;
}
/**
* Gets an Iterator for the sub nodes.
*
* @return ArrayIterator Iterator for sub nodes
*/
public function getIterator() {
return new ArrayIterator($this->subNodes);
}
}