From 217280c9ba436a9acb7d4ecc5ccb3f4aab4947e4 Mon Sep 17 00:00:00 2001 From: nikic Date: Thu, 4 Aug 2011 12:02:14 +0200 Subject: [PATCH] Add getLast and toString (and __toString) methods to Node_Name --- lib/PHPParser/Node/Name.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/PHPParser/Node/Name.php b/lib/PHPParser/Node/Name.php index eb63df48..fd9a72e1 100644 --- a/lib/PHPParser/Node/Name.php +++ b/lib/PHPParser/Node/Name.php @@ -13,4 +13,34 @@ class PHPParser_Node_Name extends PHPParser_NodeAbstract public function resolveType($type) { $this->resolveType = $type; } + + /** + * Gets the last part of the name, i.e. everything after the last namespace separator. + * + * @return string Last part of the name + */ + public function getLast() { + return $this->parts[count($this->parts) - 1]; + } + + /** + * Returns a string representation of the name by imploding the namespace parts with a separator. + * + * @param string $separator The separator to use (defaults to the namespace separator \) + * + * @return string String representation + */ + public function toString($separator = '\\') { + return implode($separator, $this->parts); + } + + /** + * Returns a string representation of the name by imploding the namespace parts with the + * namespace separator \ (backslash). + * + * @return string String representation + */ + public function __toString() { + return $this->toString('\\'); + } } \ No newline at end of file