CompilesJson.php 725B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Illuminate\View\Compilers\Concerns;
  3. trait CompilesJson
  4. {
  5. /**
  6. * The default JSON encoding options.
  7. *
  8. * @var int
  9. */
  10. private $encodingOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
  11. /**
  12. * Compile the JSON statement into valid PHP.
  13. *
  14. * @param string $expression
  15. * @return string
  16. */
  17. protected function compileJson($expression)
  18. {
  19. $parts = explode(',', $this->stripParentheses($expression));
  20. $options = isset($parts[1]) ? trim($parts[1]) : $this->encodingOptions;
  21. $depth = isset($parts[2]) ? trim($parts[2]) : 512;
  22. return "<?php echo json_encode($parts[0], $options, $depth) ?>";
  23. }
  24. }