PHP Class PhpParser\Node\Name

Inheritance: extends PhpParser\NodeAbstract
Show file Open project: nikic/php-parser Class Usage Examples

Public Properties

Property Type Description
$parts Parts of the name

Public Methods

Method Description
__construct ( string | array | self $name, array $attributes = [] ) Constructs a name node.
__toString ( ) : string Returns a string representation of the name by imploding the namespace parts with the namespace separator.
concat ( string | array | self | null $name1, string | array | self | null $name2, array $attributes = [] ) : static | null Concatenate two names, yielding a new Name instance.
getFirst ( ) : string Gets the first part of the name, i.e. everything before the first namespace separator.
getLast ( ) : string Gets the last part of the name, i.e. everything after the last namespace separator.
getSubNodeNames ( )
isFullyQualified ( ) : boolean Checks whether the name is fully qualified. (E.g. \Name)
isQualified ( ) : boolean Checks whether the name is qualified. (E.g. Name\Name)
isRelative ( ) : boolean Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)
isUnqualified ( ) : boolean Checks whether the name is unqualified. (E.g. Name)
slice ( integer $offset, integer | null $length = null ) : static | null Gets a slice of a name (similar to array_slice).
toString ( ) : string Returns a string representation of the name by imploding the namespace parts with the namespace separator.

Private Methods

Method Description
prepareName ( string | array | self $name ) : array Prepares a (string, array or Name node) name for use in name changing methods by converting it to an array.

Method Details

__construct() public method

Constructs a name node.
public __construct ( string | array | self $name, array $attributes = [] )
$name string | array | self Name as string, part array or Name instance (copy ctor)
$attributes array Additional attributes

__toString() public method

Returns a string representation of the name by imploding the namespace parts with the namespace separator.
public __toString ( ) : string
return string String representation

concat() public static method

The type of the generated instance depends on which class this method is called on, for example Name\FullyQualified::concat() will yield a Name\FullyQualified instance. If one of the arguments is null, a new instance of the other name will be returned. If both arguments are null, null will be returned. As such, writing Name::concat($namespace, $shortName) where $namespace is a Name node or null will work as expected.
public static concat ( string | array | self | null $name1, string | array | self | null $name2, array $attributes = [] ) : static | null
$name1 string | array | self | null The first name
$name2 string | array | self | null The second name
$attributes array Attributes to assign to concatenated name
return static | null Concatenated name

getFirst() public method

Gets the first part of the name, i.e. everything before the first namespace separator.
public getFirst ( ) : string
return string First part of the name

getLast() public method

Gets the last part of the name, i.e. everything after the last namespace separator.
public getLast ( ) : string
return string Last part of the name

getSubNodeNames() public method

public getSubNodeNames ( )

isFullyQualified() public method

Checks whether the name is fully qualified. (E.g. \Name)
public isFullyQualified ( ) : boolean
return boolean Whether the name is fully qualified

isQualified() public method

Checks whether the name is qualified. (E.g. Name\Name)
public isQualified ( ) : boolean
return boolean Whether the name is qualified

isRelative() public method

Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)
public isRelative ( ) : boolean
return boolean Whether the name is relative

isUnqualified() public method

Checks whether the name is unqualified. (E.g. Name)
public isUnqualified ( ) : boolean
return boolean Whether the name is unqualified

slice() public method

This method returns a new instance of the same type as the original and with the same attributes. If the slice is empty, null is returned. The null value will be correctly handled in concatenations using concat(). Offset and length have the same meaning as in array_slice().
public slice ( integer $offset, integer | null $length = null ) : static | null
$offset integer Offset to start the slice at (may be negative)
$length integer | null Length of the slice (may be negative)
return static | null Sliced name

toString() public method

Returns a string representation of the name by imploding the namespace parts with the namespace separator.
public toString ( ) : string
return string String representation

Property Details

$parts public property

Parts of the name
Deprecation: Avoid directly accessing $parts, use methods instead.
public $parts