JsonFormat.php 603 B

12345678910111213141516171819202122232425
  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. $items = $this->getItems();
  9. $toReturn = json_encode($items, JSON_PRETTY_PRINT);
  10. // Remove invalid non-UTF8 characters
  11. ini_set('mbstring.substitute_character', 'none');
  12. $toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
  13. return $toReturn;
  14. }
  15. public function display(){
  16. $this
  17. ->setContentType('application/json; charset=' . $this->getCharset())
  18. ->callContentType();
  19. return parent::display();
  20. }
  21. }