Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

JsonExpression.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Illuminate\Database\Query;
  3. use InvalidArgumentException;
  4. class JsonExpression extends Expression
  5. {
  6. /**
  7. * Create a new raw query expression.
  8. *
  9. * @param mixed $value
  10. * @return void
  11. */
  12. public function __construct($value)
  13. {
  14. parent::__construct(
  15. $this->getJsonBindingParameter($value)
  16. );
  17. }
  18. /**
  19. * Translate the given value into the appropriate JSON binding parameter.
  20. *
  21. * @param mixed $value
  22. * @return string
  23. *
  24. * @throws \InvalidArgumentException
  25. */
  26. protected function getJsonBindingParameter($value)
  27. {
  28. if ($value instanceof Expression) {
  29. return $value->getValue();
  30. }
  31. switch ($type = gettype($value)) {
  32. case 'boolean':
  33. return $value ? 'true' : 'false';
  34. case 'NULL':
  35. case 'integer':
  36. case 'double':
  37. case 'string':
  38. return '?';
  39. case 'object':
  40. case 'array':
  41. return '?';
  42. }
  43. throw new InvalidArgumentException("JSON value is of illegal type: {$type}");
  44. }
  45. }