From e932711fa4ae9b8265b18b0a5da41df8717d5583 Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 3 Apr 2012 13:04:24 -0500 Subject: [PATCH 1/2] added some methods for storing metadata to the interface --- lib/PHPParser/Node.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/PHPParser/Node.php b/lib/PHPParser/Node.php index 9c9d817..7c1faca 100644 --- a/lib/PHPParser/Node.php +++ b/lib/PHPParser/Node.php @@ -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(); } \ No newline at end of file From 2ccae143d0859e4b03e70d12e34b3180daeeedcc Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 3 Apr 2012 13:07:10 -0500 Subject: [PATCH 2/2] added implementations for the new interface methods --- lib/PHPParser/NodeAbstract.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/PHPParser/NodeAbstract.php b/lib/PHPParser/NodeAbstract.php index b7c911a..2732b70 100644 --- a/lib/PHPParser/NodeAbstract.php +++ b/lib/PHPParser/NodeAbstract.php @@ -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 */