Download the PHP package joomla/data without Composer
On this page you can find all versions of the php package joomla/data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package data
Short Description Joomla Data Package
License GPL-2.0-or-later
Homepage https://github.com/joomla-framework/data
Informations about the package data
The Data Package
Data\DataObject
Data\DataObject
is a class that is used to store data but allowing you to access the data by mimicking the way PHP handles class properties. Rather than explicitly declaring properties in the class, Data\DataObject
stores virtual properties of the class in a private internal array. Concrete properties can still be defined but these are separate from the data.
Construction
The constructor for a new Data\DataObject
object can optionally take an array or an object. The keys of the array or the properties of the object will be bound to the properties of the Data\DataObject
object.
General Usage
Data\DataObject
includes magic getters and setters to provide access to the internal property store as if they were explicitly declared properties of the class.
The bind
method allows for injecting an existing array or object into the Data\DataObject
object.
The dump
method gets a plain stdClass
version of the Data\DataObject
object's properties. It will also support recursion to a specified number of levels where the default is 3 and a depth of 0 would return a stdClass
object with all the properties in native form. Note that the dump
method will only return virtual properties set binding and magic methods. It will not include any concrete properties defined in the class itself.
The JsonSerializable
interface is implemented. This method proxies to the dump
method (defaulting to a recursion depth of 3). Note that this interface only takes effect implicitly in PHP 5.4 so any code built for PHP 5.3 needs to explicitly use either the jsonSerialize
or the dump
method before passing to json_encode
.
The Data\DataObject
class also implements the IteratorAggregate
interface so it can easily be used in a foreach
statement.
Data\DataSet
Data\DataSet
is a collection class that allows the developer to operate on a list of Data\DataObject
objects as if they were in a typical PHP array (Data\DataSet
implements the ArrayAccess
, Countable
and Iterator
interfaces).
Construction
A typical Data\DataSet
object will be instantiated by passing an array of Data\DataObject
objects in the constructor.
General Usage
Array elements can be manipulated with the offsetSet
and offsetUnset
methods, or by using PHP array nomenclature.
The magic __get
method in the Data\DataSet
class effectively works like a "get column" method. It will return an array of values of the properties for all the objects in the list.
The magic __set
method is similar and works like a "set column" method. It will set all a value for a property for all the objects in the list.
The clear
method will clear all the objects in the data set.
The keys
method will return all of the keys of the objects stored in the set. It works like the array_keys
function does on an PHP array.
Data\DataSet
supports magic methods that operate on all the objects in the list. Calling an arbitrary method will iterate of the list of objects, checking if each object has a callable method of the name of the method that was invoked. In such a case, the return values are assembled in an array forming the return value of the method invoked on the Data\DataSet
object. The keys of the original objects are maintained in the result array.
Data\DumpableInterface
Data\DumpableInterface
is an interface that defines a dump
method for dumping the properties of an object as a stdClass
with or without recursion.
Installation via Composer
Add "joomla/data": "~3.0"
to the require block in your composer.json and then run composer install
.
Alternatively, you can simply run the following from the command line:
If you want to include the test sources, use