DataSet

Implements DumpableInterface, ArrayAccess, Countable, Iterator

DataSet is a collection class that allows the developer to operate on a set of DataObjects as if they were in a typical PHP array.

since

1.0

package

Joomla Framework

Methods

__call

The magic call method is used to call object methods using the iterator.

__call( method, mixed||string|int arguments = []) : mixed||string|int

Example: $array = $objectList->foo('bar');

The object list will iterate over its objects and see if each object has a callable 'foo' method. If so, it will pass the argument list and assemble any return values. If an object does not have a callable method no return value is recorded. The keys of the objects and the result array are maintained.

since

1.0

Arguments

method

stringThe name of the method called.

arguments

array<string|int, mixed>The arguments of the method called.

Response

array<string|int, mixed>An array of values returned by the methods called on the objects in the data set.

__construct

The class constructor.

__construct(\Joomla\Data\DataObject||string|int objects = []) : 
since

1.0

throws

InvalidArgumentExceptionif an object is not a DataObject.

Arguments

objects

array<string|int, DataObject>An array of DataObject objects to bind to the data set.

Response

mixed

__get

The magic get method is used to get a list of properties from the objects in the data set.

__get( property) : mixed||string|int

Example: $array = $dataSet->foo;

This will return a column of the values of the 'foo' property in all the objects (or values determined by custom property setters in the individual DataObject's). The result array will contain an entry for each object in the list (compared to __call which may not). The keys of the objects and the result array are maintained.

since

1.0

Arguments

property

stringThe name of the data property.

Response

array<string|int, mixed>An associative array of the values.

__isset

The magic isset method is used to check the state of an object property using the iterator.

__isset( property) : 

Example: $array = isset($objectList->foo);

since

1.0

Arguments

property

stringThe name of the property.

Response

boolTrue if the property is set in any of the objects in the data set.

__set

The magic set method is used to set an object property using the iterator.

__set( property,  value) : 

Example: $objectList->foo = 'bar';

This will set the 'foo' property to 'bar' in all of the objects (or a value determined by custom property setters in the DataObject).

since

1.0

Arguments

property

stringThe name of the property.

value

mixedThe value to give the data property.

Response

void

__unset

The magic unset method is used to unset an object property using the iterator.

__unset( property) : 

Example: unset($objectList->foo);

This will unset all of the 'foo' properties in the list of DataObject's.

since

1.0

Arguments

property

stringThe name of the property.

Response

void

clear

Clears the objects in the data set.

clear() : \Joomla\Data\DataSet
since

1.0

Response

DataSetReturns itself to allow chaining.

count

Gets the number of data objects in the set.

count() : 
since

1.0

Response

intThe number of objects.

current

Get the current data object in the set.

current() : \Joomla\Data\DataObject|false
since

1.0

Response

DataObject|falseThe current object, or false if the array is empty or the pointer is beyond the end of the elements.

dump

Dumps the data object in the set, recursively if appropriate.

dump( depth = 3, \SplObjectStorage dumped = null) : mixed||string|int
see DataObject::dump()
since

1.0

Arguments

depth

intThe maximum depth of recursion (default = 3). For example, a depth of 0 will return a stdClass with all the properties in native form. A depth of 1 will recurse into the first level of properties only.

dumped

SplObjectStorage|nullAn array of already serialized objects that is used to avoid infinite loops.

Response

array<string|int, mixed>An associative array of the data objects in the set, dumped as a simple PHP stdClass object.

getObjectsKeys

Gets an array of keys, existing in objects

getObjectsKeys( type = 'all') : mixed||string|int
since

1.2.0

throws

InvalidArgumentException

Arguments

type

stringSelection type 'all' or 'common'

Response

array<string|int, mixed>Array of keys

initialise

Initialises the list with an array of objects.

initialise(mixed||string|int input = []) : 
since

1.0

throws

InvalidArgumentExceptionif an object is not a DataObject.

Arguments

input

array<string|int, mixed>An array of objects.

Response

void

jsonSerialize

Gets the data set in a form that can be serialised to JSON format.

jsonSerialize() : mixed||string|int

Note that this method will not return an associative array, otherwise it would be encoded into an object. JSON decoders do not consistently maintain the order of associative keys, whereas they do maintain the order of arrays.

since

1.0

Response

array<string|int, mixed>

key

Gets the key of the current object in the iterator.

key() : int|false
since

1.0

Response

int|falseThe object key on success; false on failure.

keys

Gets the array of keys for all the objects in the iterator (emulates array_keys).

keys() : mixed||string|int
since

1.0

Response

array<string|int, mixed>The array of keys

next

Advances the iterator to the next object in the iterator.

next() : 
since

1.0

Response

void

offsetExists

Checks whether an offset exists in the iterator.

offsetExists( offset) : 
since

1.0

Arguments

offset

mixedThe object offset.

Response

bool

offsetGet

Gets an offset in the iterator.

offsetGet( offset) : \Joomla\Data\DataObject|null
since

1.0

Arguments

offset

mixedThe object offset.

Response

DataObject|null

offsetSet

Sets an offset in the iterator.

offsetSet( offset, \Joomla\Data\DataObject object) : 
since

1.0

throws

InvalidArgumentExceptionif an object is not an instance of DataObject.

Arguments

offset

mixedThe object offset.

object

DataObjectThe object object.

Response

void

offsetUnset

Unsets an offset in the iterator.

offsetUnset( offset) : 
since

1.0

Arguments

offset

mixedThe object offset.

Response

void

rewind

Rewinds the iterator to the first object.

rewind() : 
since

1.0

Response

void

toArray

Gets all objects as an array

toArray( associative = true,  keys) : mixed||string|int
since

1.2.0

Arguments

associative

boolOption to set return mode: associative or numeric array.

keys

stringUnlimited optional property names to extract from objects.

Response

array<string|int, mixed>Returns an array according to defined options.

valid

Validates the iterator.

valid() : 
since

1.0

Response

bool

walk

Applies a function to every object in the set (emulates array_walk).

walk(
Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 841
|Array funcname) : 
since

1.2.0

throws

InvalidArgumentException

Arguments

funcname

callableCallback function.

Response

bool

Properties

current

The current position of the iterator.

since

1.0

Type(s)

int

objects

The iterator objects.

since

1.0

Type(s)

array<string|int, DataObject>