lithium\data\source\http\adapter\CouchDb::item PHP Method

item() public method

Returns a newly-created Document object, bound to a model and populated with default data and options.
public item ( string $model, array $data = [], array $options = [] ) : object
$model string A fully-namespaced class name representing the model class to which the `Document` object will be bound.
$data array The default data with which the new `Document` should be populated.
$options array Any additional options to pass to the `Document`'s constructor
return object Returns a new, un-saved `Document` object bound to the model class specified in `$model`.
    public function item($model, array $data = array(), array $options = array())
    {
        $defaults = array('class' => 'entity');
        $options += $defaults;
        if ($options['class'] === 'entity') {
            return $model::create($this->_format($data), $options);
        }
        foreach ($data as $key => $value) {
            if (isset($value['doc'])) {
                $value = $value['doc'];
            }
            if (isset($value['value'])) {
                $value = $value['value'];
            }
            $data[$key] = $this->_format($value);
        }
        return $model::create($data, $options);
    }

Usage Example

Example #1
0
 public function testItem()
 {
     $couchdb = new CouchDb($this->_testConfig);
     $data = array('_id' => 'a1', '_rev' => '1-2', 'author' => 'author 1', 'body' => 'body 1');
     $expected = array('id' => 'a1', 'rev' => '1-2', 'author' => 'author 1', 'body' => 'body 1');
     $item = $couchdb->item($this->query->model(), $data);
     $result = $item->data();
     $this->assertEqual($expected, $result);
 }