mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1471 from cakephp/feature/2.4-pretty-print
pretty print json and xml responses in debug mode
This commit is contained in:
commit
f34388c53a
4 changed files with 22 additions and 1 deletions
|
@ -30,6 +30,11 @@ App::uses('JsonView', 'View');
|
||||||
*/
|
*/
|
||||||
class JsonViewTest extends CakeTestCase {
|
class JsonViewTest extends CakeTestCase {
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
Configure::write('debug', 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testRenderWithoutView method
|
* testRenderWithoutView method
|
||||||
*
|
*
|
||||||
|
|
|
@ -30,6 +30,11 @@ App::uses('XmlView', 'View');
|
||||||
*/
|
*/
|
||||||
class XmlViewTest extends CakeTestCase {
|
class XmlViewTest extends CakeTestCase {
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
Configure::write('debug', 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testRenderWithoutView method
|
* testRenderWithoutView method
|
||||||
*
|
*
|
||||||
|
|
|
@ -128,6 +128,11 @@ class JsonView extends View {
|
||||||
} else {
|
} else {
|
||||||
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
|
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version_compare(PHP_VERSION, '5.4.0', '>=') && Configure::read('debug')) {
|
||||||
|
return json_encode($data, JSON_PRETTY_PRINT);
|
||||||
|
}
|
||||||
|
|
||||||
return json_encode($data);
|
return json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,13 @@ class XmlView extends View {
|
||||||
$data = array($rootNode => array($serialize => $data));
|
$data = array($rootNode => array($serialize => $data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Xml::fromArray($data)->asXML();
|
|
||||||
|
$options = array();
|
||||||
|
if (Configure::read('debug')) {
|
||||||
|
$options['pretty'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Xml::fromArray($data, $options)->asXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue