JsonFormat.php 506 B

12345678910111213141516171819202122
  1. <?php
  2. /**
  3. * Json
  4. * Builds a JSON string from $this->items and return it to browser.
  5. */
  6. class JsonFormat extends FormatAbstract{
  7. public function stringify(){
  8. // FIXME : sometime content can be null, transform to empty string
  9. $datas = $this->getDatas();
  10. return json_encode($datas, JSON_PRETTY_PRINT);
  11. }
  12. public function display(){
  13. $this
  14. ->setContentType('application/json')
  15. ->callContentType();
  16. return parent::display();
  17. }
  18. }