class FiveSeven extends Parser (View source)

The token parser for concrete5 5.7+ packages.

Properties

protected Strings $stringValidator

The string validator service to be used to check the validity of handles.

from  Parser

Methods

__construct(Strings $stringValidator)

Initialize the instance.

from  Parser
bool
canParseTokens(array $tokens)

Determine if this parser can be used for the specified PHP tokens of the package controlller.php file.

extractInfo(array $tokens)

Extract package details from the PHP tokens of the package controller.php file.

from  Parser
string
getControllerClassNameRegularExpression()

Get the regular expression that the controller class name must match (without the namespace).

string
getDefaultPackageMinimumCodeVersion()

Get the default minimum core version when the package doesn't specify it.

getPackageHandleFromClassName(array $tokens, string $className, int $classStart)

Extract the package handle from the fully-qualified class name.

array[]
findControllerClass(array $tokens)

Find the package controller class.

from  Parser
string
getPackageHandle(array $tokens, string $className, int $classStart, int $classEnd)

Get the package handle.

from  Parser
string
getPackageVersion(array $tokens, string $className, int $classStart, int $classEnd)

Get the package version.

from  Parser
string
getPackageName(array $tokens, string $className, int $classStart, int $classEnd)

Get the package name.

from  Parser
string
getPackageDescription(array $tokens, string $className, int $classStart, int $classEnd)

Get the package description.

from  Parser
string
getPackageMinimumCodeVersion(array $tokens, string $className, int $classStart, int $classEnd)

Get the minimum supported core version.

from  Parser
string
getPackageMinimumPHPVersion(array $tokens, string $className, int $classStart, int $classEnd)

Get the minimum supported PHP version.

from  Parser
mixed
getPropertyValue(array $tokens, string $propertyName, int $classStart, int $classEnd)

Get the value of a class property.

from  Parser
mixed
getSimpleMethodReturnValue(array $tokens, string $methodName, int $classStart, int $classEnd)

Get the return value of a class method.

from  Parser
int[]|null
getSimpleMethodBodyTokenRange(array $tokens, string $methodName, int $classStart, int $classEnd)

Get token range of the body of a very simple class method (that is, containing only a "return something;").

from  Parser
bool
isVersionValid(string|mixed $version)

Check if a version is valid.

from  Parser
int|null
findTypedToken(array $tokens, array $tokenIDs, int $startIndexInclusive = 0, int|null $endIndexExclusive = null)

Find the index of a token given its type.

from  Parser
int|null
findTextToken(array $tokens, array $tokenContent, int $startIndexInclusive = 0, int|null $endIndexExclusive = null)

Find the index of a text token given its contents.

from  Parser
array
stripNonCodeTokens(array $tokens, int $startIndexInclusive = 0, int|null $endIndexExclusive = null)

Strip whitespaces and comments from a list of tokens.

from  Parser
array
stripTFunctionCall(array $tokens)

Strip t() function calls at the beginning of a list of tokens tokens (if any).

from  Parser
array
stripEnclosingParenthesis(array $tokens)

Strip enclosing parenthesis ("(...)") (if any) in a list of tokens.

from  Parser
int|null
skipNonCodeTokens(array $tokens, int $startIndexInclusive = 0, int|null $endIndexExclusive = null)

Skip to the next non-whitespace and non-comment token.

from  Parser
mixed
decodeValueToken(array $token, string $associatedName)

Get the actual PHP value described by a value token.

from  Parser
string
decodeString(string $string)

Decode the value of a T_CONSTANT_ENCAPSED_STRING token.

from  Parser

Details

__construct(Strings $stringValidator)

Initialize the instance.

Parameters

Strings $stringValidator

the string validator service to be used to check the validity of handles

bool canParseTokens(array $tokens)

Determine if this parser can be used for the specified PHP tokens of the package controlller.php file.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

Return Value

bool

See also

Parser::canParseTokens

PackageInfo extractInfo(array $tokens)

Extract package details from the PHP tokens of the package controller.php file.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

Return Value

PackageInfo

Exceptions

Exception

protected string getControllerClassNameRegularExpression()

Get the regular expression that the controller class name must match (without the namespace).

protected string getDefaultPackageMinimumCodeVersion()

Get the default minimum core version when the package doesn't specify it.

Return Value

string

See also

Parser::getDefaultPackageMinimumCodeVersion

protected PackageInfo getPackageHandleFromClassName(array $tokens, string $className, int $classStart)

Extract the package handle from the fully-qualified class name.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $className

the class name of the package controller

int $classStart

the index of the first PHP token of the class body (its first '{')

Return Value

PackageInfo

Exceptions

Exception

See also

Parser::getPackageHandleFromClassName

protected array[] findControllerClass(array $tokens)

Find the package controller class.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

Return Value

array[]

[$className, $classStart, $classEnd] returns the class name, the index of the first PHP token of the class body (its first '{'}, and the index of the last PHP token of the class body (its last '}'}

Exceptions

Exception

protected string getPackageHandle(array $tokens, string $className, int $classStart, int $classEnd)

Get the package handle.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $className

the class name of the package controller

