public function testAppend() { $structure = new Structure(); $structure->append('key', 'v1'); $this->assertEquals('v1', $structure->key); $structure->append('key', 'v2'); $this->assertEquals(array('v1', 'v2'), $structure->key); $structure->set('key', 'v1'); $this->assertEquals('v1', $structure->key); $structure->append('key', 'v2'); $this->assertEquals(array('v1', 'v2'), $structure->key); }
/** * Give this any kind of array * to get some kirby style structure * * @param mixed $data * @param mixed $page * @param mixed $key * @return mixed */ function structure($data, $page = null, $key = null) { if (is_null($page)) { $page = page(); } if (is_array($data)) { $result = new Structure(); $result->page = $page; foreach ($data as $key => $value) { $result->append($key, structure($value, $page, $key)); } return $result; } else { if (is_a($data, 'Field')) { return $data; } else { return new Field($page, $key, $data); } } }