abstract class TypeHandling (View source)

PHP type handling functions

Constants

PARSE_TYPE_PATTERN

A property type parse pattern.

LITERAL_TYPE_PATTERN

A type pattern to detect literal types.

Properties

static protected array $collectionTypes

Methods

static array
parseType(string $type)

Returns an array with type information, including element type for collection types (array, SplObjectStorage, ...)

static string
normalizeType(string $type)

Normalize data types so they match the PHP type names: int -> integer double -> float bool -> boolean

static bool
isLiteral(string $type)

Returns true if the $type is a literal.

static bool
isSimpleType(string $type)

Returns true if the $type is a simple type.

static bool
isCollectionType(string $type)

Returns true if the $type is a collection type.

static bool
isUnionType(string $type)

Returns true if the $type is a union type.

static bool
isIntersectionType(string $type)

Returns true if the $type is an intersection type.

static string
truncateElementType(string $type)

Parses a composite type like "\Foo\Collection<\Bar\Entity>" into "\Foo\Collection" Note: If the given type does not specify an element type it is not changed

static string
stripNullableType(string $type)

No description

static string
getTypeForValue(mixed $value)

Return simple type or class for object

Details

static array parseType(string $type)

Returns an array with type information, including element type for collection types (array, SplObjectStorage, ...)

Parameters

string $type

Type of the property (see PARSE_TYPE_PATTERN)

Return Value

array

An array with information about the type

Exceptions

InvalidTypeException

static string normalizeType(string $type)

Normalize data types so they match the PHP type names: int -> integer double -> float bool -> boolean

Parameters

string $type

Data type to unify

Return Value

string

unified data type

static bool isLiteral(string $type)

Returns true if the $type is a literal.

Parameters

string $type

Return Value

bool

static bool isSimpleType(string $type)

Returns true if the $type is a simple type.

Parameters

string $type

Return Value

bool

static bool isCollectionType(string $type)

Returns true if the $type is a collection type.

Parameters

string $type

Return Value

bool

static bool isUnionType(string $type)

Returns true if the $type is a union type.

Parameters

string $type

Return Value

bool

static bool isIntersectionType(string $type)

Returns true if the $type is an intersection type.

Parameters

string $type

Return Value

bool

static string truncateElementType(string $type)

Parses a composite type like "\Foo\Collection<\Bar\Entity>" into "\Foo\Collection" Note: If the given type does not specify an element type it is not changed

Parameters

string $type

Return Value

string

The original type without its element type (if any)

static string stripNullableType(string $type)

No description

Parameters

string $type

Return Value

string

The original type without an optional "null" type information

static string getTypeForValue(mixed $value)

Return simple type or class for object

Parameters

mixed $value

Return Value

string