Exports a Collection instance to an array. Used by Collection::to().
public static toArray ( mixed $data, array $options = [] ) : array | ||
$data | mixed | Either a `Collection` instance, or an array representing a `Collection`'s internal state. |
$options | array | Options used when converting `$data` to an array: - `'handlers'` _array_: An array where the keys are fully-namespaced class names, and the values are closures that take an instance of the class as a parameter, and return an array or scalar value that the instance represents. |
return | array | Returns the value of `$data` as a pure PHP array, recursively converting all sub-objects and other values to their closest array or scalar equivalents. |
/** * Adds conversions checks to ensure certain class types and embedded values are properly cast. * * @param string $format Currently only `array` is supported. * @param array $options * @return mixed */ public function to($format, array $options = array()) { $defaults = array('handlers' => array( 'MongoId' => function($value) { return (string) $value; }, 'MongoDate' => function($value) { return $value->sec; } )); if ($format == 'array') { $options += $defaults; return Collection::toArray($this->_data, $options); } return parent::to($format, $options); }
/** * Converts the data in the record set to a different format, i.e. an array. * * @param string $format currently only `array` * @param array $options * @return mixed */ public function to($format, array $options = array()) { switch ($format) { case 'array': $result = Col::toArray($this->_data); break; default: $result = $this; break; } return $result; }
/** * Convert entity to some other format * * @param string $format Conversion format eg. `'array'` * @param array $options Options that will be passed to `\lithium\util\Collection::toArray()` * * @return mixed `$this` or `lithium\util\Collection::toArray()` * @see lithium\util\Collection::toArray() */ public function to($format, array $options = array()) { switch ($format) { case 'array': return Collection::toArray(array('name' => $this->_name, 'dir' => $this->_dir, 'url' => $this->_url, 'path' => $this->_path, 'size' => $this->_size, 'mode' => $this->_mode), $options); default: return $this; } }
/** * @todo datasource */ public static function read($url) { $xml = @simplexml_load_file($url); return Collection::toArray($xml); }