int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

string

Exceptions

Exception

protected string getPackageVersion(array $tokens, string $className, int $classStart, int $classEnd)

Get the package version.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $className

the class name of the package controller

int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

string

Exceptions

Exception

protected string getPackageName(array $tokens, string $className, int $classStart, int $classEnd)

Get the package name.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $className

the class name of the package controller

int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

string

Exceptions

Exception

protected string getPackageDescription(array $tokens, string $className, int $classStart, int $classEnd)

Get the package description.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $className

the class name of the package controller

int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

string

Exceptions

Exception

protected string getPackageMinimumCodeVersion(array $tokens, string $className, int $classStart, int $classEnd)

Get the minimum supported core version.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $className

the class name of the package controller

int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

string

Exceptions

Exception

protected string getPackageMinimumPHPVersion(array $tokens, string $className, int $classStart, int $classEnd)

Get the minimum supported PHP version.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $className

the class name of the package controller

int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

string

Exceptions

Exception

protected mixed getPropertyValue(array $tokens, string $propertyName, int $classStart, int $classEnd)

Get the value of a class property.

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $propertyName
int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

mixed

Exceptions

Exception

protected mixed getSimpleMethodReturnValue(array $tokens, string $methodName, int $classStart, int $classEnd)

Get the return value of a class method.

Get the value returned from a very simple class method (that is, containing only a "return something;").

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $methodName
int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

mixed

Exceptions

Exception

protected int[]|null getSimpleMethodBodyTokenRange(array $tokens, string $methodName, int $classStart, int $classEnd)

Get token range of the body of a very simple class method (that is, containing only a "return something;").

Parameters

array $tokens

the PHP tokens of the package controlller.php file

string $methodName
int $classStart

the index of the first PHP token of the class body (its first '{')

int $classEnd

the index of the last PHP token of the class body (its last '}'}

Return Value

int[]|null

returns null if it can't be detected (for example, for abstract methods), the token index of the opening '{' and the token index of the closing '}' otherwise

Exceptions

Exception

protected bool isVersionValid(string|mixed $version)

Check if a version is valid.

Parameters

string|mixed $version

Return Value

bool

protected int|null findTypedToken(array $tokens, array $tokenIDs, int $startIndexInclusive = 0, int|null $endIndexExclusive = null)

Find the index of a token given its type.

Parameters

array $tokens

the list of PHP tokens where the search should be performed

array $tokenIDs

the list of token identifiers to be searched

int $startIndexInclusive

the initial index where the search should start (inclusive)

int|null $endIndexExclusive

the final index where the search should end (exclusive); if null we'll search until the end of the token list

Return Value

int|null

the index of the first token with an ID included in $tokenIDs otherwise; return NULL of none of the token ID have been found

protected int|null findTextToken(array $tokens, array $tokenContent, int $startIndexInclusive = 0, int|null $endIndexExclusive = null)

Find the index of a text token given its contents.

Parameters

array $tokens

the list of PHP tokens where the search should be performed

array $tokenContent

the list of token values to be searched

int $startIndexInclusive

the initial index where the search should start (inclusive)

int|null $endIndexExclusive

the final index where the search should end (exclusive); if null we'll search until the end of the token list

Return Value

int|null

the index of the first string token found; return NULL of none of the strings have been found

protected array stripNonCodeTokens(array $tokens, int $startIndexInclusive = 0, int|null $endIndexExclusive = null)

Strip whitespaces and comments from a list of tokens.

Parameters

array $tokens

the list of PHP tokens to be processed

int $startIndexInclusive

the initial index where the search should start (inclusive)

int|null $endIndexExclusive

the final index where the search should end (exclusive); if null we'll search until the end of the token list

Return Value

array

protected array stripTFunctionCall(array $tokens)

Strip t() function calls at the beginning of a list of tokens tokens (if any).

Parameters

array $tokens

the list of PHP tokens to be processed

Return Value

array

protected array stripEnclosingParenthesis(array $tokens)

Strip enclosing parenthesis ("(...)") (if any) in a list of tokens.

Parameters

array $tokens

the list of PHP tokens to be processed

Return Value

array

protected int|null skipNonCodeTokens(array $tokens, int $startIndexInclusive = 0, int|null $endIndexExclusive = null)

Skip to the next non-whitespace and non-comment token.

Parameters

array $tokens

the whole list of tokens

int $startIndexInclusive

the initial index where the search should start (inclusive)

int|null $endIndexExclusive

the final index where the search should end (exclusive); if null we'll search until the end of the token list

Return Value

int|null

the next index of non-whitespace and non-comment token; NULL when arriving to the end of the array

protected mixed decodeValueToken(array $token, string $associatedName)

Get the actual PHP value described by a value token.

Parameters

array $token

the token containing the value

string $associatedName

the name associated to the value (used to display a useful error message),

Return Value

mixed

Exceptions

Exception

protected string decodeString(string $string)

Decode the value of a T_CONSTANT_ENCAPSED_STRING token.

Parameters

string $string

the value of a T_CONSTANT_ENCAPSED_STRING token

Return Value

string

Exceptions

Exception