PHP 클래스 PhpCsFixer\Tokenizer\Tokens

Its role is to provide the ability to manage collection and navigate through it. As a token prototype you should understand a single element generated by token_get_all.
저자: Dariusz Rumiński ([email protected])
상속: extends SplFixedArray
파일 보기 프로젝트 열기: friendsofphp/php-cs-fixer 1 사용 예제들

공개 메소드들

메소드 설명
__clone ( ) Clone tokens collection.
clearCache ( string | null $key = null ) Clear cache - one position or all of them.
clearChanged ( ) Clear internal flag if collection was changed and flag for all collection's items.
clearEmptyTokens ( ) Clear empty tokens.
clearRange ( integer $indexStart, integer $indexEnd ) Clear tokens in the given range.
clearTokenAndMergeSurroundingWhitespace ( integer $index ) Clear token and merge surrounding whitespace tokens.
detectBlockType ( PhpCsFixer\Tokenizer\Token $token ) : null | array Detect type of block.
ensureWhitespaceAtIndex ( integer $index, integer $indexOffset, string $whitespace ) : boolean Ensure that on given index is a whitespace with given kind.
findBlockEnd ( integer $type, integer $searchIndex, boolean $findEnd = true ) : integer Find block end.
findGivenKind ( integer | array $possibleKind, integer $start, integer | null $end = null ) : array Find tokens of given kind.
findSequence ( array $sequence, integer $start, integer $end = null, boolean | array $caseSensitive = true ) : array | null Find a sequence of meaningful tokens and returns the array of their locations.
fromArray ( PhpCsFixer\Tokenizer\Token[] $array, boolean $saveIndexes = null ) : Tokens Create token collection from array.
fromCode ( string $code ) : Tokens Create token collection directly from code.
generateCode ( ) : string Generate code from tokens.
generatePartialCode ( integer $start, integer $end ) : string Generate code from tokens between given indexes.
getBlockEdgeDefinitions ( ) : array Return block edge definitions.
getCodeHash ( ) : string Get hash of code.
getMeaningfulTokenSibling ( integer $index, integer $direction ) : integer | null Get index for closest sibling token that is not a whitespace or comment.
getNextMeaningfulToken ( integer $index ) : integer | null Get index for closest next token that is not a whitespace or comment.
getNextNonWhitespace ( integer $index, null | string $whitespaces = null ) : integer | null Get index for closest next token which is non whitespace.
getNextTokenOfKind ( integer $index, array $tokens = [], boolean $caseSensitive = true ) : integer | null Get index for closest next token of given kind.
getNonEmptySibling ( integer $index, integer $direction ) : integer | null Get index for closest sibling token which is not empty.
getNonWhitespaceSibling ( integer $index, integer $direction, null | string $whitespaces = null ) : integer | null Get index for closest sibling token which is non whitespace.
getPrevMeaningfulToken ( integer $index ) : integer | null Get index for closest previous token that is not a whitespace or comment.
getPrevNonWhitespace ( integer $index, null | string $whitespaces = null ) : integer | null Get index for closest previous token which is non whitespace.
getPrevTokenOfKind ( integer $index, array $tokens = [], boolean $caseSensitive = true ) : integer | null Get index for closest previous token of given kind.
getTokenNotOfKindSibling ( integer $index, integer $direction, array $tokens = [] ) : integer | null Get index for closest sibling token not of given kind.
getTokenOfKindSibling ( integer $index, integer $direction, array $tokens = [], boolean $caseSensitive = true ) : integer | null Get index for closest sibling token of given kind.
insertAt ( integer $index, Tokens | PhpCsFixer\Tokenizer\Token[] | PhpCsFixer\Tokenizer\Token $items ) Insert instances of Token inside collection.
isAllTokenKindsFound ( array $tokenKinds ) : boolean Check if all token kinds given as argument are found.
isAnyTokenKindsFound ( array $tokenKinds ) : boolean Check if any token kind given as argument is found.
isChanged ( ) : boolean Check if collection was change: collection itself (like insert new tokens) or any of collection's elements.
isMonolithicPhp ( ) : boolean Checks for monolithic PHP code.
isPartialCodeMultiline ( integer $start, integer $end ) : boolean Check if partial code is multiline.
isTokenKindFound ( integer | string $tokenKind ) : boolean Check if token kind given as argument is found.
offsetSet ( integer $index, PhpCsFixer\Tokenizer\Token $newval ) Set collection item.
offsetUnset ( integer $index ) Unset collection item.
overrideAt ( integer $index, PhpCsFixer\Tokenizer\Token | array | string $token ) Override token at given index and register it.
overrideRange ( integer $indexStart, integer $indexEnd, Tokens | PhpCsFixer\Tokenizer\Token[] $items ) Override tokens at given range.
removeLeadingWhitespace ( integer $index, null | string $whitespaces = null ) Removes all the leading whitespace.
removeTrailingWhitespace ( integer $index, null | string $whitespaces = null ) Removes all the trailing whitespace.
setCode ( string $code ) Set code. Clear all current content and replace it by new Token items generated from code directly.
setSize ( integer $size ) Set new size of collection.
toJson ( )

