function testOutput() { $prop = new stdClass(); $prop->foo = 1; $prop2 = new ArrayObject(); $prop2[] = $prop; $foo = new stdClass(); $foo->a = $prop; $foo->b = $prop2; $foo->c = $prop; $foo->d = $foo; $class = array(array($foo), array($foo), array(array($foo))); $this->assertEquals(xml_encode_all($class), '<?xml version="1.0" encoding="utf-8"?> <data><item><item><a><foo>1</foo></a><b><item><foo>1</foo></item></b><c><foo>1</foo></c><d>*RECURSION*</d></item></item><item><item><a><foo>1</foo></a><b><item><foo>1</foo></item></b><c><foo>1</foo></c><d>*RECURSION*</d></item></item><item><item><item><a><foo>1</foo></a><b><item><foo>1</foo></item></b><c><foo>1</foo></c><d>*RECURSION*</d></item></item></item></data> '); }
/** * Loads the given view using the layout and parameters in $this. * @param string $view The view to load. This should be a full view. It will not be appended to * the viewDir */ function loadView($view, $params = null) { if (!in_array($this->outputFormat, $this->allowedFormats)) { throw new RuntimeException("The extension '{$this->outputFormat}' is not supported."); } if (func_num_args() == 1) { $params = $this; } switch ($this->outputFormat) { case 'html': if ($this->layout && $this->renderPartial === false) { $this['content_view'] = $view; $view = $this->layout; } View::load($view, $params, false); break; case 'json': if (!headers_sent()) { header('Content-type: application/json; charset=utf-8'); if ($this->isRestful() && !empty($this['errors'])) { header($_SERVER['SERVER_PROTOCOL'] . ' 400 Error'); $params = array('errors' => $this['errors']); } } echo json_encode_all($params); break; case 'jsonp': if (!headers_sent()) { header('Content-type: application/javascript; charset=utf-8'); if ($this->isRestful() && !empty($this['errors'])) { header($_SERVER['SERVER_PROTOCOL'] . ' 400 Error'); $params = array('errors' => $this['errors']); } } $callback = 'callback'; if ($this->route) { $callback = $this->route->getJsonPCallback(); } echo $callback . '(' . json_encode_all($params) . ')'; break; case 'xml': if (!headers_sent()) { header('Content-type: application/xml'); if ($this->isRestful() && !empty($this['errors'])) { header($_SERVER['SERVER_PROTOCOL'] . ' 400 Error'); $params = array('errors' => $this['errors']); } } echo xml_encode_all($params); break; default: throw new RuntimeException("The extension '{$this->outputFormat}' is not supported."); break; } $this->loadView = false; }