You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

2 years ago
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\VarDumper\Caster;
  11. use Symfony\Component\VarDumper\Cloner\Stub;
  12. /**
  13. * Represents the main properties of a PHP variable, pre-casted by a caster.
  14. *
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class CutStub extends Stub
  18. {
  19. public function __construct($value)
  20. {
  21. $this->value = $value;
  22. switch (\gettype($value)) {
  23. case 'object':
  24. $this->type = self::TYPE_OBJECT;
  25. $this->class = \get_class($value);
  26. if ($value instanceof \Closure) {
  27. ReflectionCaster::castClosure($value, [], $this, true, Caster::EXCLUDE_VERBOSE);
  28. }
  29. $this->cut = -1;
  30. break;
  31. case 'array':
  32. $this->type = self::TYPE_ARRAY;
  33. $this->class = self::ARRAY_ASSOC;
  34. $this->cut = $this->value = \count($value);
  35. break;
  36. case 'resource':
  37. case 'unknown type':
  38. case 'resource (closed)':
  39. $this->type = self::TYPE_RESOURCE;
  40. $this->handle = (int) $value;
  41. if ('Unknown' === $this->class = @get_resource_type($value)) {
  42. $this->class = 'Closed';
  43. }
  44. $this->cut = -1;
  45. break;
  46. case 'string':
  47. $this->type = self::TYPE_STRING;
  48. $this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
  49. $this->cut = self::STRING_BINARY === $this->class ? \strlen($value) : mb_strlen($value, 'UTF-8');
  50. $this->value = '';
  51. break;
  52. }
  53. }
  54. }