Inheritance: extends lithium\util\Collection
Example #1
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 += array('handlers' => array('MongoId' => function ($value) {
         return (string) $value;
     }, 'MongoDate' => function ($value) {
         return $value->sec;
     }));
     $this->offsetGet(null);
     return parent::to($format, $options);
 }
Example #2
0
 /**
  * Initializes the record set and uses the database connection to get the column list contained
  * in the query that created this object.
  *
  * @see lithium\data\collection\RecordSet::$_columns
  * @return void
  * @todo The part that uses _handle->schema() should be rewritten so that the column list
  *       is coming from the query object.
  */
 protected function _init()
 {
     parent::_init();
     if ($this->_result) {
         $this->_columns = $this->_columnMap();
         if ($this->_query) {
             $columns = array_filter(array_keys($this->_columns));
             $this->_dependencies = Set::expand(Set::normalize($columns));
             $this->_keyIndex = $this->_keyIndex('');
         }
     }
 }
Example #3
0
 /**
  * Initializes the record set and uses the database connection to get the column list contained
  * in the query that created this object.
  *
  * @see lithium\data\collection\RecordSet::$_columns
  * @return void
  * @todo The part that uses _handle->schema() should be rewritten so that the column list
  *       is coming from the query object.
  */
 protected function _init()
 {
     parent::_init();
     if (!$this->_result) {
         return;
     }
     $this->_columns = $this->_columnMap();
     if (!$this->_query) {
         return;
     }
     $this->_keyIndex = $this->_keyIndex();
     $this->_dependencies = Set::expand(Set::normalize(array_filter(array_keys($this->_columns))));
     $this->_relationships = $this->_query->relationships();
 }
Example #4
0
 /**
  * Rewinds the collection of sub-`Document`s to the beginning and returns the first one found.
  *
  * @return object Returns the first `Document` object instance in the collection.
  */
 public function rewind()
 {
     $data = parent::rewind();
     $key = key($this->_data);
     return $this->offsetGet($key);
 }
 /**
  * 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;
 }
Example #6
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())
 {
     $this->offsetGet(null);
     return parent::to($format, $options);
 }
Example #7
0
 /**
  * Applies a callback to a copy of all data in the collection
  * and returns the result.
  *
  * Overriden to load any data that has not yet been loaded.
  *
  * @param callback $filter The filter to apply.
  * @param array $options The available options are:
  *              - `'collect'`: If `true`, the results will be returned wrapped
  *              in a new `Collection` object or subclass.
  * @return array|object The filtered data.
  */
 public function map($filter, array $options = array())
 {
     $this->offsetGet(null);
     return parent::map($filter, $options);
 }
Example #8
0
 /**
  * Rewinds the collection of sub-`Document`s to the beginning and returns the first one found.
  *
  * @return object Returns the first `Document` object instance in the collection.
  */
 public function rewind()
 {
     $data = parent::rewind() ?: $this->_populate();
     $key = key($this->_data);
     if (is_object($data)) {
         return $data;
     }
     if (isset($this->_data[$key])) {
         return $this->offsetGet($key);
     }
 }
Example #9
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 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;
 }
Example #10
0
 /**
  * Rewinds the collection of sub-`Document`s to the beginning and returns the first one found.
  *
  * @return object Returns the first `Document` object instance in the collection.
  */
 public function rewind()
 {
     $data = parent::rewind();
     $key = key($this->_data);
     if (is_a($data, $this->_classes['entity'])) {
         return $data;
     }
     if ($this->_isComplexType($data)) {
         $this->_data[$key] = $this->_relation('entity', $key, $this->_data[$key]);
     }
     return isset($this->_data[$key]) ? $this->_data[$key] : null;
 }