public function testCheck() { $data = array('Not', 'A', 'Set'); $this->assertFalse(Simples_Document_Set::check($data)); $data = array(array('is' => 'A Simples_Document'), array('is' => 'Another Simples_Document')); $this->assertTrue(Simples_Document_Set::check($data)); }
/** * 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; }