PHP Class JBZoo\Data\Data

Inheritance: extends ArrayObject
ファイルを表示 Open project: jbzoo/data Class Usage Examples

Public Methods

Method Description
__construct ( array | string $data = [] ) Class constructor
__toString ( ) : string Magic method to convert the data to a string Returns a serialized version of the data contained in the data object using serialize()
find ( string $key, mixed $default = null, mixed $filter = null, string $separator = '.' ) : mixed Find a key in the data recursively This method finds the given key, searching also in any array or object that's nested under the current data object.
flattenRecursive ( ) : array Return flattened array copy. Keys are NOT preserved.
get ( string $key, mixed $default = null, mixed $filter = null ) : mixed Get a value from the data given its key
has ( string $name ) : boolean Checks if the given key is present
is ( string $key, mixed $compareWith = true, boolean $strictMode = false ) : boolean Compare value by key with somethig
offsetGet ( $index )
remove ( string $name ) Remove a value from the data
search ( mixed $needle ) : string | false Find a value also in nested arrays/objects
set ( string $name, mixed $value ) Set a value in the data
write ( ) : string Encode an array or an object in INI format

Protected Methods

Method Description
_decode ( string $string ) : mixed Utility Method to unserialize the given data
_encode ( mixed $data ) : string Utility Method to serialize the given data
_filter ( mixed $value, mixed $filter ) : mixed Filter value before return
_isMulti ( $array ) : boolean Check is array is nested
_readFile ( string $filePath ) : null | string

Method Details

__construct() public method

Class constructor
public __construct ( array | string $data = [] )
$data array | string The data array

__toString() public method

Magic method to convert the data to a string Returns a serialized version of the data contained in the data object using serialize()
public __toString ( ) : string
return string

_decode() protected method

Utility Method to unserialize the given data
protected _decode ( string $string ) : mixed
$string string
return mixed

_encode() protected method

Utility Method to serialize the given data
protected _encode ( mixed $data ) : string
$data mixed The data to serialize
return string The serialized data

_filter() protected method

Filter value before return
protected _filter ( mixed $value, mixed $filter ) : mixed
$value mixed
$filter mixed
return mixed

_isMulti() protected method

Check is array is nested
protected _isMulti ( $array ) : boolean
$array
return boolean

_readFile() protected method

protected _readFile ( string $filePath ) : null | string
$filePath string
return null | string

find() public method

Example: $data->find('parentkey.subkey.subsubkey');
public find ( string $key, mixed $default = null, mixed $filter = null, string $separator = '.' ) : mixed
$key string The key to search for. Can be composed using $separator as the key/subkey separator
$default mixed The default value
$filter mixed Filter returned value
$separator string The separator to use when searching for subkeys. Default is '.'
return mixed

flattenRecursive() public method

Return flattened array copy. Keys are NOT preserved.
public flattenRecursive ( ) : array
return array

get() public method

Get a value from the data given its key
public get ( string $key, mixed $default = null, mixed $filter = null ) : mixed
$key string The key used to fetch the data
$default mixed The default value
$filter mixed Filter returned value
return mixed

has() public method

Checks if the given key is present
public has ( string $name ) : boolean
$name string The key to check
return boolean

is() public method

Compare value by key with somethig
public is ( string $key, mixed $compareWith = true, boolean $strictMode = false ) : boolean
$key string
$compareWith mixed
$strictMode boolean
return boolean

offsetGet() public method

public offsetGet ( $index )

remove() public method

Remove a value from the data
public remove ( string $name )
$name string The key of the data to remove

set() public method

Set a value in the data
public set ( string $name, mixed $value )
$name string The key used to set the value
$value mixed The value to set

write() public method

Encode an array or an object in INI format
public write ( ) : string
return string