CutStub.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. $this->cut = -1;
  27. break;
  28. case 'array':
  29. $this->type = self::TYPE_ARRAY;
  30. $this->class = self::ARRAY_ASSOC;
  31. $this->cut = $this->value = count($value);
  32. break;
  33. case 'resource':
  34. case 'unknown type':
  35. $this->type = self::TYPE_RESOURCE;
  36. $this->handle = (int) $value;
  37. $this->class = @get_resource_type($value);
  38. $this->cut = -1;
  39. break;
  40. case 'string':
  41. $this->type = self::TYPE_STRING;
  42. $this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
  43. $this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1);
  44. $this->value = '';
  45. break;
  46. }
  47. }
  48. }