JsonView.php 619 B

12345678910111213141516171819202122
  1. <?php
  2. namespace demo\Views;
  3. use Silex\Application;
  4. use Symfony\Component\HttpFoundation\Request;
  5. /**
  6. * Class JsonView is a JSON view handler.
  7. *
  8. * @package demo\Views
  9. */
  10. class JsonView {
  11. public function handle(array $controllerResult, Request $request) {
  12. // Does limited escaping using JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT.
  13. // Try /hello-json/<script>alert('Yo');<script> : Chrome with JSON Decode
  14. // extension throws JS error, which proves interpretation is triggered. This
  15. // is actually due to the extension.
  16. return $GLOBALS['app']->json($controllerResult);
  17. }
  18. }