public function testSource() { $data = array(array('_id' => 10)); $set = new Simples_Document_Set($data, array('source' => true)); $this->assertTrue($set->get(0)->properties() instanceof Simples_Document); $this->assertEquals(10, $set->get(0)->properties()->id); $set = new Simples_Document_Set($data, array('source' => false)); $this->assertFalse($set->get(0)->properties() instanceof Simples_Document); }
/** * Overrides body for bulk indexing. * * @param mixed $body Data to index. * @return mixed Data to index. */ public function body($body = null) { if (isset($body)) { if ($body instanceof Simples_Document) { $this->_body = $body; } elseif ($body instanceof Simples_Document_Set || Simples_Document_Set::check($body)) { if (!$body instanceof Simples_Document_Set) { $body = new Simples_Document_Set($body); } $this->_body = $body; } else { $this->_body = new Simples_Document($body); } return $this; } if (isset($this->_body)) { return $this->_body; } return array(); }
/** * Import a data array and transforms entities into Simples_Document or * Simples_Document_Set. * * @param array $data Data to import * @return array Data ready to work on */ protected function _import($data) { if (is_scalar($data)) { return $data; } foreach ($data as $key => $value) { // Prepare the cast config to remove the current key $options = $this->_config; if (!empty($options['cast'])) { $this->_options($key, $options); } if (!is_scalar($value)) { if (Simples_Document_Set::check($value)) { $data[$key] = new Simples_Document_Set($value, array('source' => false) + $options); } elseif (is_array($value) && !is_numeric(key($value))) { $data[$key] = new Simples_Document($value, array('source' => false) + $options); } } } return $data; }