to() public method

Converts the data in the record set to a different format, i.e. an array.
public to ( string $format, array $options = [] ) : mixed
$format string Currently only `array`.
$options array 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
Beispiel #1
0
 /**
  * Converts a `Record` object to another specified format.
  *
  * @param string $format The format used by default is `array`
  * @param array $options
  * @return mixed
  */
 public function to($format, array $options = array())
 {
     $defaults = array('handlers' => array('stdClass' => function ($item) {
         return $item;
     }));
     $options += $defaults;
     return parent::to($format, $options);
 }
Beispiel #2
0
 public function testConversion()
 {
     $data = array('foo' => '!!', 'bar' => '??', 'baz' => '--');
     $entity = new Entity(compact('data'));
     $this->assertEqual($data, $entity->to('array'));
     $this->assertEqual($data, $entity->data());
     $this->assertEqual($entity, $entity->to('foo'));
 }
Beispiel #3
0
 public function testHandlers()
 {
     $handlers = array('stdClass' => function ($value) {
         return substr($value->scalar, -1);
     });
     $array = new Entity(compact('handlers') + array('data' => array('value' => (object) 'hello')));
     $expected = array('value' => 'o');
     $this->assertIdentical($expected, $array->to('array', array('indexed' => false)));
 }
Beispiel #4
0
 /**
  * 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())
 {
     $options['internal'] = false;
     return parent::to($format, $options);
 }
 /**
  * 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;
     }));
     $options += $defaults;
     $options['internal'] = false;
     return parent::to($format, $options);
 }
Beispiel #6
0
 /**
  * Converts a `Record` object to another specified format.
  *
  * @param string $format The format used by default is `array`
  * @param array $options
  * @return mixed
  */
 public function to($format, array $options = array())
 {
     return parent::to($format, $options);
 }