DataSet

Implements \Joomla\Data\DumpableInterface, \ArrayAccess, \Countable, \Iterator

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

since

1.0

Methods

__call

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

__call(string $method, array $arguments = array()) : array

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

arrayThe arguments of the method called.

Response

arrayAn array of values returned by the methods called on the objects in the data set.

__construct

The class constructor.

__construct(array<mixed,\Joomla\Data\DataObject> $objects = array()) 
since

1.0

throws

\InvalidArgumentExceptionif an object is not an instance of Data\Object.

Arguments

$objects

array<mixed,\Joomla\Data\DataObject>An array of DataObject objects to bind to the data set.

__get

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

__get(string $property) : array

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 Data\Object'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

arrayAn associative array of the values.

__isset

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

__isset(string $property) : boolean

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

since

1.0

Arguments

$property

stringThe name of the property.

Response

booleanTrue 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(string $property, mixed $value) : void

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 Data\Object).

since

1.0

Arguments

$property

stringThe name of the property.

$value

mixedThe value to give the data property.

__unset

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

__unset(string $property) : void

Example: unset($objectList->foo);

This will unset all of the 'foo' properties in the list of Data\Object's.

since

1.0

Arguments

$property

stringThe name of the property.

_initialise

Initialises the list with an array of objects.

_initialise(array $input = array()) : void
since

1.0

throws

\InvalidArgumentExceptionif an object is not an instance of Data\DataObject.

Arguments

$input

arrayAn array of objects.

clear

Clears the objects in the data set.

clear() : \Joomla\Data\DataSet
since

1.0

Response

\Joomla\Data\DataSetReturns itself to allow chaining.

count

Gets the number of data objects in the set.

count() : integer
since

1.0

Response

integerThe number of objects.

current

Get the current data object in the set.

current() : \Joomla\Data\DataObject
since

1.0

Response

\Joomla\Data\DataObjectThe 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(integer $depth = 3, \SplObjectStorage $dumped = null) : array
see \Joomla\Data\DataObject::dump()
since

1.0

Arguments

$depth

integerThe 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

\SplObjectStorageAn array of already serialized objects that is used to avoid infinite loops.

Response

arrayAn 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(string $type = 'all') : array
since

1.2.0

throws

\InvalidArgumentException

Arguments

$type

stringSelection type 'all' or 'common'

Response

arrayArray of keys

jsonSerialize

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

jsonSerialize(mixed $serialized = null) : array

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

Arguments

$serialized

mixedAn array of objects that have already been serialized that is used to infinite loops (null on first call).

Response

arrayAn array that can be serialised by json_encode().

key

Gets the key of the current object in the iterator.

key() : scalar
since

1.0

Response

scalarThe object key on success; null on failure.

keys

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

keys() : array
since

1.0

Response

arrayThe array of keys

next

Advances the iterator to the next object in the iterator.

next() : void
since

1.0

offsetExists

Checks whether an offset exists in the iterator.

offsetExists(mixed $offset) : boolean
since

1.0

Arguments

$offset

mixedThe object offset.

Response

booleanTrue if the object exists, false otherwise.

offsetGet

Gets an offset in the iterator.

offsetGet(mixed $offset) : \Joomla\Data\DataObject
since

1.0

Arguments

$offset

mixedThe object offset.

Response

\Joomla\Data\DataObjectThe object if it exists, null otherwise.

offsetSet

Sets an offset in the iterator.

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

1.0

throws

\InvalidArgumentExceptionif an object is not an instance of Data\Object.

Arguments

$offset

mixedThe object offset.

$object

\Joomla\Data\DataObjectThe object object.

offsetUnset

Unsets an offset in the iterator.

offsetUnset(mixed $offset) : void
since

1.0

Arguments

$offset

mixedThe object offset.

rewind

Rewinds the iterator to the first object.

rewind() : void
since

1.0

toArray

Gets all objects as an array

toArray(boolean $associative = true, string $k = null) : array
since

1.2.0

Arguments

$associative

booleanOption to set return mode: associative or numeric array.

$k

stringUnlimited optional property names to extract from objects.

Response

arrayReturns an array according to defined options.

valid

Validates the iterator.

valid() : boolean
since

1.0

Response

booleanTrue if valid, false otherwise.

walk

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

walk(callable $funcname) : boolean
since

1.2.0

throws

\InvalidArgumentException

Arguments

$funcname

callableCallback function.

Response

boolean

Properties

current

The current position of the iterator.

since

1.0

Type(s)

integer

objects

The iterator objects.

since

1.0

Type(s)

array<mixed,\Joomla\Data\DataObject>