Medical Appointments API

DataTypeUtil
in package

Class DataTypeUtil

This utility class provides methods to extract and convert data to different data types.

Tags
author

Luis Graciano contacto@luisgraciano.dev

Table of Contents

extractBool()  : bool|null
Extracts a boolean value from an array using the provided key.
extractDatetime()  : DateTime|null
Extracts a DateTime value from an array using the provided key.
extractInt()  : int|null
Extracts an integer value from an array using the provided key.
extractString()  : string|null
Extracts a string value from an array using the provided key.
__construct()  : mixed
DataTypeUtil constructor.

Methods

extractBool()

Extracts a boolean value from an array using the provided key.

public static extractBool(array<string|int, mixed> $data, string $key[, bool|null $default = null ]) : bool|null
Parameters
$data : array<string|int, mixed>

The array to extract data from.

$key : string

The key to extract the data for.

$default : bool|null = null

The default value to return if the key is not found.

Return values
bool|null

The extracted boolean value or the default value if the key is not found.

extractDatetime()

Extracts a DateTime value from an array using the provided key.

public static extractDatetime(array<string|int, mixed> $data, string $key[, DateTime|null $default = null ]) : DateTime|null
Parameters
$data : array<string|int, mixed>

The array to extract data from.

$key : string

The key to extract the data for.

$default : DateTime|null = null

The default value to return if the key is not found.

Tags
throws
Exception

If there is an error creating the DateTime object.

Return values
DateTime|null

The extracted DateTime value or the default value if the key is not found.

extractInt()

Extracts an integer value from an array using the provided key.

public static extractInt(array<string|int, mixed> $data, string $key[, int|null $default = null ]) : int|null
Parameters
$data : array<string|int, mixed>

The array to extract data from.

$key : string

The key to extract the data for.

$default : int|null = null

The default value to return if the key is not found.

Return values
int|null

The extracted integer value or the default value if the key is not found.

extractString()

Extracts a string value from an array using the provided key.

public static extractString(array<string|int, mixed> $data, string $key[, string|null $default = null ]) : string|null
Parameters
$data : array<string|int, mixed>

The array to extract data from.

$key : string

The key to extract the data for.

$default : string|null = null

The default value to return if the key is not found.

Return values
string|null

The extracted string value or the default value if the key is not found.

__construct()

DataTypeUtil constructor.

private __construct() : mixed

This constructor is private to prevent instantiation of this class.

Return values
mixed

Search results