Parses string representations into their corresponding native PHP variable type. The base implementation does a simple type-check.
Methods | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
final
public
|
parse(mixed $var, int $type, bool $allow_null = false): string
Validate a variable according to type.
It may return NULL as a valid type if $allow_null is true.
Validate a variable according to type. It may return NULL as a valid type if $allow_null is true. Parameters
ReturnsValidated and type-coerced variable Throws
|
# | ||||||||
protected
|
parseImplementation(mixed $var, int $type, bool $allow_null): string
Actually implements the parsing. Base implementation does not
do anything to $var. Subclasses should overload this!
Actually implements the parsing. Base implementation does not do anything to $var. Subclasses should overload this! Overriden by |
# | ||||||||
protected
|
error($msg)
Throws an exception.
|
# | ||||||||
protected
|
errorInconsistent(string $class, int $type)
Throws an inconsistency exception.
|
# | ||||||||
protected
|
errorGeneric(mixed $var, int $type)
Generic error for if a type didn't work.
Generic error for if a type didn't work. |
# | ||||||||
public
static
|
getTypeName(int $type): string
|
# |
Constants | ||
---|---|---|
public
|
C_STRING = 1
|
# |
public
|
ISTRING = 2
|
# |
public
|
TEXT = 3
|
# |
public
|
ITEXT = 4
|
# |
public
|
C_INT = 5
|
# |
public
|
C_FLOAT = 6
|
# |
public
|
C_BOOL = 7
|
# |
public
|
LOOKUP = 8
|
# |
public
|
ALIST = 9
|
# |
public
|
HASH = 10
|
# |
public
|
C_MIXED = 11
|
# |
Properties | |||
---|---|---|---|
public
static
|
|
$types = [
'string' => self::C_STRING,
'istring' => self::ISTRING,
'text' => self::TEXT,
'itext' => self::ITEXT,
'int' => self::C_INT,
'float' => self::C_FLOAT,
'bool' => self::C_BOOL,
'lookup' => self::LOOKUP,
'list' => self::ALIST,
'hash' => self::HASH,
'mixed' => self::C_MIXED,
]
Lookup table of allowed types. Mainly for backwards compatibility, but
also convenient for transforming string type…
Lookup table of allowed types. Mainly for backwards compatibility, but also convenient for transforming string type names to the integer constants. |
# |
public
static
|
|
$stringTypes = [self::C_STRING => true, self::ISTRING => true, self::TEXT => true, self::ITEXT => true]
Lookup table of types that are string, and can have aliases or
allowed value lists.
Lookup table of types that are string, and can have aliases or allowed value lists. |
# |