lithium\data\Entity::to()
Converts the data in the record set to a different format, i.e. an array.
Parameters
-
string
$formatCurrently only
array. -
array
$optionsOptions for converting:
'indexed'boolean: Allows to control how converted data of nested collections is keyed. When set totruewill force indexed conversion of nested collection data. By defaultfalsewhich will only index the root level.
Returns
mixedSource
public function to($format, array $options = []) {
$defaults = ['handlers' => []];
$options += $defaults;
$options['handlers'] += $this->_handlers;
switch ($format) {
case 'array':
$data = $this->_updated;
$rel = array_map(function($obj) { return $obj->data(); }, $this->_relationships);
$data = $rel + $data;
$options['indexed'] = isset($options['indexed']) ? $options['indexed'] : false;
$result = Collection::toArray($data, $options);
break;
case 'string':
$result = $this->__toString();
break;
default:
$result = $this;
break;
}
return $result;
}