public function testDataOperation() { $gas_data = new Gas\Data(array('foo' => 'bar')); $this->assertArrayHasKey('foo', $gas_data->get()); $gas_data->set('lorem', 'ipsum'); $this->assertArrayHasKey('lorem', $gas_data->get()); }
/** * Overiding method, triggered when try calling inaccesible method * * @param string Available method are : to_xml(), to_json(), to_data() * @return mixed */ public function __call($method, $params) { if (preg_match('/^to_(xml|json|data)$/', $method, $m) && count($m) == 2) { $records_array = $this->to_array(); switch ($m[1]) { case 'data': $records_data = new \Gas\Data(); $records_data->set('data', $records_array); break; case 'json': $records_data = json_encode($records_array); break; case 'xml': if (!function_exists('simplexml_load_file')) { throw new \RuntimeException('[to_xml]Simple XML must be installed'); } $xml_template = "<?xml version='1.0' standalone='yes'?> <result> </result>"; $result = new \SimpleXMLElement($xml_template); foreach ($records_array as $index => $record) { ${$index} = $result->addChild($index); foreach ($record as $key => $value) { ${$index}->addChild($key, $value); } } $records_data = $result->asXML(); break; } return $records_data; } throw new \BadMethodCallException('[' . $method . ']Unknown method.'); }