Overview

Namespaces

  • NGS
    • Client
      • Exception
    • Converter
    • Patterns
  • PHP

Classes

  • BigDecimalConverter
  • BigIntConverter
  • ByteStreamConverter
  • LocalDateConverter
  • MoneyConverter
  • ObjectConverter
  • PrimitiveConverter
  • TimestampConverter
  • UUIDConverter
  • XmlConverter

Interfaces

  • ConverterInterface
  • Overview
  • Namespace
  • Class
  • Tree

Class PrimitiveConverter

Converts values to primitive php types (string, integer, float, boolean)

Abstract
Namespace: NGS\Converter
Located at Converter/PrimitiveConverter.php
Methods summary
public static integer
# toInteger( float|integer|string $value )

Converts value to integer type

Converts value to integer type

Parameters

$value
float|integer|string
$value

Returns

integer

Throws

InvalidArgumentException
If $value cannot be converted to integer
public static array
# toIntegerArray( array $items, mixed $allowNullValues = false )

Converts all values in array to integer types. Resulting array will be reindexed with numeric indices.

Converts all values in array to integer types. Resulting array will be reindexed with numeric indices.

Parameters

$items
array
$items
$allowNullValues

Returns

array

Throws

InvalidArgumentException
If any element in array containts null value or cannot be converted to integer
public static string
# toString( mixed $value )

Converts value to string

Converts value to string

Parameters

$value
mixed
$value Value

Returns

string
Resulting string

Throws

InvalidArgumentException
If value cannot be converted to string, or its length exceeds given $length
public static string
# toFixedString( mixed $value, integer $length )

Converts value to string and checks it doesn't exceed maximum length

Converts value to string and checks it doesn't exceed maximum length

Parameters

$value
mixed
$value Value
$length
integer
$length Maximum allowed string length

Returns

string
Resulting string

Throws

InvalidArgumentException
If value cannot be converted to string, or its length exceeds given $length
public static array
# toStringArray( array $items, mixed $allowNullValues = false )

Converts all values in array to string types. Resulting array will be reindexed with numeric indices.

Converts all values in array to string types. Resulting array will be reindexed with numeric indices.

Parameters

$items
array
$items Array of values convertible to strings
$allowNullValues

Returns

array
Array of strings with reindexed keys

Throws

InvalidArgumentException
If any array element cannot be converted to string
public static array
# toFixedStringArray( array $items, type $length, mixed $allowNullValues = false )

Converts all values in array to string types and checks that each string length doesn't exceed maximum length. Resulting array will be reindexed with numeric indices.

Converts all values in array to string types and checks that each string length doesn't exceed maximum length. Resulting array will be reindexed with numeric indices.

Parameters

$items
array
$items Array of values convertible to strings
$length
type
$length Maximum allowed string length
$allowNullValues

Returns

array
Array of strings with reindexed keys

Throws

InvalidArgumentException
If any array element cannot be converted to string, or its value exceeds given $length
public static boolean
# toBoolean( boolean|string|integer $value )

Converts value to boolean; valid string values are: 'true','1', 'on','false','0','off' (all case-insensitive); valid integer values are 0 and 1

Converts value to boolean; valid string values are: 'true','1', 'on','false','0','off' (all case-insensitive); valid integer values are 0 and 1

Parameters

$value
boolean|string|integer
Source value

Returns

boolean
Converted value

Throws

InvalidArgumentException
If value cannot be converted to boolean
public static array
# toBooleanArray( array $items, mixed $allowNullValues = false )

Converts all values in array to bool types. Resulting array will be reindexed with numeric indices. For list of valid values, see: NGS\Converter\PrimitiveConverter::toBoolean()

Converts all values in array to bool types. Resulting array will be reindexed with numeric indices. For list of valid values, see: NGS\Converter\PrimitiveConverter::toBoolean()

Parameters

$items
array
$items Array of values convertible to booleans.
$allowNullValues

Returns

array
Array of booleans with reindexed keys

Throws

InvalidArgumentException
If any array element cannot be converted to string, or its value exceeds given $length
public static float
# toFloat( boolean|string|integer $value )

Converts value to float.

Converts value to float.

Parameters

$value
boolean|string|integer
Source value

Returns

float
Converted value

Throws

InvalidArgumentException
If value cannot be converted to float
public static array
# toFloatArray( array $items, mixed $allowNullValues = false )

Converts all values in array to float types. Resulting array will be reindexed with numeric indices.

Converts all values in array to float types. Resulting array will be reindexed with numeric indices.

Parameters

$items
array
$items
$allowNullValues

Returns

array

Throws

InvalidArgumentException
If any element in array containts null value or cannot be converted to float
public static array
# toMap( array $items )

Converts all values in array to string type. As toStringArray, but preserves original array keys.

Converts all values in array to string type. As toStringArray, but preserves original array keys.

Parameters

$items
array
$items Array of values convertible to strings

Returns

array
Array of strings with preserved original keys

Throws

InvalidArgumentException
If any array element cannot be converted to string
public static array
# toMapArray( array $items )

Converts all values in array to string map (string array), runs toMap() on each element.

Converts all values in array to string map (string array), runs toMap() on each element.

Parameters

$items
array
$items Array of string maps

Returns

array
Array of string arrays with preserved original keys

Throws

InvalidArgumentException
If any array element cannot be converted to string map
API documentation generated by ApiGen 2.8.0