JsonFormat.php 521 B

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