비공개 메소드들

메소드 설명
calculateCodeHash ( string $code ) : integer Calculate hash for code.
changeCodeHash ( string $codeHash ) Change code hash.
getCache ( string $key ) : Tokens Get cache value for given key.
hasCache ( string $key ) : boolean Check if given key exists in cache.
registerFoundToken ( PhpCsFixer\Tokenizer\Token | array | string $token ) Register token as found.
setCache ( string $key, Tokens $value ) Set cache item.

메소드 상세

__clone() 공개 메소드

Clone tokens collection.
public __clone ( )

clearCache() 공개 정적인 메소드

Clear cache - one position or all of them.
public static clearCache ( string | null $key = null )
$key string | null position to clear, when null clear all

clearChanged() 공개 메소드

Clear internal flag if collection was changed and flag for all collection's items.
public clearChanged ( )

clearEmptyTokens() 공개 메소드

Empty tokens can occur e.g. after calling clear on item of collection.
public clearEmptyTokens ( )

clearRange() 공개 메소드

Clear tokens in the given range.
public clearRange ( integer $indexStart, integer $indexEnd )
$indexStart integer
$indexEnd integer

clearTokenAndMergeSurroundingWhitespace() 공개 메소드

Clear token and merge surrounding whitespace tokens.

detectBlockType() 공개 정적인 메소드

Detect type of block.
public static detectBlockType ( PhpCsFixer\Tokenizer\Token $token ) : null | array
$token PhpCsFixer\Tokenizer\Token token
리턴 null | array array with 'type' and 'isStart' keys or null if not found

ensureWhitespaceAtIndex() 공개 메소드

If there is a whitespace then it's content will be modified. If not - the new Token will be added.
public ensureWhitespaceAtIndex ( integer $index, integer $indexOffset, string $whitespace ) : boolean
$index integer index
$indexOffset integer index offset for Token insertion
$whitespace string whitespace to set
리턴 boolean if new Token was added

findBlockEnd() 공개 메소드

Find block end.
public findBlockEnd ( integer $type, integer $searchIndex, boolean $findEnd = true ) : integer
$type integer type of block, one of BLOCK_TYPE_*
$searchIndex integer index of opening brace
$findEnd boolean if method should find block's end, default true, otherwise method find block's start
리턴 integer index of closing brace

findGivenKind() 공개 메소드

Find tokens of given kind.
public findGivenKind ( integer | array $possibleKind, integer $start, integer | null $end = null ) : array
$possibleKind integer | array kind or array of kind
$start integer optional offset
$end integer | null optional limit
리턴 array array of tokens of given kinds or assoc array of arrays

findSequence() 공개 메소드

