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

Merge pull request #14 from schmittjoh/patch-1

Adds capabilities for storing additional information in nodes
This commit is contained in:
nikic 2012-04-04 04:48:20 -07:00
commit ce08ea46c2
2 changed files with 64 additions and 0 deletions

View File

@ -43,4 +43,38 @@ interface PHPParser_Node
* @param null|string $docComment Nearest doc comment or null
*/
public function setDocComment($docComment);
/**
* Sets an attribute on a node.
*
* @param string $key
* @param mixed $value
*/
public function setAttribute($key, $value);
/**
* Returns whether an attribute exists.
*
* @param string $key
*
* @return Boolean
*/
public function hasAttribute($key);
/**
* Returns the value of an attribute.
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function getAttribute($key, $default = null);
/**
* Returns all attributes for the given node.
*
* @return array
*/
public function getAttributes();
}

View File

@ -5,6 +5,7 @@ abstract class PHPParser_NodeAbstract implements PHPParser_Node, IteratorAggrega
protected $subNodes;
protected $line;
protected $docComment;
protected $attributes;
/**
* Creates a Node.
@ -17,6 +18,7 @@ abstract class PHPParser_NodeAbstract implements PHPParser_Node, IteratorAggrega
$this->subNodes = $subNodes;
$this->line = $line;
$this->docComment = $docComment;
$this->attributes = array();
}
/**
@ -72,6 +74,34 @@ abstract class PHPParser_NodeAbstract implements PHPParser_Node, IteratorAggrega
public function setDocComment($docComment) {
$this->docComment = $docComment;
}
/**
* @inheritDoc
*/
public function setAttribute($key, $value) {
$this->attributes[$key] = $value;
}
/**
* @inheritDoc
*/
public function hasAttribute($key) {
return array_key_exists($key, $this->attributes);
}
/**
* @inheritDoc
*/
public function getAttribute($key, $default = null) {
return array_key_exists($key, $this->attributes) ? $this->attributes[$key] : $default;
}
/**
* @inheritDoc
*/
public function getAttributes() {
return $this->attributes;
}
/* Magic interfaces */