mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2025-01-22 05:11:39 +01:00
c7c94f38f1
Instead manually implement IteratorAggregate and define the required magic methods. The reasoning behind this is: a) Extending ArrayObject is always risky, because a lot of magic which is known to be buggy is involved b) This allows to lateron change the implementation for the nodes altogether, for example it could be changed to using real public fields instead of a $subNodes array.
66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
|
|
|
abstract class PHPParser_NodeAbstract implements PHPParser_Node, IteratorAggregate
|
|
{
|
|
protected $subNodes;
|
|
protected $line;
|
|
protected $docComment;
|
|
|
|
/**
|
|
* Creates a Node.
|
|
*
|
|
* @param array $subNodes Array of sub nodes
|
|
* @param int $line Line
|
|
* @param null|string $docComment Nearest doc comment
|
|
*/
|
|
public function __construct(array $subNodes, $line = -1, $docComment = null) {
|
|
$this->subNodes = $subNodes;
|
|
$this->line = $line;
|
|
$this->docComment = $docComment;
|
|
}
|
|
|
|
/**
|
|
* Gets the type of the node.
|
|
*
|
|
* @return string Type of the node
|
|
*/
|
|
public function getType() {
|
|
return substr(get_class($this), 15);
|
|
}
|
|
|
|
/**
|
|
* Gets line the node started in.
|
|
*
|
|
* @return int Line
|
|
*/
|
|
public function getLine() {
|
|
return $this->line;
|
|
}
|
|
|
|
/**
|
|
* Gets the nearest doc comment.
|
|
*
|
|
* @return null|string Nearest doc comment or null
|
|
*/
|
|
public function getDocComment() {
|
|
return $this->docComment;
|
|
}
|
|
|
|
/* Magic interfaces */
|
|
|
|
public function &__get($name) {
|
|
return $this->subNodes[$name];
|
|
}
|
|
public function __set($name, $value) {
|
|
$this->subNodes[$name] = $value;
|
|
}
|
|
public function __isset($name) {
|
|
return isset($this->subNodes[$name]);
|
|
}
|
|
public function __unset($name) {
|
|
unset($this->subNodes[$name]);
|
|
}
|
|
public function getIterator() {
|
|
return new ArrayIterator($this->subNodes);
|
|
}
|
|
} |