Download the PHP package donatj/printf-parser without Composer
On this page you can find all versions of the php package donatj/printf-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download donatj/printf-parser
More information about donatj/printf-parser
Files in donatj/printf-parser
Package printf-parser
Short Description PHP printf-syntax compatible printf string parser. Parses printf strings into a stream of lexemes.
License MIT
Informations about the package printf-parser
Printf Parser
PHP printf-syntax compatible printf string parser.
Parses printf strings into a stream of lexemes.
Requirements
- php: >=7.2
Installing
Install the latest version with:
Example
Here is a simple example:
Output:
Documentation
Class: donatj\Printf\Parser
Parser implements a PHP Printf compatible Printf string parser.
Method: Parser->__construct
Parser constructor.
Parameters:
- \donatj\Printf\Emitter
$emitter
- The given Emitter to emit Lexemes as parsed
Method: Parser->parseStr
Parses a printf string and emit parsed lexemes to the configured Emitter
Class: donatj\Printf\LexemeEmitter
Method: LexemeEmitter->getLexemes
Return the Lexemes received by the emitter as an immutable LexemeCollection
Class: donatj\Printf\LexemeCollection
LexemeCollection is an immutable iterable collection of Lexemes with ArrayAccess
Method: LexemeCollection->getInvalid
Retrieve the first invalid Lexeme or null if all are valid.
This is useful for checking if a printf string parsed without error.
Method: LexemeCollection->toArray
Get the LexemeCollection as an ordered array of Lexemes
Returns:
- \donatj\Printf\Lexeme[]
Method: LexemeCollection->argTypes
Returns the list of expected arguments a 1-indexed map of the following
Returns:
- string[]
Class: donatj\Printf\Lexeme
Lexeme represents a "basic" component of a printf string - either Literal Strings "!" or Invalid Lexemes
Method: Lexeme->__construct
LexItem constructor.
Method: Lexeme->getLexItemType
The type of the printf Lexeme
Method: Lexeme->getVal
The text of the lexeme
Method: Lexeme->getPos
The string position of the given lexeme
Class: donatj\Printf\ArgumentLexeme
Method: ArgumentLexeme->__construct
ArgumentLexeme constructor.
LexItem constructor.
Method: ArgumentLexeme->getArg
The position specifier, such as %3$s
would return 3 and %s
would return null
Returns:
- int | null - null on unspecified
Method: ArgumentLexeme->getShowPositive
Is the "Prefix positive numbers with a plus sign +" flag enabled
Method: ArgumentLexeme->getPadChar
Specified pad character flag
Returns:
- string | null - null on unspecified
Method: ArgumentLexeme->getPadWidth
Specified pad width
Returns:
- int | null - null on unspecified
Method: ArgumentLexeme->getLeftJustified
Is left-justification flag enabled?
Method: ArgumentLexeme->getPrecision
The Lexeme's indicated precision.
Returns:
- int | null - null on unspecified
Method: ArgumentLexeme->argType
Returns based on the type of argument one of the following
ArgumentLexeme::ARG_TYPE_MISSING
ArgumentLexeme::ARG_TYPE_INT
ArgumentLexeme::ARG_TYPE_DOUBLE
ArgumentLexeme::ARG_TYPE_STRING
Method: ArgumentLexeme->getLexItemType
The type of the printf Lexeme
Method: ArgumentLexeme->getVal
The text of the lexeme
Method: ArgumentLexeme->getPos
The string position of the given lexeme