ReprSerializer.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. * This file is part of Raven.
  4. *
  5. * (c) Sentry Team
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Serializes a value into a representation that should reasonably suggest
  12. * both the type and value, and be serializable into JSON.
  13. * @package raven
  14. */
  15. class Raven_ReprSerializer extends Raven_Serializer
  16. {
  17. protected function serializeValue($value)
  18. {
  19. if ($value === null) {
  20. return 'null';
  21. } elseif ($value === false) {
  22. return 'false';
  23. } elseif ($value === true) {
  24. return 'true';
  25. } elseif (is_float($value) && (int) $value == $value) {
  26. return $value.'.0';
  27. } elseif (is_integer($value) || is_float($value)) {
  28. return (string) $value;
  29. } elseif (is_object($value) || gettype($value) == 'object') {
  30. return 'Object '.get_class($value);
  31. } elseif (is_resource($value)) {
  32. return 'Resource '.get_resource_type($value);
  33. } elseif (is_array($value)) {
  34. return 'Array of length ' . count($value);
  35. } else {
  36. return $this->serializeString($value);
  37. }
  38. }
  39. }