Find a sequence of meaningful tokens and returns the array of their locations.
public findSequence ( array $sequence, integer $start, integer $end = null, boolean | array $caseSensitive = true ) : array | null
$sequence array an array of tokens (same format used by getNextTokenOfKind)
$start integer start index, defaulting to the start of the file
$end integer end index, defaulting to the end of the file
$caseSensitive boolean | array global case sensitiveness or an array of booleans, whose keys should match the ones used in $others. If any is missing, the default case-sensitive comparison is used
리턴 array | null an array containing the tokens matching the sequence elements, indexed by their position

fromArray() 공개 정적인 메소드

Create token collection from array.
public static fromArray ( PhpCsFixer\Tokenizer\Token[] $array, boolean $saveIndexes = null ) : Tokens
$array PhpCsFixer\Tokenizer\Token[] the array to import
$saveIndexes boolean save the numeric indexes used in the original array, default is yes
리턴 Tokens

fromCode() 공개 정적인 메소드

Create token collection directly from code.
public static fromCode ( string $code ) : Tokens
$code string PHP code
리턴 Tokens

generateCode() 공개 메소드

Generate code from tokens.
public generateCode ( ) : string
리턴 string

generatePartialCode() 공개 메소드

Generate code from tokens between given indexes.
public generatePartialCode ( integer $start, integer $end ) : string
$start integer start index
$end integer end index
리턴 string

getBlockEdgeDefinitions() 공개 정적인 메소드

Return block edge definitions.
public static getBlockEdgeDefinitions ( ) : array
리턴 array

getCodeHash() 공개 메소드

Get hash of code.
public getCodeHash ( ) : string
리턴 string

getMeaningfulTokenSibling() 공개 메소드

Get index for closest sibling token that is not a whitespace or comment.
public getMeaningfulTokenSibling ( integer $index, integer $direction ) : integer | null
$index integer token index
$direction integer direction for looking, +1 or -1
리턴 integer | null

getNextMeaningfulToken() 공개 메소드

Get index for closest next token that is not a whitespace or comment.
public getNextMeaningfulToken ( integer $index ) : integer | null
$index integer token index
리턴 integer | null

getNextNonWhitespace() 공개 메소드

This method is shorthand for getNonWhitespaceSibling method.
public getNextNonWhitespace ( integer $index, null | string $whitespaces = null ) : integer | null
$index integer token index
$whitespaces null | string whitespaces characters for Token::isWhitespace
리턴 integer | null

getNextTokenOfKind() 공개 메소드

This method is shorthand for getTokenOfKindSibling method.
public getNextTokenOfKind ( integer $index, array $tokens = [], boolean $caseSensitive = true ) : integer | null
$index integer token index
$tokens array possible tokens
$caseSensitive boolean perform a case sensitive comparison
리턴 integer | null

getNonEmptySibling() 공개 메소드

Get index for closest sibling token which is not empty.
public getNonEmptySibling ( integer $index, integer $direction ) : integer | null
$index integer token index
$direction integer direction for looking, +1 or -1
리턴 integer | null

getNonWhitespaceSibling() 공개 메소드

Get index for closest sibling token which is non whitespace.
public getNonWhitespaceSibling ( integer $index, integer $direction, null | string $whitespaces = null ) : integer | null
$index integer token index
$direction integer direction for looking, +1 or -1
$whitespaces null | string whitespaces characters for Token::isWhitespace
리턴 integer | null

getPrevMeaningfulToken() 공개 메소드

Get index for closest previous token that is not a whitespace or comment.
public getPrevMeaningfulToken ( integer $index ) : integer | null
$index integer token index
리턴 integer | null

getPrevNonWhitespace() 공개 메소드

This method is shorthand for getNonWhitespaceSibling method.
public getPrevNonWhitespace ( integer $index, null | string $whitespaces = null ) : integer | null
$index integer token index
$whitespaces null | string whitespaces characters for Token::isWhitespace
리턴 integer | null

getPrevTokenOfKind() 공개 메소드

This method is shorthand for getTokenOfKindSibling method.
public getPrevTokenOfKind ( integer $index, array $tokens = [], boolean $caseSensitive = true ) : integer | null
$index integer token index
$tokens array possible tokens
$caseSensitive boolean perform a case sensitive comparison
리턴 integer | null

