예제 #1
0
 /**
  * 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':
             $data = $this->_updated;
             $rel = array_map(function ($obj) {
                 return $obj->data();
             }, $this->_relationships);
             $data = $rel + $data;
             $result = Collection::toArray($data, $options);
             break;
         case 'string':
             $result = $this->__toString();
             break;
         default:
             $result = $this;
             break;
     }
     return $result;
 }
예제 #2
0
파일: Entity.php 프로젝트: fedeisas/lithium
 /**
  * Converts the data in the record set to a different format, i.e. an array.
  *
  * @param string $format Currently only `array`.
  * @param array $options Options for converting:
  *        - `'indexed'` _boolean_: Allows to control how converted data of nested collections
  *          is keyed. When set to `true` will force indexed conversion of nested collection
  *          data. By default `false` which will only index the root level.
  * @return mixed
  */
 public function to($format, array $options = array())
 {
     $defaults = array('handlers' => array());
     $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;
 }