getTokenNotOfKindSibling() 공개 메소드

Get index for closest sibling token not of given kind.
public getTokenNotOfKindSibling ( integer $index, integer $direction, array $tokens = [] ) : integer | null
$index integer token index
$direction integer direction for looking, +1 or -1
$tokens array possible tokens
리턴 integer | null

getTokenOfKindSibling() 공개 메소드

Get index for closest sibling token of given kind.
public getTokenOfKindSibling ( integer $index, integer $direction, array $tokens = [], boolean $caseSensitive = true ) : integer | null
$index integer token index
$direction integer direction for looking, +1 or -1
$tokens array possible tokens
$caseSensitive boolean perform a case sensitive comparison
리턴 integer | null

insertAt() 공개 메소드

Insert instances of Token inside collection.
public insertAt ( integer $index, Tokens | PhpCsFixer\Tokenizer\Token[] | PhpCsFixer\Tokenizer\Token $items )
$index integer start inserting index
$items Tokens | PhpCsFixer\Tokenizer\Token[] | PhpCsFixer\Tokenizer\Token instances of Token to insert

isAllTokenKindsFound() 공개 메소드

Check if all token kinds given as argument are found.
public isAllTokenKindsFound ( array $tokenKinds ) : boolean
$tokenKinds array
리턴 boolean

isAnyTokenKindsFound() 공개 메소드

Check if any token kind given as argument is found.
public isAnyTokenKindsFound ( array $tokenKinds ) : boolean
$tokenKinds array
리턴 boolean

isChanged() 공개 메소드

Check if collection was change: collection itself (like insert new tokens) or any of collection's elements.
public isChanged ( ) : boolean
리턴 boolean

isMonolithicPhp() 공개 메소드

Checks that the code is pure PHP code, in a single code block, starting with an open tag.
public isMonolithicPhp ( ) : boolean
리턴 boolean

isPartialCodeMultiline() 공개 메소드

Check if partial code is multiline.
public isPartialCodeMultiline ( integer $start, integer $end ) : boolean
$start integer start index
$end integer end index
리턴 boolean

isTokenKindFound() 공개 메소드

Check if token kind given as argument is found.
public isTokenKindFound ( integer | string $tokenKind ) : boolean
$tokenKind integer | string
리턴 boolean

offsetSet() 공개 메소드

Warning! $newval must not be typehinted to be compatible with ArrayAccess::offsetSet method.
public offsetSet ( integer $index, PhpCsFixer\Tokenizer\Token $newval )
$index integer
$newval PhpCsFixer\Tokenizer\Token

offsetUnset() 공개 메소드

Unset collection item.
public offsetUnset ( integer $index )
$index integer

overrideAt() 공개 메소드

Override token at given index and register it.
public overrideAt ( integer $index, PhpCsFixer\Tokenizer\Token | array | string $token )
$index integer
$token PhpCsFixer\Tokenizer\Token | array | string token prototype

overrideRange() 공개 메소드

Override tokens at given range.
public overrideRange ( integer $indexStart, integer $indexEnd, Tokens | PhpCsFixer\Tokenizer\Token[] $items )
$indexStart integer start overriding index
$indexEnd integer end overriding index
$items Tokens | PhpCsFixer\Tokenizer\Token[] tokens to insert

removeLeadingWhitespace() 공개 메소드

Removes all the leading whitespace.
public removeLeadingWhitespace ( integer $index, null | string $whitespaces = null )
$index integer
$whitespaces null | string optional whitespaces characters for Token::isWhitespace

removeTrailingWhitespace() 공개 메소드

Removes all the trailing whitespace.
public removeTrailingWhitespace ( integer $index, null | string $whitespaces = null )
$index integer
$whitespaces null | string optional whitespaces characters for Token::isWhitespace

setCode() 공개 메소드

Set code. Clear all current content and replace it by new Token items generated from code directly.
public setCode ( string $code )
$code string PHP code

setSize() 공개 메소드

Set new size of collection.
public setSize ( integer $size )
$size integer

toJson() 공개 메소드

public toJson ( )